Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C5.1. (Chapter 9) Design a public class named Car to represent a car. The class contains: a. Five public integer constants named SUV, TRUCK, SEDAN,

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
C5.1. (Chapter 9) Design a public class named Car to represent a car. The class contains: a. Five public integer constants named SUV, TRUCK, SEDAN, MINIVAN, SPORTS_CAR b. A private int data field named type that specifies the type of car (default value is MINIVAN) c. Eight public integer constants named GAS, DIESEL, ELECTRICITY, HYDROGEN, NATURAL_GAS, WIND, SOLAR, WATER d. A private int data field named fuel that specifies the type of fuel for the car (default value is GAS) e. A private int data field named year that specifies the year of car (default value is 1980) I f. A private String data field named brand that specifies the brand of car (default value is "Ford") g. A private String data field named colour that specifies the colour of car (default value is "Red") h. The accessor and mutator methods for all five private data fields (type, fuel, year, brand, colour). A no-arg constructor that creates a default car j. A constructor that creates a car with the specified type, fuel, year, brand, and colour. Ensure that the parameter names of the constructor are the same name as the corresponding data fields. Utilize the "this" keyword to ensure the data fields are not hidden. 1. k. A method toString() that returns a string description for the car. For example, the default car must return the following string (year + colour + brand + fuel type): i. "1980 Red Ford Gas-powered Minivan" Draw the UML diagram for the class Car and then implement the class. The Car class must be part of the ca.car.package package (you need to figure out how to do this in Java) Write a test program (TestCar) that must also be part of the ca.car.package package. INFO 2313 LAB.85 Page 3 of 4 In the test program, create five Car objects using an array of Car objects: One of them must be the default car (to test the default constructor) Each five cars must be unique, with a different year, colour, brand, fuel and type For each car, print out the description using the tostring() method and encapsulate in a method that is called by the main method: o static void printCars (Car (c) Next, test the mutator methods: Ensure all of the cars are the same colour "Black" Randomly select two cars and set their fuel to GAS powered (use the Math.random() function to select the two, be careful to generate two different cars to modify) Randomly select two cars and set their brand to "Tesla" (use the Math. Random () function to select the two, careful to generate two different cars to modify) Randomly select three cars and set their type to SEDAN (use the Math.random() function to select the three, be careful to generate three different cars to modify) Encapsulate this code in its own method and call from the main method: o static void testMutatormethods (Car [] car) Print out all the mutated cars from the main method after returning from the test.Mutator Methods method, using printCars Test the accessor methods and print out using the Car class toString() method): Only the Black GAS-powered cars I Only the cars with the brand "Tesla" and type of SEDAN Only the alternate fuel cars (fuel is not equal to GAS and not equal to DEISEL) Encapsulate this code in its own method and call from the main method: o static void printCars (Car (c) Next, test the mutator methods: Ensure all of the cars are the same colour "Black" Randomly select two cars and set their fuel to GAS powered (use the Math. Random() ) function to select the two, be careful to generate two different cars to modify) Randomly select two cars and set their brand to "Tesla" (use the Math.random() function to select the two, be careful to generate two different cars to modify) Randomly select three cars and set their type to SEDAN (use the Math.random() ) function to select the three, be careful to generate three different cars to modify) Encapsulate this code in its own method and call from the main method: ostatic void testMutatormethods (Car [] car) Print out all the mutated cars from the main method after returning from the test Mutator Methods method, using printCars Test the accessor methods and print out (using the car class toString() method): Only the Black GAS-powered cars I Only the cars with the brand "Tesla" and type of SEDAN Only the alternate fuel cars (fuel is not equal to GAS and not equal to DETSEL) . Encapsulate this code in its own method and call from the main method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

1. How did you go about making your selection?

Answered: 1 week ago