l1 : hiding the code :
main :
car class :
sub class delorean :
factory class :
main :
Code:
package sellerBot;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
seller chi = new seller();
chi.selectCar();
}
}
car class :
Code:
package sellerBot;
public abstract class Car {
protected double price, oil;
String brand;
public abstract void specs();
@Override
public String toString() {
return "Car [price=" + price + ", oil=" + oil + ", brand=" + brand + "]";
}
}
sub class delorean :
Code:
package sellerBot;
public class Delorean extends Car{
private boolean flaxCapacitor;
double plutonium;
public Delorean() {
super.brand = this.getClass().toString();
super.oil = 5;
super.price = 50000;
this.flaxCapacitor = true;
this.plutonium = 20;
}
@Override
public void specs() {
// TODO Auto-generated method stub
System.out.println(this.toString());
}
@Override
public String toString() {
return super.toString() + " Delorean [flaxCapacitor=" + flaxCapacitor + ", plutonium=" + plutonium + "]";
}
}
factory class :
Code:
package sellerBot;
import java.util.Scanner;
public class seller {
private Car selected;
public void selectCar() {
Scanner s1 = new Scanner(System.in); // after typing this intelliJ should add the import code anyways
System.out.println("type car U want ");
String x = s1.next(); // .next(); to input a string
switch (x.toLowerCase()) {
case "delorean":
selected = new Delorean();
break;
default:
break;
}
System.out.println(selected.toString());
}
}