/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package iava.test3; /** * * @author Admin */ public class Vehicle3 { int ModelYear; public Vehicle3(){ ModelYear = 0; } public Vehicle3(int ModelYear){ this.ModelYear = ModelYear; } public void setModelYear(int ModelYear){ this.ModelYear = ModelYear; } public int getModelYear(){ return ModelYear; } public String toString(){ return "Model Year " + this.ModelYear; } }
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package iava.test3; /** * * @author Admin */ public class Car3 extends Vehicle3 { private String Brand; private double Price; public Car3(String Brand, int ModelYear, double Price) { super(ModelYear); this.Brand = Brand; this.Price = Price; } public void setBrand(String Brand){ this.Brand = Brand; } public String getBrand(){ return Brand; } public void setPrice(double Price){ this.Price = Price; } public double getPrice(){ return Price; } public boolean isequal(Car3 c){ return this.Brand.equals(c.Brand) && this.ModelYear == c.getModelYear() && this.Price == c.Price; } @Override public String toString(){ return "Brand: " + this.Brand + " Model " + this.ModelYear + " Price " + this.Price; } }
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license */ package iava.test3; /** * * @author Admin */ public class Test3 { public static void main(String[] args) { Car3 ca1 = new Car3("Toyota", 2020, 8500); Car3 ca2 = new Car3("Toyota", 2020, 8500); System.out.println("The First Car is " + ca1 + " SAR" + "\n"); System.out.println("The Second Car is " + ca2 + " SAR" + "\n"); System.out.println("Are these cars Equal?" + ca1.equals(ca2)); } }