Answer to Question #327823 in Java | JSP | JSF for Siyabonga

Question #327823

Write a java program for Tlhogi’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as R25, R22, R15, or R5, accordingly. Display an error message if the user enters an invalid item. Save the file as CarCareChoice.java.




It might not be reasonable to expect users to type long entries such as “oil change” accurately. Modify the CarCareChoice class so that as long as the user enters the first three characters of a service, the choice is considered valid. Save the file as CarCareChoice2.java.




Finally write a test class to test both classes. Save the file as TestCarCareChoice.java

1
Expert's answer
2022-04-13T14:21:07-0400
import java.util.Scanner;

public class CarCareChoise {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("List of available services: oil change, tire rotation, battery check, or brake inspection.");
        System.out.print("Choose a service: ");
        String choose=scan.next();
        if(choose.contains("oil")){
            System.out.println("You chose an oil change.Price: R25 ");
        }
        else if(choose.contains("tir")){
            System.out.println("You chose a tire rotation.Price: R22 ");
        }
        else if(choose.contains("bat")){
            System.out.println("You chose a battery check.Price: R15");
        }
        else if(choose.contains("bra")){
            System.out.println("You chose a brake inspection.Price: R5 ");
        }
        else{
            System.out.println("Error, you chose an invalid item");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS