Question: modify the CarCareChoice 2 class so that as long as the user enters the first three characters of a service, the choice is considered valid:

modify the CarCareChoice2 class so that as long as the user enters the first three characters of a service, the choice is considered valid:
import java.util.*;
public class CarCareChoice2
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String []services={"oil change", "tire rotation", "battery check", "brake inspection"};
double []price={25,22,15,5};
System.out.println("Available Services");
for(String ser:services){
System.out.println("-"+ser);
}
System.out.println("Please enter the name of the service you would like");
String serviceChoice=input.nextLine().toLowerCase();
boolean found=false;
for (int i =0; i < services.length; i++){
if (services[i].toLowerCase().startsWith(serviceChoice)){
System.out.println("Enter selection >>"+ services[i]);
System.out.println(services[i]+" price is "+ price[i]);
found = true;
break;
}
}
if (!found){
System.out.println("Wrong service selected");
}
}
}

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 Programming Questions!