Can You do a java code for Staff class and registration
Class
Staff class have two methods 1/ To Check case checkCase() to
check if the car is registered our not 2/ To mange owner
registration Class have two methods 1/ To make registration 2/
modify registration
This codes is for Vehicle , Car , Owner and the main class
public class Vehicle {
private String manufacturer;
private Owner owner;
public Vehicle(String manufacturer,Owner owner){
this.manufacturer =manufacturer;
this.owner=owner;
}
public String getManufacturer() {
return manufacturer;
}
public Owner getOwner() {
return owner;
}
public void display(){
System.out.println("Manufacturer: "+this.manufacturer);
this.owner.display();
}
}
------------------------------------------------------------------------------------
public class Car extends Vehicle {
private String model;
public String RegNumber;
private String carNoP;
private boolean registered = false;
private double price;
private ArrayList cars;
private int quantity;
public Car(String RegNumber, String manufacturer, Owner owner)
{
super(manufacturer, owner);
this.RegNumber = RegNumber;
}
public Car(String manufacturer, Owner owner, String model,
String RegNumber, String carNoP, double price) {
super(manufacturer, owner);
this.model = model;
this.RegNumber = RegNumber;
this.carNoP = carNoP;
this.price = price;
}
public Car(double price, String manufacturer, Owner owner)
{
super(manufacturer, owner);
this.price = price;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getRegNumber() {
return RegNumber;
}
public void setRegNumber(String RegNumber) {
this.RegNumber = RegNumber;
}
public boolean isRegistered() {
return registered;
}
public void setRegistered(boolean registered) {
this.registered = registered;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public void registerCar(String regNo) {
if (registered = false) {
RegNumber = regNo;
registered = true;
} else {
System.out.println("Registered");
}
}
public void display() {
super.display();
System.out.println("Model : " + model);
System.out.println("Car Plate Number: " + carNoP);
System.out.println("Registration Number: " + RegNumber);
}
}
-----------------------------------------------------------------------------------------------
public class Owner {
private String name;
private String id;
private String phone;
private ArrayList cars;
public Owner(String name,String id,String phone){
this.name=name;
this.id=id;
this.phone = phone;
cars = new ArrayList<>();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList getCarList(){
return cars;
}
public void setCarList(ArrayList c){
this.cars = c;
}
public void buyCar(ArrayList carList){
Scanner in = new Scanner(System.in);
System.out.println("Buying a Car: ");
System.out.println("Model:");
String model = in.nextLine();
System.out.println("Quantity:");
int quantity = Integer.parseInt(in.nextLine());
double total = 0;
int c = 0;
for (Car car: carList) {
if (car.getModel().equals(model)) {
System.out.println("Bill:");
System.out.println("Price: " + car.getPrice());
System.out.println("Quantity: " + quantity);
double p = car.getPrice() * quantity;
total += p;
System.out.println("Total: " + p);
break;
}
}
}
public void makeRegistration(Car c){
String RegNO = c.getRegNumber();
if (c.isRegistered() == false){
c.RegNumber = RegNO;
c.setRegistered(true);
}
else{
System.out.println(" Already Registered");
}
}
public void display(){
System.out.println("Owner Name: "+this.name);
System.out.println("Owner ID: "+this.id);
System.out.println("Owner phone: "+this.phone);
}
}
----------------------------------------------------------------------------------
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Insert Owner's name :
");
String ownername = sc.next();
System.out.print("Insert Owner's id :
");
String ownerid = sc.next();
System.out.print("Insert Owner's Phone
: ");
String ownerPhone = sc.next();
System.out.print("Enter car
manufacturer name : ");
String mname = sc.next();
System.out.print("Enter car model :
");
String carmodel = sc.next();
System.out.print("Enter car Plate
number : ");
String carNo = sc.next();
System.out.print("Enter car
registration number : ");
String regnumber = sc.next();
System.out.print("Enter car price :
");
double price =
Double.parseDouble(sc.next());
Owner newowner = new Owner(ownername,
ownerid,ownerPhone);
Car newcar = new Car(mname, new
Owner(ownername, ownerid, ownerPhone), carmodel, regnumber, carNo,
price);
newowner.getCarList().add(newcar);
newcar.display();
newowner.makeRegistration(newcar);
newcar.registerCar(regnumber);
newowner.buyCar(newowner.getCarList());
}
}
Can You do a java code for Staff class and registration Class Staff class have two methods 1/ To Check case checkCase()
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Can You do a java code for Staff class and registration Class Staff class have two methods 1/ To Check case checkCase()
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!