0% found this document useful (0 votes)
29 views2 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy