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,
---------------------------------------------------------------
Not much I know, but atleast i'm trying! Some help would be greatly appreciated!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