TASK - Update VehicleApp project: Write a Java code that follow class diagram relationship and apply overriding method f

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

TASK - Update VehicleApp project: Write a Java code that follow class diagram relationship and apply overriding method f

Post by answerhappygod »

Task Update Vehicleapp Project Write A Java Code That Follow Class Diagram Relationship And Apply Overriding Method F 1
Task Update Vehicleapp Project Write A Java Code That Follow Class Diagram Relationship And Apply Overriding Method F 1 (84.94 KiB) Viewed 43 times
Existing Vehicle Project:
//Car.java
package vehicleapp;
public class Car extends Vehicle{

private String model;
private double cc;

public Car(String powertrain, String type, String
transmission, String model, float cc){
super(powertrain, type,
transmission);
this.model=model;
this.cc=cc;}
//accessor & mutator method
public String getModel(){
return model;}
public void setModel(String model) {
this.model = model;}

public double getCc(){
return cc;}

public void setCc(double cc){
this.cc = cc;}

public double getLiters(){
return cc/1000;}

@Override
public double getRoadtaxPrice(){

double roadtaxPrice=0;

if(cc<=1000){
roadtaxPrice=20;}

else if(cc<=1200){
roadtaxPrice=55;}

else if(cc<=1400){
roadtaxPrice=70;}

else if(cc<=1600){
roadtaxPrice=90;}

else if(cc<=1800){

roadtaxPrice=200+((cc-1600)*0.4);}

else if(cc<=2000){

roadtaxPrice=280+((cc-1800)*0.5);}

else if(cc<=2500){

roadtaxPrice=380+((cc-2000)*1);}

else if(cc<=3000){

roadtaxPrice=880+((cc-2500)*2.50);}

else if(cc>3000){

roadtaxPrice=2130+((cc-3000)*4.50);}

return roadtaxPrice;}
}
//Tyre.java
package vehicleapp;
public class Tyre{

private Vehicle vehicle;
private int rimDiameter;
private int width;
private int aspectRatio;
private char speedRating;
public Tyre(int rimDiameter, int width, int
aspectRatio, char speedRating){
this.rimDiameter=rimDiameter;
this.width=width;
this.aspectRatio=aspectRatio;
this.speedRating=speedRating;}

//accessor & mutator method
public int getRimDiameter(){
return rimDiameter;}

public void setRimDiameter(int rimDiameter){
this.rimDiameter = rimDiameter;}
public int getWidth(){
return width;}
public void setWidth(int width){
this.width = width;}
public int getAspectRatio(){
return aspectRatio;}
public void setAspectRatio(int aspectRatio){
this.aspectRatio = aspectRatio;}
public void setSpeedRating(char
speedRating){
this.speedRating =
speedRating;}

public int getSpeedRating(){

int rating=0;

switch(speedRating){
case 'R' ->
rating=170;
case 'S' ->
rating=180;
case 'T' ->
rating=190;
case 'U' ->
rating=200;
case 'H' ->
rating=210;
case 'V' ->
rating=240;
default -> {}
}

return rating;}
}
//VehicleApp.java
package vehicleapp;
public class VehicleApp{
public static void main(String[] args){

Tyre product1 = new Tyre(2, 3, 4,
'0');

//Array
Vehicle transport[] = new
Vehicle[3];

//Parent class reference to child
object
transport[0] = new Lorry("Hybrid",
"Lorry", "Manual", 5000);
transport[1] = new Car("Electric",
"Car", "Manual", "Proton", 3001);
transport[2] = new SuperCar("Hybrid",
"SUV", "Automatic", "Honda", 3000, 400);
product1.setSpeedRating('V');

//(1)upCasting Lorry
System.out.printf("1. %s %s with %s
transmission\n", transport[0].getPowertrain(),
transport[0].getType(), transport[0].getTransmission());
System.out.printf("Roadtax Price =
RM%.2f\n\n", transport[0].getRoadtaxPrice());
System.out.println("Current Speed
(Accelerate) = " +transport[0].accelerate() +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[0].brake()
+"km/h");

System.out.println("Current Speed
(Accelerate) = " +transport[0].autoAccelerate(1) +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[0].autoBrake(5)
+"km/h\n");

System.out.println("Tyre Speed Rating =
" +product1.getSpeedRating() +"km/h");

//(1)downCasting Lorry
Lorry lorry1 = (Lorry)
transport[0];
System.out.printf("Towing Capability =
%.2fkg\n", lorry1.getTowCap());

//(2)upCasting Car
System.out.printf("\n2. %s %s with %s
transmission\n", transport[1].getPowertrain(),
transport[1].getType(), transport[1].getTransmission());
System.out.printf("Roadtax Price =
RM%.2f\n\n", transport[1].getRoadtaxPrice());
System.out.println("Current Speed
(Accelerate) = " +transport[1].accelerate() +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[1].brake()
+"km/h");

System.out.println("Current Speed
(Accelerate) = " +transport[1].autoAccelerate(1) +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[1].autoBrake(16)
+"km/h\n");

System.out.println("Tyre Speed Rating =
" +product1.getSpeedRating() +"km/h");

//(2)downCasting Car
Car car1 = (Car) transport[1];
System.out.printf("%.0fcc
= %.1fL\n", car1.getCc(),
car1.getLiters());

//(3)upCasting SuperCar
System.out.printf("\n3. %s %s with %s
transmission\n", transport[2].getPowertrain(),
transport[2].getType(), transport[2].getTransmission());
System.out.printf("Roadtax Price =
RM%.2f\n\n", transport[2].getRoadtaxPrice());
System.out.println("Current Speed
(Accelerate) = " +transport[2].accelerate() +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[2].brake()
+"km/h");

System.out.println("Current Speed
(Accelerate) = " +transport[2].autoAccelerate(1) +"km/h");

System.out.println("Current Speed
(Brake) = " +transport[2].autoBrake(4)
+"km/h\n");

System.out.println("Tyre Speed Rating =
" +product1.getSpeedRating() +"km/h");

//(3)downCasting SuperCar
SuperCar car2 = (SuperCar)
transport[2];
System.out.printf("Maximum Speed
= %dkm/h\n\n", car2.getSpeedMax());
}
}
TASK - Update VehicleApp project: Write a Java code that follow class diagram relationship and apply overriding method for inherited class. Using an existing VehicleApp project, update the project with the following Class Diagram information. Inside a main() method create an object that can call the inheritance and composition (Car and Tyre class). You should be able to call an overriding method, getRoadtaxPrice() and show their value. Tyre Vehicle - rimDiameter: int - witdh: int - aspectRatio: int - SpeedRating: char + Tyre(rim Diameter: int, witdh: int, aspectRatio: int, speedRating: char) + getSpeedRating(): int 4 Car - model: String - cc: double + Car() + Car(model: String, cc: double, type: String, transmission: String, powertrain: String) + getLiters(): double + getRoadtaxPrice(): double Create an overriding method, getRoadtaxPrice() in Car class: This method will return total road tax value, based on the following information. Cubic Centimeters Based Rate Progressive Rate Total Road Tax (cc) (RM) (per cc) (RM) 1000 and below 20 20.00 1001 to 1200 55 55.00 2001 to 1400 70 70.00 1401 to 1600 90 90.00 1601 to 1800 200 RM0.40 200.40 to 280 1801 to 2000 280 RM0.50 280.50 to 380 2001 to 2500 380 RM1.00 381.00 to 880 2501 to 3000 880 RM2.50 882.50 to 2130.00 3001 and above 2130 RM4.50 2134.50 and above
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply