Question

In: Computer Science

I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...

I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date. Also it needs to be able to change from Autumn, to another season depending on the amount of years it takes. So if the course will take 3 years, the student will finish "Summer/2025". How can I implement this?

Solutions

Expert Solution

Note: Done accordingly. Please comment for any problem. Please Uprate. Thanks

Code:

package Test;

import java.util.Scanner;

public class CourseTerm {

   public static void main(String[] args) {
       Scanner input=new Scanner(System.in);
       String seasonAndYear,season;
       int year ;
       while(true){ //loop until proper input is given
           System.out.print("What season and year did you start your degree? (eg. Autumn/2022) :");//asking for input
           seasonAndYear=input.nextLine();
           //checking for proper input
           if(seasonAndYear.contains("/")) {
               String[] arrOfStr = seasonAndYear.split("/");
               if(arrOfStr.length==2) {//checking for proper input
                   try
                   {
                       year=Integer.parseInt(arrOfStr[1]);
                       season=arrOfStr[0];
                       //checking for proper input
                       if(season.equalsIgnoreCase("Autumn") || season.equalsIgnoreCase("Summer")||season.equalsIgnoreCase("Spring")||season.equalsIgnoreCase("Winter")) {
                           season=getEndSeason(season); //calling function to get end of the season
                           System.out.println("For 2 year course you will end in :"+(year+2)+"/"+season);//Printing for 2 year course
                           System.out.println("For 3 year course you will end in :"+(year+3)+"/"+season);//Printing for 3 year course
                           break;
                       }else {//Printing error message
                           System.out.println("Invlaid Input. Please give again... Format is Autumn/2022");
                       }
                   }catch(Exception e) {//Printing error message
                       System.out.println("Invlaid Input. Please give again... Format is Autumn/2022");  
                   }
                      
               }else {//Printing error message
                   System.out.println("Invlaid Input. Please give again... Format is Autumn/2022");
               }
           }else {//Printing error message
               System.out.println("Invlaid Input. Please give again... Format is Autumn/2022");
           }
       }
       input.close();
   }

   private static String getEndSeason(String season) {
       season=season.toLowerCase();
       //returning season based on start season
       if(season.equalsIgnoreCase("autumn")) {
           return "Summer";
       }else if(season.equalsIgnoreCase("summer")) {
           return "Spring";
       }else if(season.equalsIgnoreCase("spring")) {
           return "Winter";
       }else if(season.equalsIgnoreCase("winter")) {
           return "Autumn";
       }
       return null;
   }

}

Output:


Related Solutions

I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
JAVA - I am asking for the user to input their firstName and lastName but I...
JAVA - I am asking for the user to input their firstName and lastName but I want the method myMethod() to be able to print it when it is called. Is that possible? I'm new to Java and i'm not too sure what I should do to fix this. Also if I were to create a IF statement would I have to declare int amountDeposited; , int accountBalance; , int newBalance; in the new if statement. import java.util.Scanner; import java.util.Arrays;...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
I need to draw a cylinder in java with user input, and I can't seem to...
I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input... I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.            g.drawOval(80, 110, radius, height);            g.drawLine(?, ?, ?, ?); g.drawLine(?, ?, ?, ?);   ...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
in Java, I need to create an array of animals. The user is going to be...
in Java, I need to create an array of animals. The user is going to be prompted to enter the size of the array where a valid size is 10-30(inclusive). Then I have to populate only half of this array. I am not sure how to do that so can you please write comments explaining. Thank you
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT