Question

a. Write an application for Cody's Car Care Shop that shows a user a list of...

a. 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 an error message if the user enters an invalid item. Save the file as CarCareChoice.java.

b. 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.

Java Programming 8th Edition

Chapter 8 Exercise 3a-b

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class CarCareChoice {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Available services: oil change, tire rotation, battery check, or brake inspection");
        System.out.print("Select one of the service above: ");
        String service = scanner.nextLine();
        if(service.equalsIgnoreCase("oil change")){
            System.out.println("Price for "+service+" is $25");
        }
        else if(service.equalsIgnoreCase("tire rotation")){
            System.out.println("Price for "+service+" is $22");
        }
        else if(service.equalsIgnoreCase("battery check")){
            System.out.println("Price for "+service+" is $15");
        }
        else if(service.equalsIgnoreCase("brake inspection")){
            System.out.println("Price for "+service+" is $5");
        }
        else{
            System.out.println("Invalid service");
        }
            
    }
}

////////////////////////////////////////////////////////////////////////

import java.util.Scanner;

public class CarCareChoice2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Available services: oil change, tire rotation, battery check, or brake inspection");
        System.out.print("Select one of the service above: ");
        String service = scanner.nextLine();
        if(service.substring(0,3).equalsIgnoreCase("oil")){
            System.out.println("Price for "+service+" is $25");
        }
        else if(service.substring(0,3).equalsIgnoreCase("tir")){
            System.out.println("Price for "+service+" is $22");
        }
        else if(service.substring(0,3).equalsIgnoreCase("bat")){
            System.out.println("Price for "+service+" is $15");
        }
        else if(service.substring(0,3).equalsIgnoreCase("bra")){
            System.out.println("Price for "+service+" is $5");
        }
        else{
            System.out.println("Invalid service");
        }

    }
}
Add a comment
Know the answer?
Add Answer to:
a. Write an application for Cody's Car Care Shop that shows a user a list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (A). Write an application that extends JPanel and displays a pharse in large font. Each time...

    (A). Write an application that extends JPanel and displays a pharse in large font. Each time the user clicks a JButton, display the same pharse in a different color, a little further to the right, and in a slightly smaller font. Allow only three clicks…Save the file as JChangeSizeAndColorPanel.java (B). Modify the JChangeSizeAndColorPanel application so that it continuously changes the size, color, and location of phrase as long as the user continues to click the button. Save file as JChangeSizeAndColorPanel2.java

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • FIRST: Write code that prompts the user for the name of a text file, opens that...

    FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each line to the screen. You must implement the file read in a try/catch block rather than throwing the exception on the main method. NEXT: Modify your code so that the program takes the name of two files from the command line, opens the first file if it exists for...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

  • Pop’s Pie Shop wants you to help computerize its ever-changing menu. Here’s an example of the...

    Pop’s Pie Shop wants you to help computerize its ever-changing menu. Here’s an example of the delicious items that Pop’s has to offer: Here is what we are starting with today: Savory: Savory Mince & Cheese Pork & Peach BBQ C urried Lamb & Spinach Chicken & Kumara Smoked Salmon, Leek & Potato Thai Butternut Curry (vegan) Sausage Roll Spinach & Cheese Roll Beef Pasty Sweet Pie by the slice: Banoffee Blueberry Apple (vegan) Buttermilk & Raspberry Chocolate Chess Chocolate...

  • In the original flashcard problem, a user can ask the program to show an entry picked...

    In the original flashcard problem, a user can ask the program to show an entry picked randomly from a glossary. When the user presses return, the program shows the definition corresponding to that entry. The user is then given the option of seeing another entry or quitting. A sample session might run as follows: Enter s to show a flashcard and q to quit: s Define: word1 Press return to see the definition definition1 Enter s to show a flashcard...

  • this needs to be in Java: use a comparator class which is passed into the sort...

    this needs to be in Java: use a comparator class which is passed into the sort method that is available on the ArrayList. import java.util.Scanner; public class Assign1{ public static void main(String[] args){ Scanner reader = new Scanner (System.in); MyDate todayDate = new MyDate(); int choice = 0; Library library = new Library(); while (choice != 6){ displayMainMenu(); if (reader.hasNextInt()){ choice = reader.nextInt(); switch(choice){ case 1: library.inputResource(reader, todayDate); break; case 2: System.out.println(library.resourcesOverDue(todayDate)); break; case 3: System.out.println(library.toString()); break; case 4: library.deleteResource(reader,...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT