Question: 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)
 Write a program in Java that asks the user to enter

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!