Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: Basic Java Program Help

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question Basic Java Program Help

    Need help with a java program assignment for school. Here is the problem:

    We are all looking forward to retiring someday. Assuming we will retire on our 65th birthday, write a Java program that prompts the user for his/her birthday month, day, and year and then prints out the date the user will retire.

    I am having trouble calculating when the user will turn 65. Here is what I have so far:
    package com.mime.project1;
     
    import java.util.Scanner;
     
    public class Assign2 {
    	public static void main(String[] args) {
    		Scanner stdIn = new Scanner(System.in);
     
    int month, day, year;
     
    System.out.print("Enter the month you were born: ");
    month = stdIn.nextInt();
    System.out.print("Enter the day you were born: ");
    day = stdIn.nextInt();
    System.out.print("Enter the year you were born: ");
    year = stdIn.nextInt();
     
     
    	}
     
    }
    Last edited by helloworld922; January 16th, 2012 at 09:38 PM.


  2. #2
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Basic Java Program Help

    You need to think of the retirement year with reference to the year entered by the user and the value 65. Note: This is not where you get people to do your homework. Now, what is the relationship between the age of the user as calculated by from the information provided, and the value 65? That is how you will know how many years remain for active work before retirement.

  3. The Following User Says Thank You to elisha.java For This Useful Post:

    Nuggets (January 17th, 2012)

  4. #3
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    Quote Originally Posted by elisha.java View Post
    You need to think of the retirement year with reference to the year entered by the user and the value 65. Note: This is not where you get people to do your homework. Now, what is the relationship between the age of the user as calculated by from the information provided, and the value 65? That is how you will know how many years remain for active work before retirement.
    I'm still having a hard time understanding how to calculate the years.

  5. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Basic Java Program Help

    Hint:

    Say you were born the year 0. What year would you be 65?
    Now say your friend was born year 1. What year would they be 65?

    Now how do you generalize this to someone born year y?

  6. The Following User Says Thank You to helloworld922 For This Useful Post:

    Nuggets (January 17th, 2012)

  7. #5
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    Quote Originally Posted by helloworld922 View Post
    Hint:

    Say you were born the year 0. What year would you be 65?
    Now say your friend was born year 1. What year would they be 65?

    Now how do you generalize this to someone born year y?
    Okay, so I would have to set the value of the inputted year to equal 0 right? Then I would need a for loop to count the years until it reaches 65?
    for (year=0; year<65; year++)
    Am I getting closer or no?

  8. #6
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    One more hint guys, please. Is it a for, if or while loop? All the for loop did was count up to 65 for the year. I need it to output the exact year the person will turn 65, not the number 65.

  9. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Basic Java Program Help

    @Nuggets: Get a copy and pencil and write down how will you solve it if the same problem is given to you to solve manually?
    Write down the steps clearly as you followed manually to solve the problem.
    Implement those steps in your program.

    Note: You don't need any loop for this program.

  10. The Following User Says Thank You to Mr.777 For This Useful Post:

    Nuggets (January 17th, 2012)

  11. #8
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    Quote Originally Posted by Mr.777 View Post
    @Nuggets: Get a copy and pencil and write down how will you solve it if the same problem is given to you to solve manually?
    Write down the steps clearly as you followed manually to solve the problem.
    Implement those steps in your program.

    Note: You don't need any loop for this program.
    That helped a lot, thanks! So I just need to add 65 to the year inputted (year += 65). Wow, made this problem a lot more complicated than it was.

  12. #9
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Basic Java Program Help

    @neeraj0708: If you would just spend few minutes to read Forums Rules, you will come to know that spoon feeding is not allowed.

    Request to Admin or Moderators: Kindly ban such users who try to spoon feed as they don't even bother to read forums rules or create a test to get successful registration on the forums and test must contain all the forums rules.

  13. The Following User Says Thank You to Mr.777 For This Useful Post:

    copeg (January 17th, 2012)

  14. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Basic Java Program Help

    Quote Originally Posted by Mr.777 View Post
    @neeraj0708: If you would just spend few minutes to read Forums Rules, you will come to know that spoon feeding is not allowed.

    Request to Admin or Moderators: Kindly ban such users who try to spoon feed as they don't even bother to read forums rules or create a test to get successful registration on the forums and test must contain all the forums rules.
    The user has been warned accordingly and deleted their thread on their own.

  15. #11
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    Quote Originally Posted by Mr.777 View Post
    @neeraj0708: If you would just spend few minutes to read Forums Rules, you will come to know that spoon feeding is not allowed.

    Request to Admin or Moderators: Kindly ban such users who try to spoon feed as they don't even bother to read forums rules or create a test to get successful registration on the forums and test must contain all the forums rules.
    The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people.

    How am I supposed to gain knowledge through this forum? "We invite beginner Java programmers right through to Java professionals to post here and share your knowledge." I'm sorry I don't know as much as you about programming Java, as I only started 2 weeks ago. Am I not allowed to ask for help on certain things? Why is information so privy? What's so bad about asking for some help? Maybe I shouldn't have said it was for school. Anyways, I'm disappointed in this forum. I guess when I get to your level of expertise in Java, I know I shouldn't try and help a beginner out, or point him in a kind direction...
    Last edited by Nuggets; January 17th, 2012 at 05:50 PM.

  16. #12
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Basic Java Program Help

    Dear Nuggets, you may have misunderstood the above ruckus as being directed towards you - it was not. Rather it was directed towards a member who was doing what is called 'spoon-feeding' (and whose post was subsequently deleted), which is against forum rules:

    Providing homework solutions in full or in part is frowned upon, and contributions that are considered as such will be subject to moderation (editing and/or deletion)

    The following article should give you an idea as to why this rule exists

    The Problem with Spoon-feeding

  17. #13
    Member
    Join Date
    Jan 2012
    Posts
    65
    My Mood
    Happy
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Program Help

    Alright, was confused because I didn't even see that persons response. Thanks copeg for the help!

  18. #14
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Basic Java Program Help

    Should we sometimes be worried of the side-effects of our tough language towards new programmers before doing anything or just go ahead scaring them away? I will never tolerate spoon-feeding but I wonder if telling them how wrong they are will help them. It would be easier if we all started and went pro the same day or week! I am not creating an affinity for conflict but I believe that we should learn to tame talents that will replace our own when our times are up! Thank you.

  19. #15
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Basic Java Program Help

    This thread has been slightly pushed off course...lets please stay on topic. Its not to deny anyone their piece of mind, but in the effort to keep the forums organized please start a new thread for discussion not related to the original topic.

    Nuggets, I am not sure if your problem that started this thread has been solved or not. If so, please mark the thread as solved, otherwise please update this thread with the appropriate information/questions/etc...

  20. #16
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Basic Java Program Help

    Given I have had to move several posts out of this thread to their own, I am locking this thread. Nuggets, apologies and if your question has yet to be answered please start another thread. Others, if you feel the need to discuss please start another thread.

  21. The Following User Says Thank You to copeg For This Useful Post:

    elisha.java (January 18th, 2012)

Similar Threads

  1. BASIC program help
    By ryanquanz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 15th, 2011, 10:42 AM
  2. Very basic program but its making me crazy
    By craig carl in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 2nd, 2011, 03:16 PM
  3. Not sure what to do next (Basic java program)
    By desi22601 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 21st, 2010, 09:05 AM
  4. Basic program which gets cost, adds tax, gets payment then calculates change.
    By bibboorton in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 25th, 2010, 10:31 AM
  5. Basic Java Program Help
    By roaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2009, 10:28 PM