Question: Here's the problem. How to solve it? Below is the essential code. //AutoShowroom class. public class AutoShowroom { Car[] arr; //printStatus() method. public void printStatus()

![code. //AutoShowroom class. public class AutoShowroom { Car[] arr; //printStatus() method. public](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f678615fb77_70466f67860c5b57.jpg)

Here's the problem. How to solve it?
Below is the essential code.
//AutoShowroom class. public class AutoShowroom { Car[] arr; //printStatus() method. public void printStatus() { //printng the welcome message. System.out.println("Welcome to FIT2099 Showroom"); //creating the array of 3 Car objects. arr = new Car[3]; //calling the createCars() method. createCars(); //calling the diplayCars() method. displayCars(); //printing the thank you message. System.out.println("Thank you for visiting FIT2099 Showroom"); } //createCars() method. public void createCars() { //creating the 3 Car objects with values. arr[0] = new Car("BMW","X7"); arr[1] = new Car("Audi","A8"); arr[2] = new Car("Mercedes","GLS"); } //displayCars() method. public void displayCars() { int count = 1; //printing the Car object details using the foreach loop. for(Car obj:arr) { System.out.println("Car (" + count + ") " + obj.getCarDescription()); count++; } } } Car.java
//Car class. public class Car { //Car class data members. private String make; private String model; //constructor for the Car class. public Car(String make,String model) { this.make = make; this.model = model; } //getCarDescription() method. public String getCarDescription() { return "Maker:" + make + " and Model:" + model; } } AutoShowroomDriver.class
//AutoShowroomDriver class. public class AutoShowroomDriver { //main() method. public static void main(String[] args) { //creating the AutoShowroom object. AutoShowroom obj = new AutoShowroom(); //calling the printStatus() method. obj.printStatus(); } }Task 2. Refactor Auto Showroom to use ArrayList Native Java arrays have some significant limitations - not least, they are statically allocated. That means that their maximum size is fixed at the time of their creation - you can't easily resize an array. We would like to change Auto Showroom to make it easier to add new cars. Fortunately, the Java class libraries provide a wide variety of collection classes in the Java Collections Framework. We will use one called the ArrayList class. Modify the AutoShowroom class to use an ArrayList rather than an array to store the collection of Cars. Task 3. Refactor Car's method names using your IDE's refactoring tools In Week 2, you created a Car class with a method called getCar Description() that returns a string consisting of the car maker and the car model. This is not really a good name. By convention in Java, methods starting with get return the value of an attribute, and that's not what this method does. Also, since it is a part of the Car class, we really don't need the "Car" part of the method name. We can just call it description(). Making this sort of change using a simple text editor can be a lot of work. We need to change the method name not only in the Car class but also in every client of Car that uses that method. We don't want to change any method that has the same name but belongs to a different class. Fortunately, Most modern IDEs provide refactoring tools to help. Go to the Class class and find the method getCarDescription(). Select the text getCarDescription() and then right-click on it to bring up a menu. Choose Refactor Rename. Edit the method name to be just description(). The IDE will analyse the code for the system and change the method name everywhere it occurs. Now open the AutoShowroom class and check that the method name has changed where it is used in the method displayCars(). Once you have made the changes, informally test your program to ensure that the functionality is unchanged. Refactoring should not change what your program does, only how it does it. In a larger project, you would use automated unit tests and possibly system tests to ensure that your refactoring has not affected any functionality. Task 4. Create a Buyer and a Bid class We need to add a Buyer class to our system. You will need to use some of the new Java language features we have seen in lectures to implement Buyer, including private attributes and constructors. The Buyer class needs to have private attributes to store: the buyer's ID (buyertld) the buyer's given name (givenName) family name (familyName) Note that we have not specified the type of buyertld. You can choose to use a numeric integer type, or a Java string. This kind of decision is actually a design decision. Create a text file called Justifications.txt and add it to the top-level directory of your project. In it, briefly list the advantages and disadvantages of using both, and justify your final decision. "I don't know how to use Java integers very well" is not in itself sufficient justification. Additionally, add a comment explaining why you should use "givenName" and "familyName" rather than "firstName" and "lastName". Implement two constructors for Buyer, with these signatures: Buyer("type* newBuyerld) Buyer("type* newBuyerld, String newGivenName, String newFamilyName) Replace type with the name of the type you have used as the attribute. These features provide two different ways of creating and initialising a Buyer object. Next, implement two mutators (methods that change attribute values): setGivenName(...) . setFamilyName(...) These should both take String arguments. Finally, implement an accessor method called description) that returns a String containing the Buyer ID, given name, and family name concatenated together, in that order and separated by spaces, Similar to the Buyer class, add a new class that represents a bid on a car. The Bid class needs to have private attributes to store: 1. the bid's ID 2. an instance of the Buyer class 3. the price of the bid 4. the date of the bid (you can use Date class from Util package or a simple string) Add setters and getters for all the four attributes mentioned above. Add a constructor that accepts as input values for the four attributes. Task 5. Adding Bids to Cars First, add an ArrayList attribute called bids to Car to store a collection of Bids objects. Again, justify your choice in Justifications.txt. Add a method addBid(Buyer newBuyer, price, date) to Car to add a new bid in a car. In the Auto Showroom class, modify createCars() so that it also creates some Buyers and Bids objects and add them to some cars. Make sure you test both Bid and Buyer constructors and the mutators. Modify displayCars() so that, as well as displaying the description for each car, it also displays a list of the bids and their buyers. You will need to decide how to access the bids and buyers in Car from the AutoShowroom class. There should be no I/O in any class other than AutoShowroom, and the mechanism should not allow the bids array stored in Car to be modified by any other class. Task 6. Add console 1/0 Many programs that you will write, including the assignments in this subject, will have a user interface of some kind, to allow humans to interact directly with them. These days, most such programs use some kind of graphical user interface, which is often web-based. However, in certain circumstances, a console-based user interface is used. You'll see a console-based user interface if you open the command prompt (or PowerShell) in Windows) or a Terminal on a Mac or a Linux machine. A console user interface is a bit like having a two-way conversation with an old typewriter (which in fact how they originally worked). You'd type something of its own. at the keyboard, hit enter, and then the computer would respond with some text out Console-based user interfaces are usually less attractive and harder to learn, but they: can be as fast or faster to use than a GUI for experienced users, can be used over a slow or heavily loaded network connection, can be easily scripted with another computer program taking the place of the human typing the input, and importantly, are much easier to write than a GUI or web interface! There are several ways to implement a console user interface in Java. Unfortunately, the simplest method is the Console class2, is incompatible with your IDE's console where the output displays when you run from within the IDE. Modify Auto Showroom so that when Bid and Buyer objects are created, the user is prompted to enter the buyer's first name, last name, buyer ID, bid price, and date
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
