In: Computer Science
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?
CODE -
import java.util.Scanner;
public class input_system {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
// Take input from the user
System.out.print("What year did you start your degree? ");
String input = keyboard.nextLine();
keyboard.close();
// Split the string based on "/" to seperate season and year from the input
String[] season_input = input.split("/");
String season = season_input[0];
int year = Integer.parseInt(season_input[1]);
// Add 3 to the year.
// I have added 3 year as a sample.
// You can add any no. of years.
year += 3;
// Change season to summer.
// I have changed to summer as no. of years added is 3
// You can change to any season based on the requirement.
season = "Summer";
// Concatenate the season and year to form the output string
String output = season + "/" + Integer.toString(year);
// Display the course finishing year
System.out.println("You will finish your course in " + output);
}
}
SCREENSHOT -
If you have any doubt regarding the solution, then do
comment.
Do upvote.