Question: Java Exercise 1 (10 marks) (Ex1.java) An automobile showroom manager wants to keep track of the cars. He want a program keep information about each
Exercise 1 (10 marks) (Ex1.java) An automobile showroom manager wants to keep track of the cars. He want a program keep information about each car. He wants to know, its brand, color, manufacturing Year, and price. 1. Create a Java class "cars" that has the following attributes: brand (String), color (String), manufacturing Year (int) and price (double). Give all attributes a private visibility. (2 marks) 2. Write two constructors for the class cars: one without parameters, and another with parameters to fill all its attributes. (2 marks) 3. Write an accessor and a mutator method for each attribute. Make all methods public. (3 marks) 4. Write a "toString" method to display the attributes of the class "cars" (1 mark) 5. Create a new Java Main class "testAutomobile" to test your "Cars" class. The class should have a main method to do the following: a. Create an object called "blackCars" of type "Cars" using the constructor without parameters(1 marks) b. Set the brand of the blackCars to "Nissan", color to "Black", manufacturing year to 2018, and price to 141.500 using the mutator methods. (1 marks) c. Display the blackCars object using the toString method. (1 marks) d. Create another object called "redCars" of type "Cars" using the constructor with parameters, setting the brand to "Mercedese", color to "red", manufacturing year to :2019, and price to 270000.00 using the constructor. (1 marks) e. Display the red Cars using the toString() method. (1 marks) f. Open a file called "shoRoom.txt" that has all the information about the available cars in the show room. The file will look like this: BMW Blue 2010 80000 Tahoe Brown 2013 75000.500 Toyota White 2000 35000 Then the main method should read the information about each cars, create an object of type Cars and initialize its attributes, then display this object using the toString method. (2 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
