Results 1 to 15 of 15
  1. #1
    amzers is offline Member
    Join Date
    Dec 2010
    Posts
    31
    Rep Power
    0

    Default I need to edit this code

    hey everyone...i need help with my programming im trying to make,...i really need to know how to edit this code cause im a newbie at this...so i need someone who can edit this code,and I dont need discussions, i just want to get this over with..thanks :)

    __________________________________________________ _________________


    */import java.io.*;
    public class age {

    public static void main(String[] args)throws Exception{

    BufferedReader input = new BufferedReader (new InputStreamReader(System.in));

    String name;
    System.out.println("ENTER NAME:");
    name=input.readLine();
    System.out.println("Name is:" + name);


    Integer answer;
    System.out.println("ENTER YOUR AGE:");
    answer=Integer(input.parseInt);

    if (answer <='7')
    System.out.println("Still playing");
    if (answer > '8')
    System.out.println("Is studying");
    if (answer < '21')
    System.out.println("Is studying");
    if (answer > '22')
    System.out.println("Is working");
    if (answer < '64')
    System.out.println("Is working");
    if (answer >= '65')
    System.out.println("Now retired");


    }
    }

    __________________________________________________ _______________

    so where did i go wrong?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Java Code:
    //the edited code

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by masijade View Post
    Java Code:
    //the edited code
    Duh! I did something else: I created beautiful ASCII art but there's one problem now: it won't compile. Any suggestions?

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Red face

    What do you mean by I need to edit this code?

    Are there any errors in there? Do you want to know how to format it? Or something else?

    And why do you don't need discussions? Then what's the point of forums? :confused:

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    amzers is offline Member
    Join Date
    Dec 2010
    Posts
    31
    Rep Power
    0

    Default

    yea,...i cant seem to run the AGE thingy,...

    well,people have been helping me through this...a discussion and a code would help me,...i really cant understand will all those stuffs without the actual thing,...then id be understanding it with also the correct code

  6. #6
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Here is what you need to do,

    Java Code:
    import java.io.*;
    
    public class Age {
    
    	public static void main(String[] args) {
    
    		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    		try {
    			System.out.print("ENTER NAME: ");
    			String name = input.readLine();
    			System.out.println("Name is: " + name);
    
    			System.out.print("ENTER YOUR AGE: ");
    			String age = input.readLine();
    			int answer = Integer.parseInt(age);
    			
    			if (answer <= 7)
    				System.out.println("Still playing");
    			if (answer > 8)
    				System.out.println("Is studying");
    			if (answer < 21)
    				System.out.println("Is studying");
    			if (answer > 22)
    				System.out.println("Is working");
    			if (answer < 64)
    				System.out.println("Is working");
    			if (answer >= 65)
    				System.out.println("Now retired");
    		} catch (IOException io) {
    			io.printStackTrace();
    		}
    	}
    }

    Following things you need to understand correctly,

    1) I/O (specially Readers in this example) java API documentation.

    2) Wrapper classes (specially Integer in this example) java API documentation.

    3) Your if(condition) are not properly handled. They will produce multiple outputs for some ages. You need to manage that correctly. Have a habit of using curly braces if{} else{} when you use if/else statements.

    4) Don't make the main method throw any exceptions. That would result in crashing your JVM in case if you come across any exception. And you wont even know what made your program dead. Using try/catch is always recommended.

    Learn these things without fail and practice them, thats for your benefit.

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    Nice job of spoon feeding there.
    You could have completely skipped the explanation since I doubt the OP will go beyond cutting and pasting the code...

  8. #8
    amzers is offline Member
    Join Date
    Dec 2010
    Posts
    31
    Rep Power
    0

    Default

    Quote Originally Posted by goldest View Post
    Here is what you need to do,

    Java Code:
    import java.io.*;
    
    public class Age {
    
    	public static void main(String[] args) {
    
    		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    		try {
    			System.out.print("ENTER NAME: ");
    			String name = input.readLine();
    			System.out.println("Name is: " + name);
    
    			System.out.print("ENTER YOUR AGE: ");
    			String age = input.readLine();
    			int answer = Integer.parseInt(age);
    			
    			if (answer <= 7)
    				System.out.println("Still playing");
    			if (answer > 8)
    				System.out.println("Is studying");
    			if (answer < 21)
    				System.out.println("Is studying");
    			if (answer > 22)
    				System.out.println("Is working");
    			if (answer < 64)
    				System.out.println("Is working");
    			if (answer >= 65)
    				System.out.println("Now retired");
    		} catch (IOException io) {
    			io.printStackTrace();
    		}
    	}
    }

    Following things you need to understand correctly,

    1) I/O (specially Readers in this example) java API documentation.

    2) Wrapper classes (specially Integer in this example) java API documentation.

    3) Your if(condition) are not properly handled. They will produce multiple outputs for some ages. You need to manage that correctly. Have a habit of using curly braces if{} else{} when you use if/else statements.

    4) Don't make the main method throw any exceptions. That would result in crashing your JVM in case if you come across any exception. And you wont even know what made your program dead. Using try/catch is always recommended.

    Learn these things without fail and practice them, thats for your benefit.

    Hope that helps,

    Goldest

    thank you so much for your help,I am going fix this if statements cause it still displays multiple outputs and thank you for the idea given :)

  9. #9
    amzers is offline Member
    Join Date
    Dec 2010
    Posts
    31
    Rep Power
    0

    Default

    */import java.io.*;

    public class age {

    public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("ENTER NAME: ");
    String name = input.readLine();
    System.out.println("Name is: " + name);

    System.out.print("ENTER YOUR AGE: ");
    String age = input.readLine();
    int answer = Integer.parseInt(age);

    if (answer <= 7)
    System.out.println("Still playing");

    if (answer <= 21)
    System.out.println("Is studying");


    if (answer <= 65)
    System.out.println("Is Still working");

    if (answer >= 65)
    System.out.println("Is retired");

    }
    }


    figured it out :) and thank you so much

  10. #10
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by Tolls View Post
    Nice job of spoon feeding there.
    You could have completely skipped the explanation since I doubt the OP will go beyond cutting and pasting the code...
    Just doing my bit. It's up to the OP whether to go for the learning or not.

    You are Welcome amzers, but try to learn the things beyond copy-paste! :D

    Hope you will,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    Quote Originally Posted by goldest View Post
    Just doing my bit. It's up to the OP whether to go for the learning or not.

    You are Welcome amzers, but try to learn the things beyond copy-paste! :D

    Hope you will,

    Goldest
    Then please go elsewhere and "help".
    Spoon feeding is frowned upon here, especially by those of us in the industry who have to repair code produced by people who copy/pasted their way into jobs.

  12. #12
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Red face

    Quote Originally Posted by Tolls View Post
    Then please go elsewhere and "help".
    Spoon feeding is frowned upon here, especially by those of us in the industry who have to repair code produced by people who copy/pasted their way into jobs.
    We are here to discuss, learn, advice and help. The extent may vary person to person.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    We are not here to spoon feed solutions.
    Supplying solutions does not help.

  14. #14
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Thumbs up

    Quote Originally Posted by Tolls View Post
    We are not here to spoon feed solutions.
    Supplying solutions does not help.
    I agree with this.

    But I didn't provide ONLY solution, I gave the pointers as well where the OP needs to improve in order to get good understanding.

    But I will keep your suggestion in mind. :)

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    Honestly, most of the kids will ignore any explanation if they've been given the solution.
    All many of them want is a pass mark, and explanations aren't needed for that.

    (OP, this may or may not apply to you, so no offense intended)

Similar Threads

  1. Replies: 9
    Last Post: 06-02-2012, 05:04 PM
  2. Online IDE to edit and compile code?
    By DarrenReeder in forum Other IDEs
    Replies: 1
    Last Post: 02-06-2011, 01:58 AM
  3. Add , edit ,delete code in struts
    By sandy1000 in forum Web Frameworks
    Replies: 0
    Last Post: 12-28-2010, 06:25 AM
  4. Replies: 0
    Last Post: 03-28-2010, 09:55 AM
  5. Edit .jar
    By jwerre in forum New To Java
    Replies: 1
    Last Post: 10-04-2009, 04:35 AM

Posting Permissions

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