Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Java Lab

The document contains code for a MotorVehicle class with model attributes and a display method, and a Car class that extends MotorVehicle with a discount rate attribute. The main method creates a Car object, calls its display and discount methods to output the model details and calculate the discounted price.

Uploaded by

biswa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Java Lab

The document contains code for a MotorVehicle class with model attributes and a display method, and a Car class that extends MotorVehicle with a discount rate attribute. The main method creates a Car object, calls its display and discount methods to output the model details and calculate the discounted price.

Uploaded by

biswa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Lab

Biswajit Dutta
DC2018BCA0004

#Code

class MotorVehicle {
String modelName;
int modelNumber;
float modelPrice;

MotorVehicle(String mname, int mnumber, float mprice) {


modelName = mname;
modelNumber = mnumber;
modelPrice = mprice;
}

void display() {
System.out.println("Model name is: " + modelName);
System.out.println("Model number is: " + modelNumber);
System.out.println("Model price is: " + modelPrice);
}
}

public class Car extends MotorVehicle {


int discountRate;
Car(String mname, int mnumber, float mprice, int dr) {
super(mname,mnumber,mprice);
discountRate = dr;
}

void display() {
super.display();
System.out.println("The discount rate is : " + discountRate);
}

void discount() {
float discount = modelPrice*discountRate/100;
float priceafterdiscount = modelPrice-discount;
System.out.println("The discount is : " + discount);
System.out.println("The price after discount rate : " + priceafterdiscount);
}
public static void main(String args[]) {

Car c = new Car("Hyundai", 6000, 4200000f, 15);

c.display();
c.discount();
}
}

#Output

You might also like