Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles,...

50.1K

Verified Solution

Question

Programming

Using a Java.

2. Write a Java program calculate_fare.java to take the inputfor number of miles, and the class of journey (1,2, or 3, forfirst, second, and third class respectively), for a trainjourney.

The program should then calculate and display the fare ofjourney based on the following criteria:
Note: Use Switch...case and if...elseconstruct

First (1) Class

Second (1) Class

Third (3) Class

First 100 mile

$ 3 per mile

$ 2 per mile

$ 1.50 per mile

Next 150 mile

$ 2.50 per mile

$ 1.50 per mile

$ 1 per mile

Remaining

$ 2 per mile

$ 1 per mile

$ 0.50 per mile

Rubric:
- Input, usage of appropriate data types - 2 points
- Appropriate usage of if...else in each case of switch constructfor each class of journey : 4 points
- Documentation and appropriate variable names- 2 points

The layout of  switch case should be as follows:

switch(cls)//class

{

     case 1: if construct for calculatingfare for class 1

     case 2: if construct for calculatingfare for class 2

     case 3: if construct for calculatingfare for class 3

     default: Display it is an invalidclass

}

Answer & Explanation Solved by verified expert
3.6 Ratings (541 Votes)
If you have any doubts please give me comment import    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students