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

Question 1 Design a class named Car that contains . 6 data fields: make (String)

ID: 3588967 • Letter: Q

Question

Question 1 Design a class named Car that contains . 6 data fields: make (String), model (String. colour(Strig.I· Question 2 Write a test program that Sets themarSpeed for crs to 22 in/h Creates a Car object with the default properties (L.e blu Creates a second Car object for a black Audi A3 with an Drives the Hyundai :30for 20km Refuels the Hyundai 130 fuel (double), odometer (int) and maxSpeed (int) Assume that all cars have the same maxSpeed (hint: make this a static variable) Hyundai 30 with 40 of fu A no-arg constructor that creates a blue Hyundai 130 with odometer value of 100km 40L of fuel. A constructor that creates a car with 55L of fuel and theDrives the Audi A3 for 175km specified make, model, colour and odometer value The getter and setter methods for make, model, colour, fuel, odometer and maxSpeed A method named refuel() that sets the fuel to 50L A method named drive) that increments the odometer by the specified distance and decrements the fuel at a rate of Prints the make, model,colour,fuel, odometer-and maxSpeed for the car with the greatest amount of fuel remaining · model, colou, fuel, odometer value and . Prints the make maxSpeed for the car with the least amount of fuel remainin .51/100km.

Explanation / Answer

Answer 1:

class Car {
   string make;
   string model;
   string color;
   double fuel;
   int odoMeter;
   int maxSpeed;

   Car() {
       make = "Hyundai";
       model = "i30";
       color = "blue";
       fuel = 40;
       odoMeter = 0;
       maxSpeed = 130;
   }

   Car(string make, string model, string color, string odometer) {
       this->make = make;
       this->model = model;
       this->color = color;
       this->fuel = 55;
       this->odoMeter = odometer;
       this->maxSpeed = 130;
   }

   void refuel() {
       fuel = 50;
   }

   void drive(int distance) {
       odoMeter += distance;
       fuel -= distance /100 * 7.5;
   }

   string getMake() {
       return make;
   }

   string getModel() {
       return model;
   }

   string getColor() {
       return color;
   }

   double getFuel() {
       return fuel;
   }

   int getOdoMeter() {
       return odoMeter;
   }

   int getMaxSpeed() {
       return maxSpeed;
   }
  
   void setMake(string make) {
       this->make = make;
   }

   void setModel(string model) {
       this->model = model;
   }

   void setColor(string color) {
       this->color = color;
   }

   void setFuel(double fuel) {
       this->fuel = fuel;
   }

   void setOdoMeter(int odoMeter) {
       this->odoMeter = odometer;
   }

   void setMaxSpeed(int maxSpeed) {
       this->maxSpeed = maxSpeed;
   }
};

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