Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program in Java that asks the user to enter one of the following streams: science, commerce, or arts. Based on the user's choice,
Write a program in Java that asks the user to enter one of the following streams:
science, commerce, or arts. Based on the user's choice, the program should print the
courses available in that stream. The program should use conditional statements to
determine which courses are available, and it should use the toLowerCase method
to convert the user input to lowercase so that it can match the even if the user
enters the stream in uppercase or mixed case letters. If the user enters an invalid
stream, the program should print an error message.
Import the required packages, such as the java.util.Scanner package, which
will be used to take input from the user.
Create a new Scanner object to read the user's input.
Prompt the user to enter one of the streams: science, commerce, or arts.
Read the user's input and store it in a string variable.
Use the toLowerCase method to convert the user's input to lowercase.
Use conditional statements to determine which courses are available based on
the user's input.
print an error message indicating that the user has entered an invalid stream.
Close the Scanner object to release any resources it is using.
Run the program and test it by entering various streams in uppercase,
lowercase, or mixed case and checking if the correct courses are printed.
OUTPUT:
For the commerce stream, the following courses are available in first year:
Accountancy
Business Studies
Economics
Entrepreneurship
Invalid stream. Please enter a valid stream science commerce, arts
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started