code blow public class Aya { //instantiate variables private int ManufacturingYear; private double EngineCapacity; private String VehicleType; private double Fuel_Consumption; //create a class constructor public Aya(int my, double ec, String vt, double fc) { this.ManufacturingYear = my; this.EngineCapacity = ec; this.VehicleType = vt; this.Fuel_Consumption = fc; } //create a function to print all vehicle data public void printVehicleData() { System.out.println("Manufacturing Year: " + ManufacturingYear); System.out.println("Engine Capacity: " + EngineCapacity); System.out.println("Vehicle Type: " + VehicleType); System.out.println("Fuel Consumption: " + Fuel_Consumption); } //create a function to print the fuel economy public void printFuelEconomy() { if (Fuel_Consumption > 30) { System.out.println("Fuel Economy: Excellent"); } else if (Fuel_Consumption >= 20 && Fuel_Consumption <= 30) { System.out.println("Fuel Economy: Very Good"); } else if (Fuel_Consumption >= 10 && Fuel_Consumption < 20) { System.out.println("Fuel Economy: Good"); } else if (Fuel_Consumption < 10) { System.out.println("Fuel Economy: Average"); } } public static void main(String[] args) { //create an object from Aya class Aya a = new Aya(2022, 1.6, "Passenger Cars", 9); //call printVehicleData function a.printVehicleData(); //call printFuelEconomy function a.printFuelEconomy(); } } In the main class that contains the Main function, the following is done: 1- Create an object of the previous class or class, which represents a car. 2- Assigning different values to the properties of the previous object by entering the data using the input boxes (not setting them manually within the code). 3- Calling the two functions (printing vehicle data and printing fuel economy level) for the object
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
for code blow
public class Aya {
//instantiate variables
private int ManufacturingYear;
private double EngineCapacity;
private String VehicleType;
private double Fuel_Consumption;
//create a class constructor
public Aya(int my, double ec, String vt, double fc) {
this.ManufacturingYear = my;
this.EngineCapacity = ec;
this.VehicleType = vt;
this.Fuel_Consumption = fc;
}
//create a function to print all vehicle data
public void printVehicleData() {
System.out.println("Manufacturing Year: " + ManufacturingYear);
System.out.println("Engine Capacity: " + EngineCapacity);
System.out.println("Vehicle Type: " + VehicleType);
System.out.println("Fuel Consumption: " + Fuel_Consumption);
}
//create a function to print the fuel economy
public void printFuelEconomy() {
if (Fuel_Consumption > 30) {
System.out.println("Fuel Economy: Excellent");
} else if (Fuel_Consumption >= 20 && Fuel_Consumption <= 30) {
System.out.println("Fuel Economy: Very Good");
} else if (Fuel_Consumption >= 10 && Fuel_Consumption < 20) {
System.out.println("Fuel Economy: Good");
} else if (Fuel_Consumption < 10) {
System.out.println("Fuel Economy: Average");
}
}
public static void main(String[] args) {
//create an object from Aya class
Aya a = new Aya(2022, 1.6, "Passenger Cars", 9);
//call printVehicleData function
a.printVehicleData();
//call printFuelEconomy function
a.printFuelEconomy();
}
}
In the main class that contains the Main function, the following is done:
1- Create an object of the previous class or class, which represents a car.
2- Assigning different values to the properties of the previous object by entering the data using the input boxes (not setting them manually within the code).
3- Calling the two functions (printing vehicle data and printing fuel economy level) for the object.

Step by step
Solved in 2 steps with 1 images









