Only the following part Isabel required: UseTaxList.java and UseTaxListTest.java
ID: 3750827 • Letter: O
Question
Only the following part Isabel required: UseTaxList.java and UseTaxListTest.java UseTaxComparator.java and UseTaxComparatorTest.java VehiclesPart2.java and VehiclesPart2Test.java
Files to submit to for grading: . Vehicle java . Car.java, CarTest.java Truck.java, TruckTest.java .SemiTractorTrailer.java, SemiTractorTrailerTest.java Motorcycle.java, MotorcycleTest.java VehiclesPartl java, VehiclesPartITest.java Specifications Overview: This project is the first of three parts that will involve calculating the annual use tax for vehicles where the amount is based on the type of vehicle, its value, and various tax rates. You will develop Java classes that represent categories of vehicles: car, truck, semi-tractor trailer (a subclass of truck), and motorcycle. These categories will be implemented as follows: an abstract Vehicle class which has three subclasses Car, Truck, and Motorcycle. The Truck class has a subclass SemiTractorTrailer. The driver class for this project, VehiclesPart1.java, should contain a main method that creates one or more instances of each of the non-abstract classes in the Vehicle hierarchy. As you develop each non-abstract class, you should add code in the main method to create and print one or more instances of the class. Thus, after you have created all the classes, your main method should create and print one or more objects (e.g, at least one for each of the types Car, Truck, SemiTractorTrailer, and Motorcycle). You can use VehiclesPart 1 in conjunction with interactions b running the program in the canvas (or debugger with a breakpoint) and single stepping until the each of the instances is created. You can then enter interactions for the instances in the usual way. However, a more efficient way to test your methods would be to create the JUnit test file (required for Partl Vehicle Car Truck Motorcycle SemiTractorTrailer Projet Class Inhar tance
Explanation / Answer
I have implemented Part 1 in the previous question, Below are the rest of the classes with Junits.
CarTest.java
public class CarTest {
/** Fixture initialization (common initialization
* for all tests). **/
@Before public void setUp() {
}
/** test useTax.
* @throws NegativeValueException here.
**/
@Test public void useTaxTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
22000, false);
double cost = car1.useTax();
Assert.assertEquals(220, cost, 0.01);
}
/** test useTax alt.
* @throws NegativeValueException here.
**/
@Test public void useTaxAltTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
22000, true);
double cost = car1.useTax();
Assert.assertEquals(110, cost, 0.01);
}
/** test useTax threshold.
* @throws NegativeValueException here.
**/
@Test public void useTaxThresholdTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
double cost = car1.useTax();
Assert.assertEquals(3330, cost, 0.01);
}
/** test toString .
* @throws NegativeValueException here.
**/
@Test public void toStringTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
22000, false);
String toString = "Smith, John: Car 2017 Honda Accord "
+ "Value: $22,000.00 Use Tax: $220.00 "
+ "with Tax Rate: 0.01";
Assert.assertEquals(car1.toString(), toString);
}
/** test toString alt.
* @throws NegativeValueException here.
**/
@Test public void toStringAltTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
22000, true);
String toString = "Smith, John: Car 2017 Honda Accord "
+ "(Alternative Fuel) "
+ "Value: $22,000.00 Use Tax: $110.00 "
+ "with Tax Rate: 0.005";
Assert.assertEquals(car1.toString(), toString);
}
/** test toString lux.
* @throws NegativeValueException here.
**/
@Test public void toStringLuxTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
String toString = "Smith, John: Car 2017 Honda Accord "
+ "Value: $111,000.00 Use Tax: $3,330.00 "
+ "with Tax Rate: 0.01 Luxury Tax Rate: 0.02";
Assert.assertEquals(car1.toString(), toString);
}
/** test toString alt lux.
* @throws NegativeValueException here.
**/
@Test public void toStringAltLuxTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, true);
String toString = "Smith, John: Car 2017 Honda Accord "
+ "(Alternative Fuel) "
+ "Value: $111,000.00 Use Tax: $2,775.00 "
+ "with Tax Rate: 0.005 Luxury Tax Rate: 0.02";
Assert.assertEquals(car1.toString(), toString);
}
/** test compareTo.
* @throws NegativeValueException here.
**/
@Test public void compareToTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
Car car2 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
Assert.assertEquals(0, car1.compareTo(car2));
}
/** test equals true.
* @throws NegativeValueException here.
**/
@Test public void equalsTrueTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
Car car2 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
Assert.assertEquals(true, car1.equals(car2));
}
/** test equals false.
* @throws NegativeValueException here.
**/
@Test public void equalsFalseTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
Object car2 = new Object();
Assert.assertEquals(false, car1.equals(car2));
}
/** test hashCode.
* @throws NegativeValueException here.
**/
@Test public void hashCodeTest() throws NegativeValueException {
Car car1 = new Car("Smith, John", "2017 Honda Accord",
111000, false);
int here = car1.hashCode();
Assert.assertEquals(here, 0);
}
}
MotorcycleTest.java
TruckTest.java
UseTaxComparatorTest.java
VehiclesPart2.java
Hope this covers everything. Please let me know if you have any issues
UseTaxListTest.java
VehiclesPart2Test.java
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.