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

Thread: Summer Project - Stuck?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Summer Project - Stuck?

    For my college summer task I have been given this as question two, I simply cannot get my head around it!


    Create a class Exercise2 with the code below:

    import java.util.Scanner;  //package needed to read from keyboard
    public class Exercise2
    {
       public static void main (String[] args)
       {
           //declare Scanner and integer variables
           Scanner sc = new Scanner(System.in);
           int allMonths, years, partMonths;
     
           //ask for age in months
           System.out.print("Age in months: ");
     
           //set allMonths to value typed in
           //code here
     
           //calculate years from allMonths
           //code here
           //calculate partMonths from allMonths
           //code here
     
           //display message about calculated years and months
           //code here
       }//end main
    }//end class


    Currently the program prompts the user for a number of months but does not yet calculate and output how many years and months this is equivalent to. For example when the user types an input of 40 the program output should be:
    Age in months: 40
    40 months = 3 years and 4 months

    What you need to do
    Modify the program so that for an input number of months the whole years and months are calculated and displayed

    Test your program with age in months values as follows.
    Test 1: 11
    Test 2: 24
    Test 3: 30

    ---------------------------------------------------------------
    I have tried and got this so far,
    ---------------------------------------------------------------


    import java.util.Scanner;  //package needed to read from keyboard
    public class Exercise2
    {
       public static void main (String[] args)
       {
           //declare Scanner and integer variables
           Scanner scan = new Scanner (System.in);
           int allMonths, years, partMonths;
     
           //ask for age in months
           String inData;
     
           System.out.println("Age in months: ");
           inData = scan.nextLine();
     
           //set allMonths to value typed in
     
     
           //calculate years from allMonths
           //code here
           //calculate partMonths from allMonths
           //code here
     
           //display message about calculated years and months
           //code here
       }//end main
    }//end class
    Not much I know, but atleast i'm trying! Some help would be greatly appreciated!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Summer Project - Stuck?

    Quote Originally Posted by hillzyy View Post
    ...
    ---------------------------------------------------------------
    I have tried and got this so far,
    ---------------------------------------------------------------
    import java.util.Scanner;  //package needed to read from keyboard
    public class Exercise2
    {
       public static void main (String[] args)
       {
           //declare Scanner and integer variables
           Scanner scan = new Scanner (System.in);
           int allMonths, years, partMonths;
     
           //ask for age in months
           String inData;
     
           System.out.println("Age in months: ");
           inData = scan.nextLine();
     
           //set allMonths to value typed in
     
     
           //calculate years from allMonths
           //code here
           //calculate partMonths from allMonths
           //code here
     
           //display message about calculated years and months
           //code here
       }//end main
    }//end class
    ...
    Well what does the program do so far?
    Does it compile?
    Does it run?
    Do you have any error messages?
    If you were to run it in the debugger, and add a breakpoint after:
    inData = scan.nextLine();
    ... does inData hold the String you expect to see there?
    What is broken? Where are you stuck?
    ...Short of doing the entire work for you, you leave not much clue what it is you need help with.

  3. #3
    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: Summer Project - Stuck?

    @Krumpir, please read the forum rules and the following:
    http://www.javaprogrammingforums.com...n-feeding.html

Similar Threads

  1. Google Summer of Code 2012
    By heiguga in forum Paid Java Projects
    Replies: 0
    Last Post: March 28th, 2012, 04:59 AM
  2. Im stuck, please help
    By bigsmoke101 in forum Loops & Control Statements
    Replies: 3
    Last Post: April 12th, 2011, 04:34 PM
  3. School java project, completely stuck
    By John1818 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 18th, 2010, 04:10 AM
  4. Stuck help please!
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 5th, 2010, 05:31 PM
  5. I'm stuck
    By iank in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2009, 10:21 AM