Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will need to parse this data and load it to the inventory of the dealership. After loading the inventory with the data, you will

You will need to parse this data and load it to the inventory of the dealership. After loading the inventory with the data, you will verify that the inventory has been loaded correctly by using the following methods in the Inventory class.

Vehicle findCheapestVehicle()

Vehicle findMostExpensiveVehicle()

double getAveragePriceOfAllVehicles()

Chevrolet Corvette 1963 200000 FALSE
Chevrolet Corvette 1957 130000 TRUE
Bugatti Chiron 2022 3500000 FALSE
Genesis G90 2022 495666 FALSE
Shelby Cobra 427 1965 2000000 TRUE
Chevrolet Camaro 1969 150000 TRUE
Ford Mustang Bullit 1968 180000 FALSE
Ferrari Testarossa 1992 180000 FALSE
Porche 911 2022 200000 TRUE
Bentley Bacalar 2022 1900000 TRUE

The most expensive vehicle is the Bugatti Chiron, cheapest vehicle is the Chevy Corvette 1957 and the average price for all vehicles is $893,566.60.

Write JUnit tests to verify this result in the DealershipTest.java class.

When finished, submit Dealership.java and DealershipTest.java.

Dealership.java

// import io exceptions

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class Dealership {

private Inventory inventory;

public Dealership() {

this.inventory = new Inventory();

}

public void loadInventoryFromFile(String file) throws IOException {

BufferedReader reader = new BufferedReader(new FileReader(file));

String line;

while ((line = reader.readLine()) != null) {

String[] fields = line.split(",");

if (fields.length != 5) {

throw new IOException("Invalid data format in file.");

}

String make = fields[0];

String model = fields[1];

int year = Integer.parseInt(fields[2]);

double price = Double.parseDouble(fields[3]);

boolean convertible = Boolean.parseBoolean(fields[4]);

Vehicle vehicle = new Vehicle(make, model, year, price, convertible);

inventory.add(vehicle);

}

reader.close();

}

public Inventory getInventory() {

return inventory;

}

DealershipTest.java

/ import org.junit.* libraries

// import library to open and read files

public class DealershipTest { private Dealership dealership;

/* Use the annotation @Before for a method that loads the data from a csv file. Create a setUp() method that throws an exception in case there is a problem reading the file. This method must create a new dealership object and import the data from a csv file. Place the file on your c: drive so the path is as follows "c:\dealership.csv" */

/* Use the annotation @Test for a method that tests for the cheapest vehicle at the dealership defined as follows: - Create a testCheapest() method. - Initialize the dealership inventory list - call method to find cheapest vehicle - use assertEquals to check for the cheapest vehicle given in specs */

/* Use the annotation @Test for a method that tests for the most expensive vehicle at the dealership defined as follows: - Create a testMostExpensive() method. - Initialize the dealership inventory list - call method to find most expensive vehicle - use assertEquals to check for the most expensive vehicle given in specs */

/* Use the annotation @Test for a method that tests for the average price for all of the vehicles at the dealership defined as follows: - Create a testAveragePrice() method. - Initialize the dealership inventory list - call method to find the average vehicle price - use assertEquals to check for the average vehicle price given in specs */

}

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 Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago