Preview:
/////////////////////////////////////////////////////////////////////////////////////////
//For CarApplication.java
//////////////////////////////////////////////////////////////////////////////////////////

public class CarApplication{
	public static void main(String[] args){
		
		//Create Car1 and Add values with constructor 
		Car car1 = new Car("CIVIC","2024", 7500000);
		
		//Create Car2 and Add values with constructor
		Car car2 = new Car("SWIFT","2019", 4500000);
		
		
		System.out.println("\nCar1\n");
		//Print car1 value before discount
		System.out.println("Model of Car1 = "+car1.getModel());
		System.out.println("Year of Car1 = "+car1.getYear());
		System.out.println("Price of Car1 = "+car1.getPrice()+"\n");
		
		
		car1.setDiscount(5);
		
		System.out.println("After 5% Discount");
		
		
		//Print car1 value after discount
		System.out.println("Price of Car1 = "+car1.getPrice()+"\n");
		
		
		System.out.println("Car2\n");
		
		
		//Print car1 value before discount
		System.out.println("Name of Car2 = "+car2.getModel());
		System.out.println("Year of Car2 = "+car2.getYear());
		System.out.println("Price of Car2 = "+car2.getPrice()+"\n");
		
		car2.setDiscount(7);
		
		System.out.println("After 5% Discount");
		
		//Print car1 value after discount
		System.out.println("Price of Car2 = "+car2.getPrice()+"\n");
		
		System.out.println("Numbers of Cars = "+Car.carno);
		
				
	}	
}

//////////////////////////////////////////////////////////////////////////////////////////
// FOr Car.java
//////////////////////////////////////////////////////////////////////////////////////////

public class Car{
	private String model;
	private String year;
	private double price;
	public static int carno=0;
	
	public Car(String model , String year, double price){
		setModel(model);
		setYear(year);
		setPrice(price);
		carno++;
	}
	
	public void setModel(String model){
		this.model = model;
	}
	
	public void setYear(String year){
		this.year = year;
	}
	
	public void setPrice(double price){
		if(price>0){
			this.price = price;
		}
	}
	
	public String getModel(){
		return this.model;
	}
	
	public String getYear(){
		return this.year;
	}
	
	public double getPrice(){
		return this.price;
	}
	
	public void setDis count(double discount){
		this.price =this.price - ((discount*this.price)/100);
	}
		
}

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter