Explore BrainMass
Share

Explore BrainMass

    Java program asks the user how many automobiles are described.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a program that asks the user how many automobiles are to be described, and for each automobile it inputs the user's selection of make and color. Then it outputs color and make. Although you could do this easily using a simple procedural program, do it by using a main method in class AutomobileDriver to instantiate an object called auto from a class Automobile.

    In the Automobile class, do the following:

    Create a setMake() method. In this method, prompt the user "Input make of auto: ". Store their input into a make variable.
    Create a setColor() method. In this method, prompt the user "Input color of auto: ". Store their input into a color variable.
    Create "getter" methods for make and color.
    Create a printAll() method. In this method, print the color and make of the automobile on one line in accordance to the sample session given below.

    In the AutomobileDriver class, do the following:

    Create an instance of Automobile.
    Call the setMake() method.
    Call the setColor() method.
    Call the printAll() method.

    Be sure your output is similar to the following:

    How many autos do you want?: 2
    Enter make: Honda
    Enter color: Blue

    Enter make: Chevy
    Enter color: Red

    You have a Blue Honda.
    You have a Red Chevy.

    © BrainMass Inc. brainmass.com October 10, 2019, 4:27 am ad1c9bdddf
    https://brainmass.com/computer-science/arrays/java-program-automobiles-described-460947

    Solution Preview

    First, we create an Automobile class given below.

    public class Automobile {

    private String make;
    private String color;

    public String getMake() {
    return this.make;
    }

    public void setMake(String make) {
    this.make = make;
    }

    public String getColor() {
    return this.color;
    }

    public void setColor(String color) {
    this.color = color;
    }

    public void printAll() {
    System.out.println("You have a " + this.color + " " + this.make);
    }

    }

    Next, we create ...

    Solution Summary

    The expert writes a java program that asks the user how many automobiles are to be described.

    $2.19