82.0k views
1 vote
Write an application for Cody’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 $25, $22, $15, or $5, accordingly. Display Invalid Entry if the user enters an invalid item. Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Once you are happy with your results, click the Submit button to record your score.

1 Answer

3 votes

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Cody’s Car Care Shop");

System.out.println("Available services: oil change, tire rotation, battery check, and brake inspection");

System.out.print("Choose your service: ");

String service = input.nextLine();

if (service.equals("oil change"))

System.out.println("Your choice is: " + service + ". Its price is: $25");

else if (service.equals("tire rotation"))

System.out.println("Your choice is: " + service + ". Its price is: $22");

else if (service.equals("battery check"))

System.out.println("Your choice is: " + service + ". Its price is: $15");

else if (service.equals("brake inspection"))

System.out.println("Your choice is: " + service + ". Its price is: $5");

else

System.out.println("Invalid entry!");

}

}

Step-by-step explanation:

Print the available services

Ask the user for the service using Scanner

Check the service user entered using if else structure. If the service matches one of the options that is printed, print out the service and its price

Otherwise, print invalid entry

User Jason Sturges
by
3.8k points