Results 1 to 5 of 5
  1. #1
    woodmandan2 is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default 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
    Java 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 2

    Java 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 3

    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();
    		}
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    woodmandan2 is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.

    Sorry.... I will post the error messages, in code format, shortly.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.

    Thanks, that will help quite a bit.

  5. #5
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Exception Handing Programs - Will not Compile, cannot determine what is wrong.

    I wonder why any of this compiles... "Class" is not a valid java declaration... and empty spaces in names are... um... uncommon, not to say forbidden. ^^
    I like likes!

Similar Threads

  1. Need help on my excpetion handing assignment
    By EZ-Ed in forum New To Java
    Replies: 2
    Last Post: 10-03-2012, 11:35 AM
  2. spring mvc form handing
    By BALUBALU in forum Spring
    Replies: 3
    Last Post: 08-08-2012, 06:01 PM
  3. Replies: 3
    Last Post: 02-03-2012, 08:52 PM
  4. Replies: 1
    Last Post: 04-27-2011, 10:08 AM
  5. Did I compile this wrong?
    By eindoofus in forum New To Java
    Replies: 2
    Last Post: 04-17-2011, 07:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •