In Java Write a program that asks the user to enter how many automobiles are to be described, and for each automobile, it (the driver) inputs the user’s selection of make and color. Then the driver 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. Make your classes conform to the following UML class diagram: Let Automobile methods setMake and setColor do the prompting and inputting for make and color, and include input verification which asks again if a selection is illegal. Let Automobile methods printColor and printMake print color and make on one line. In AutomobileDriver, after asking auto to call setMake and setColor, use auto.printColor().printMake(); to chain the two printing methods. Write code so that the program can produce the following display: Sample session: How many cars do you want to consider? 2 Select Buick, Chevrolet, or Pontiac (b,c,p): x The only valid selections are 'b', 'c', or 'p' Select Buick, Chevrolet, or Pontiac (b,c,p): p Select blue, green, or red (b,g,r): r red Pontiac Select Buick, Chevrolet, or Pontiac (b,c,p): c Select blue, green, or red (b,g,r): g green Chevrolet The driver class: import java.util.Scanner; public class AutomobileDriver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int n; // quantity of cars Automobile auto = new Automobile(); System.out.print( "How many cars do you want to consider? "); n = stdIn.nextInt(); for (int i=0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Java

 

Write a program that asks the user to enter how many automobiles are to be
described, and for each automobile, it (the driver) inputs the user’s selection of
make and color. Then the driver 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. Make your classes conform to the following UML class diagram:
Let Automobile methods setMake and setColor do the prompting and inputting
for make and color, and include input verification which asks again if a selection
is illegal. Let Automobile methods printColor and printMake print color and
make on one line. In AutomobileDriver, after asking auto to call setMake and
setColor, use auto.printColor().printMake(); to chain the two printing methods.
Write code so that the program can produce the following display:

 

Sample session:
How many cars do you want to consider? 2
 Select Buick, Chevrolet, or Pontiac (b,c,p): x
 The only valid selections are 'b', 'c', or 'p'
 Select Buick, Chevrolet, or Pontiac (b,c,p): p
 Select blue, green, or red (b,g,r): r
 red Pontiac
 Select Buick, Chevrolet, or Pontiac (b,c,p): c
Select blue, green, or red (b,g,r): g
 green Chevrolet

 

The driver class:
import java.util.Scanner;
public class AutomobileDriver
{
 public static void main(String[] args)
 {
 Scanner stdIn = new Scanner(System.in);
 int n; // quantity of cars
 Automobile auto = new Automobile();
 System.out.print( "How many cars do you want to consider? ");
 n = stdIn.nextInt();
 for (int i=0; i<n; i++)
 {
 auto.setMake();
 auto.setColor();
 auto.printColor().printMake();
 System.out.println();
 } // end for
 } // end main
} // end class AutomobileDriver

Expert Solution
Step 1

In order to write a solution for this problem in Java, we will need to create a main method in the AutomobileDriver class. This method will be responsible for instantiating an object called auto from the Automobile class.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education