Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Files to submit to for grading: . Vehicle java . Car.java, CarTest.java Truck.ja

ID: 3750541 • Letter: F

Question


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

Vehicle.java

public abstract class Vehicle implements Comparable<Vehicle> {

   protected String owner, yearMakeModel;
   protected double value;
   protected boolean altFuel;
   protected static int vehicleCount = 0;

   public Vehicle(String ownerIn, String ymmIn,
       double valueIn, boolean altFuelIn) {
      owner = ownerIn;
      yearMakeModel = ymmIn;
      value = valueIn;
      altFuel = altFuelIn;
      vehicleCount += 1;
   }
   public String getOwner() {
      return owner;
   }
   public void setOwner(String ownerIn) {
      owner = ownerIn;
   }
   public String getYearMakeModel() {
      return yearMakeModel;
   }
   public void setYearMakeModel(String ymmIn) {
      yearMakeModel = ymmIn;
   }
   public double getValue() {
      return value;
   }
   public void setValue(double valueIn) {
      value = valueIn;
   }
   public boolean getAlternativeFuel() {
      return altFuel;
   }
   public void setAlternativeFuel(boolean altFuelIn) {
      altFuel = altFuelIn;
   }
   public static int getVehicleCount() {
      return vehicleCount;
   }
   public static void resetVehicleCount() {
      vehicleCount = 0;
   }
   public abstract double useTax();
   public String toString() {
      return null;
   }
  
   public boolean equals(Object obj) {
      if (!(obj instanceof Vehicle)) {
         return false;
      }
      else {
         Vehicle other = (Vehicle) obj;
         return (owner + yearMakeModel + value).
            equals(other.owner + other.yearMakeModel + other.value);
      }
   }    
   public int hashCode() {
      return 0;
   }
   public int compareTo(Vehicle objIn) {
      int result;
      result = this.getOwner().compareTo(objIn.getOwner());
      return result;
   }
}


Car.java

import java.text.DecimalFormat;

public class Car extends Vehicle {
   public static final double TAX_RATE = 0.01;
   public static final double ALTERNATIVE_FUEL_TAX_RATE = 0.005;
   public static final double LUXURY_THRESHOLD = 50000;
   public static final double LUXURY_TAX_RATE = 0.02;

   public Car(String ownerIn, String yearMakeModelIn, double valueIn,
      boolean altFuelIn) {
      super(ownerIn, yearMakeModelIn, valueIn, altFuelIn);
   }
   public double useTax() {
      double tax = 0.0;
      if (altFuel) {
         tax = (value * ALTERNATIVE_FUEL_TAX_RATE);
      }
      else {
         tax = (value * TAX_RATE);      
      }
      if (value >= LUXURY_THRESHOLD) {
         tax += (value * LUXURY_TAX_RATE);
      }
      return tax;
   }
   public String toString() {
      DecimalFormat decFormat = new DecimalFormat("#,##0.00#");
      DecimalFormat decFormat2 = new DecimalFormat("#,##0.0##");
      double rate = 0.0;
      boolean lux = false;
      if (altFuel) {
         rate = ALTERNATIVE_FUEL_TAX_RATE;
      }
      else {
         rate = TAX_RATE;
      }
      String output = owner + ": Car " + yearMakeModel;
      if (altFuel) { output += " (Alternative Fuel)"; }
      output += " " + "Value: $" + decFormat.format(value) + " Use Tax: $"
         + decFormat.format(useTax()) + " with Tax Rate: "
         + decFormat2.format(rate);
      if (value >= 50000) { output += " Luxury Tax Rate: 0.02"; }
      return output;
   }
}

CarTest.java

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class CarTest {

   private Car car1 = new Car("Jones, Sam", "2017 Honda Accord",
       22000, false);
   private Car car2 = new Car("Jones, Jo", "2017 Honda Accord",
       22000, true);
   private Car car3 = new Car("Smith, Pat", "2015 Mercedes-Benz Coupe",
       110000, false);
   private Car car4 = new Car("Smith, Jack", "2015 Mercedes-Benz Coupe",
       110000, true);
   private Car car5 = new Car("blah, blah", "", 0, false);
   private Car car6 = new Car("Jones, Sam", "2017 Honda Accord",
       22000, false);
   private static final double DELTA = 1e-15;
   @Before public void setUp() {
   }

   @Test public void useTaxStdTest() {
      Assert.assertEquals(220.00, car1.useTax(), DELTA);
   }
   @Test public void notAltFuelTest() {
      Assert.assertEquals(220.00, car1.useTax(), DELTA);
   }

   @Test public void useTaxStdAltTest() {
      Assert.assertEquals(110.00, car2.useTax(), DELTA);
   }
   @Test public void useTaxLuxTest() {
      Assert.assertEquals(3300.00, car3.useTax(), DELTA);
   }
   @Test public void useTaxLuxAltTest() {
      Assert.assertEquals(2750.00, car4.useTax(), DELTA);
   }
   @Test public void toStringTest() {
      Assert.assertTrue(car1.toString().contains("with Tax Rate:"));
   }
   @Test public void toStringTest2() {
      Assert.assertTrue(car2.toString().contains("(Alternative Fuel)"));
   }
   @Test public void toStringTest3() {
      Assert.assertTrue(car3.toString().contains("Luxury Tax Rate: 0.02"));
   }
   @Test public void haseCodeTest() {
      Assert.assertEquals(0, car1.hashCode());
   }
   @Test public void equalsTest() {
      Assert.assertTrue(car1.equals(car6));
   }
   @Test public void notEqualsTest() {
      Assert.assertFalse(car1.equals(car2));
   }
   @Test public void notEqualsObjectTest() {
      Assert.assertFalse(car1.equals(null));
   }
   @Test public void getOwnerTest() {
      Assert.assertTrue(car1.getOwner().contains("Jones, Sam"));
   }
   @Test public void setOwnerTest() {
      car5.setOwner("User, Test");
      Assert.assertTrue(car5.getOwner().contains("User, Test"));
   }
   @Test public void getYearMakeModelTest() {
      Assert.assertTrue(car2.getYearMakeModel()
         .contains("2017 Honda Accord"));
   }
   @Test public void setYearMakeModelTest() {
      car5.setYearMakeModel("2018 Maserati Gilbi");
      Assert.assertTrue(car5.getYearMakeModel()
         .contains("2018 Maserati Gilbi"));
   }

   @Test public void getValueTest() {
      Assert.assertEquals(110000.00, car3.getValue(), DELTA);
   }
   @Test public void setValueTest() {
      car5.setValue(49000.00);
      Assert.assertEquals(49000.00, car5.getValue(), DELTA);
   }
   @Test public void getAlternativeFuelTest() {
      Assert.assertTrue(car2.getAlternativeFuel());
   }

   @Test public void setAlternativeFuelTest() {
      car5.setAlternativeFuel(true);
      Assert.assertTrue(car5.getAlternativeFuel());
   }
   @Test public void getVehicleCountTest() {
      car1.resetVehicleCount();
      Car testCar1 = new Car("", "", 0, false);
      Car testCar2 = new Car("", "", 0, false);
      Assert.assertEquals(2, car5.getVehicleCount());
   }
   @Test public void resetVehicleCountTest() {
      car5.resetVehicleCount();
      Assert.assertEquals(0, car5.getVehicleCount());
   }
}

Truck.java

import java.text.DecimalFormat;
public class Truck extends Vehicle {

   protected double tonage = 0.0;
   public static final double TAX_RATE = 0.02;
   public static final double ALTERNATIVE_FUEL_TAX_RATE = 0.01;
   public static final double LARGE_TRUCK_TONS_THRESHOLD = 2.0;
   public static final double LARGE_TRUCK_TAX_RATE = 0.03;

   public Truck(String ownerIn, String yearMakeModelIn, double valueIn,
      boolean altFuelIn, double tonageIn) {
      super(ownerIn, yearMakeModelIn, valueIn, altFuelIn);
      tonage = tonageIn;
   }
   public double getTons() {
      return tonage;
   }

   public void setTons(double tonageIn) {
      tonage = tonageIn;
   }
   public double useTax() {
      double tax = 0.0;
      if (altFuel) {
         tax = (value * ALTERNATIVE_FUEL_TAX_RATE);
      }
      else {
         tax = (value * TAX_RATE);      
      }
      if (tonage > LARGE_TRUCK_TONS_THRESHOLD) {
         tax += (value * LARGE_TRUCK_TAX_RATE);
      }
      return tax;
   }
   public String toString() {
      DecimalFormat decFormat = new DecimalFormat("#,##0.00#");
      DecimalFormat decFormat2 = new DecimalFormat("#,##0.0##");
      double rate = 0.0;
      boolean lux = false;
      if (altFuel) {
         rate = ALTERNATIVE_FUEL_TAX_RATE;
      }
      else {
         rate = TAX_RATE;
      }
      String output = owner + ": Truck " + yearMakeModel;
      if (altFuel) { output += " (Alternative Fuel)"; }
      output += " " + "Value: $" + decFormat.format(value) + " Use Tax: $"
         + decFormat.format(useTax()) + " with Tax Rate: "
         + decFormat2.format(rate);
      if (tonage > LARGE_TRUCK_TONS_THRESHOLD) {
         output += " Large Truck Tax Rate: " + LARGE_TRUCK_TAX_RATE; }
      return output;
   }
}

TruckTest.java

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TruckTest {

   private Truck truck1 = new Truck("Williams, Jo", "2012 Chevy Silverado",
      30000, false, 1.5);
   private Truck truck2 = new Truck("Williams, Sam", "2010 Chevy Mack",
      40000, true, 2.5);
   private Truck truck3 = new Truck("", "", 0.0, false, 0.0);
   private static final double DELTA = 1e-15;
   @Before public void setUp() {
   }
   @Test public void toStringTest() {
      Assert.assertTrue(truck1.toString().contains("Chevy Silverado"));
   }
   @Test public void toStringTest2() {
      Assert.assertTrue(truck2.toString().contains("(Alternative Fuel)"));
   }
   @Test public void getTonsTest() {
      Assert.assertEquals(1.5, truck1.getTons(), DELTA);
   }
   @Test public void setTonsTest() {
      truck3.setTons(1.2);
      Assert.assertEquals(1.2, truck3.getTons(), DELTA);
   }

   @Test public void useTaxStdTruckTest() {
      Assert.assertEquals(600.00, truck1.useTax(), DELTA);
   }
   @Test public void useTaxAltTruckTest() {
      Assert.assertEquals(1600.00, truck2.useTax(), DELTA);
   }

}

SemiTractorTrailer.java

public class SemiTractorTrailer extends Truck {
   protected int axles = 0;
   public static final double PER_AXLE_TAX_RATE = 0.005;

   public SemiTractorTrailer(String ownerIn, String yearMakeModelIn,
      double valueIn, boolean altFuelIn, double tonageIn, int axlesIn) {
      super(ownerIn, yearMakeModelIn, valueIn, altFuelIn, tonageIn);
      axles = axlesIn;
   }
   public int getAxles() {
      return axles;
   }
   public void setAxles(int axlesIn) {
      axles = axlesIn;
   }
   public double useTax() {
      double tax = 0.0;
      tax = super.useTax();
      tax += (value * PER_AXLE_TAX_RATE * axles);
      return tax;
   }
   public String toString() {
      String output = "";
      output = super.toString();
      output += " Axle Tax Rate: " + (PER_AXLE_TAX_RATE * axles);
      return output;  
   }
}

SemiTractorTrailerTest.java

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class SemiTractorTrailerTest {
   private SemiTractorTrailer semi1 = new SemiTractorTrailer("Williams, Pat",
      "2012 International Big Boy", 45000, false, 5.0, 4);
   private SemiTractorTrailer semi2 = new SemiTractorTrailer("Pederson, Bill",
      "2015 Peterbuilt Stallion", 85000, false, 5.0, 4);
   private SemiTractorTrailer semi3 = new SemiTractorTrailer("", "",
       0.0, false, 0.0, 0);
   private static final double DELTA = 1e-15;
   @Before public void setUp() {
   }
   @Test public void toStringTest() {
      Assert.assertTrue(semi1.toString().contains("Axle Tax Rate:"));
   }
   @Test public void getTonsTest() {
      Assert.assertEquals(5.0, semi1.getTons(), DELTA);
   }
   @Test public void setTonsTest() {
      semi3.setTons(4.2);
      Assert.assertEquals(4.2, semi3.getTons(), DELTA);
   }

   @Test public void useTaxStdTruckTest() {
      Assert.assertEquals(3150.00, semi1.useTax(), DELTA);
   }
   @Test public void useTaxAltTruckTest() {
      Assert.assertEquals(5950.00, semi2.useTax(), DELTA);
   }
   @Test public void getAxlesTest() {
      Assert.assertEquals(4, semi1.getAxles());
   }
   @Test public void setAxlesTest() {
      semi3.setAxles(5);
      Assert.assertEquals(5, semi3.getAxles());
   }

}

MotorcycleTest.java

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class MotorcycleTest {

   private Motorcycle bike1 = new Motorcycle("Brando, Marlon",
            "1964 Harley-Davidson Sportster", 14000, false, 750);
   private Motorcycle bike2 = new Motorcycle("Dean, James",
            "1962 Triumph Bonneville", 23000, false, 865);
   private Motorcycle bike3 = new Motorcycle("", "", 0.0, false, 0);
   private Motorcycle bike4 = new Motorcycle("Brando, Marlon",
            "1964 Harley-Davidson Sportster", 14000, false, 750);
   private Motorcycle bike5 = new Motorcycle("Johnson, Duane",
            "1975 Honda Scooter", 5000, true, 450);

   private static final double DELTA = 1e-15;
   @Before public void setUp() {
   }

   @Test public void useTaxStdTest() {
      Assert.assertEquals(280.00, bike1.useTax(), DELTA);
   }
   @Test public void useTaxAltFuelTest() {
      //Assert.assertEquals(460.00, bike5.useTax(), DELTA);
      Assert.assertTrue(bike5.toString().contains("(Alternative Fuel)"));
      
   }
   @Test public void useTaxLargeBikeTest() {
      Assert.assertTrue(bike2.toString().contains("Large Bike Tax Rate"));
   }
    
   @Test public void toStringTest() {
      Assert.assertTrue(bike1.toString().contains("Motorcycle"));
   }

   @Test public void haseCodeTest() {
      Assert.assertEquals(0, bike1.hashCode());
   }

   @Test public void equalsTest() {
      Assert.assertTrue(bike1.equals(bike4));
   }

   @Test public void notEqualsTest() {
      Assert.assertFalse(bike1.equals(bike2));
   }

   @Test public void getOwnerTest() {
      Assert.assertTrue(bike1.getOwner().contains("Brando, Marlon"));
   }
   @Test public void setOwnerTest() {
      bike3.setOwner("User, Test");
      Assert.assertTrue(bike3.getOwner().contains("User, Test"));
   }

   @Test public void getYearMakeModelTest() {
      Assert.assertTrue(bike2.getYearMakeModel()
         .contains("1962 Triumph Bonneville"));
   }
   @Test public void setYearMakeModelTest() {
      bike3.setYearMakeModel("2018 Harley-Davidson Softtail");
      Assert.assertTrue(bike3.getYearMakeModel()
         .contains("2018 Harley-Davidson Softtail"));
   }
   @Test public void getValueTest() {
      Assert.assertEquals(23000.00, bike2.getValue(), DELTA);
   }
   @Test public void setValueTest() {
      bike3.setValue(49000.00);
      Assert.assertEquals(49000.00, bike3.getValue(), DELTA);
   }
   @Test public void getAlternativeFuelTest() {
      Assert.assertFalse(bike1.getAlternativeFuel());
   }
   @Test public void setAlternativeFuelTest() {
      bike3.setAlternativeFuel(true);
      Assert.assertTrue(bike3.getAlternativeFuel());
   }

   @Test public void getEngineSizeTest() {
      Assert.assertEquals(750, bike1.getEngineSize());
   }
   @Test public void setEngineSizeTest() {
      bike3.setEngineSize(950);
      Assert.assertEquals(950, bike3.getEngineSize());
   }






}

Motorcycle.java

import java.text.DecimalFormat;
public class Motorcycle extends Vehicle {
   protected int engine = 0;
   public static final double TAX_RATE = 0.005;
   public static final double ALTERNATIVE_FUEL_TAX_RATE = 0.0025;
   public static final double LARGE_BIKE_CC_THRESHOLD = 499;
   public static final double LARGE_BIKE_TAX_RATE = .015;
   public Motorcycle(String ownerIn, String yearMakeModelIn,
      double valueIn, boolean altFuelIn, int engineIn) {
      super(ownerIn, yearMakeModelIn, valueIn, altFuelIn);
      engine = engineIn;
   }

   public int getEngineSize() {
      return engine;
   }
   public void setEngineSize(int engineIn) {
      engine = engineIn;
   }
   public double useTax() {
      double tax = 0.0;
      if (altFuel) {
         tax = (value * ALTERNATIVE_FUEL_TAX_RATE);
      }
      else {
         tax = (value * TAX_RATE);      
      }
      if (engine > LARGE_BIKE_CC_THRESHOLD) {
         tax += (value * LARGE_BIKE_TAX_RATE);
      }
      return tax;
   }
   public String toString() {
      DecimalFormat decFormat = new DecimalFormat("#,##0.00#");
      DecimalFormat decFormat2 = new DecimalFormat("#,##0.0##");
      double rate = 0.0;
      boolean lux = false;
      if (altFuel) {
         rate = ALTERNATIVE_FUEL_TAX_RATE;
      }
      else {
         rate = TAX_RATE;
      }
      String output = owner + ": Motorcycle " + yearMakeModel;
      if (altFuel) { output += " (Alternative Fuel)"; }
      output += " " + "Value: $" + decFormat.format(value) + " Use Tax: $"
         + decFormat.format(useTax()) + " with Tax Rate: "
         + decFormat2.format(rate);
      if (engine >= LARGE_BIKE_CC_THRESHOLD) {
         output += " Large Bike Tax Rate: " + LARGE_BIKE_TAX_RATE; }
      return output;
   }


}

VehiclesPart1.java

import java.io.FileNotFoundException;
public class VehiclesPart1 {
   public static void main(String[] args) {

      UseTaxList tmpTaxList = new UseTaxList();
      try {
         tmpTaxList.readVehicleFile("vehicle_1.txt");
      }
      catch (FileNotFoundException ex) {
         ex.printStackTrace();
      }
      System.out.println(tmpTaxList.summary());
      System.out.println(" ");
      System.out.println(tmpTaxList.listByOwner());
      System.out.println(" ");
      System.out.println(tmpTaxList.listByUseTax());
      System.out.println(" ");
      System.out.println(tmpTaxList.excludedRecordsList());
   }
}

VehiclesPart1Test.java

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class VehiclesPart1Test {
   @Before public void setUp() {
     
       testVehicle = new VehiclesPart1();
   }
   @Test public void testVehiclesPart1() {
      VehiclesPart2 vPart2Obj = new VehiclesPart2(); // test constructor
      String[] args = {"vehicles1.txt"};
      Vehicle.resetVehicleCount();
      VehiclesPart2.main(args);
      Assert.assertEquals(8, Vehicle.getVehicleCount());
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote