Results 1 to 5 of 5
- 01-09-2013, 03:54 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Exception Handing Programs - Will not Compile, cannot determine what is wrong.
Hi all. This is my task for the assignment:
1. Write a program where the user enters their name and age, and then is required to see if their age is between 0 and 125. If not, there is an error code.
2. Write a program to withdraw money from a 10,000 dollar checking account, if it is less than 0 or greater than 10000 there will be an error.
3. write a program to start three tasks at a given time, and make time between those tasks (pauses), utilizing the concept of multithreading.
Basically I am attempting to write three separate programs, with three separate tasks. Programs 1 + 3 will not compile. Program 2 will compile, but does not function correctly after compiled. I have literally spent hours attempting to figure out what I am doing wrong, to no avail. Here is the source code for my programs:
Program 1
Program 2Java Code:import java.util.Scanner; public class InvalidAgeException extends Exception { public InvalidAgeException() { super("The age entered is Invalid" } } Class InputAge { public static void main(String args[]) { try { Scanner input data = new Scanner( System.in ); System.out.print("Enter your name"); String str1 = inputdata.nextLine(); System.out.print("Enter your age"); int age = inputdata.nextInt(); if (age < 0 || age > 125) { throw InvalidAgeException(age); } } catch(InvalidAgeException age) { System.out.println("Age is Incorrect"); } finally { System.out.println("Execution complete, program finished"); } } }
Program 3Java Code:import java.util.Scanner; public class InvalidAgeException extends Exception { public InvalidAgeException() { super("The age entered is Invalid" } } Class InputAge { public static void main(String args[]) { try { Scanner input data = new Scanner( System.in ); System.out.print("Enter your name"); String str1 = inputdata.nextLine(); System.out.print("Enter your age"); int age = inputdata.nextInt(); if (age < 0 || age > 125) { throw InvalidAgeException(age); } } catch(InvalidAgeException age) { System.out.println("Age is Incorrect"); } finally { System.out.println("Execution complete, program finished"); } } }
Java Code:class Thread1 extends Thread { public void run() { for(int j = 0; j<100; j += 2) System.out.println("Thread 1: " + j); } } class Thread 2 extends Thread { public void run() } for(int k = 1; k<100; k += 4) System.out.println("Thread 2: " + k); } } class Thread3 extends Thread { public void run() { for(int k = 1; k<100; k += 6) System.out.println("Thread 3: " + k); } } Class Program3 { public static void main(String arg[]) { try{ Thread1 objThread1 = new Thread1(); Thread2 objThread2 = new Thread2(); Thread3 objThread3 = new Thread3(); objThread1.start(); Thread.sleep(1000); objThread2.start(); Thread.sleep(1000); objThread3.start(); }catch(InterruptedException e){ e.printStackTrace(); } } }
-
Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.
If you need help with compilation errors, it would be advisable to show us the error messages and indicate which lines are causing the errors. I really shouldn't have to request this information as it should be obvious that we'd need it.
- 01-09-2013, 04:41 AM #3
Member
- Join Date
- Jan 2013
- Posts
- 4
- Rep Power
- 0
Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.
Sorry.... I will post the error messages, in code format, shortly.
-
Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.
Thanks, that will help quite a bit.
- 01-09-2013, 02:05 PM #5
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Similar Threads
-
Need help on my excpetion handing assignment
By EZ-Ed in forum New To JavaReplies: 2Last Post: 10-03-2012, 11:35 AM -
spring mvc form handing
By BALUBALU in forum SpringReplies: 3Last Post: 08-08-2012, 06:01 PM -
I add java.exe to programs in preferences but I cannot compile java in textpad. help!
By ashleymcg in forum New To JavaReplies: 3Last Post: 02-03-2012, 08:52 PM -
Programs compile differently on 32-bit and 64-bit versions of eclipse?
By BAPandora in forum EclipseReplies: 1Last Post: 04-27-2011, 10:08 AM -
Did I compile this wrong?
By eindoofus in forum New To JavaReplies: 2Last Post: 04-17-2011, 07:22 PM


LinkBack URL
About LinkBacks
Reply With Quote.gif)

Bookmarks