In: Computer Science
import java.util.Scanner;
class Car{
private String make;
private String model;
private int year;
public Car(String make,String model,int year){
this.make=make;
this.model=model;
this.year=year;
}
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public int getYear(){
return Year;
}
public void setMake(String make){
this.make=make;
}
public void setModel(String model){
this.model=model;
}
public void setYear(int year){
this.year=year;
}
public String toString(){
return "Make: "+make+" | Model: "+model+" | Year: "+year;
}
}
class CarDealership{
private Car carOne;
private Car carTwo;
private Car carThree;
int amount=0;
public CarDealership(Car carOne,Car carTwo,Car carThree){
this.carOne=carOne;
this.carTwo=carTwo;
this.carThree=carThree;
}
public void performMaintenance(Scanner scan){
System.out.println("Welcome to the Maintenance Menu!")
System.out.println("Please select the service you wish to record:");
System.out.println("1. Oil Change ($50)\n2. Tire Rotation ($30)");
System.out.println("3. Detailing ($100)\n4. Tune-up ($200)");
int i=sc.nextInt();
int j=0;
while(j==0){
System.out.println("Your selection has been recorded!");
System.out.println("Did you sell another service?");
System.out.println("1. Yes\n2. No");
String s=sc.nextLine();
if(s.equalsIgnoreCase("No")){
System.out.println("Thank you! Now returning to the Main Menu...")
break;
}
}
}
public void sellCar(Scanner scan){
System.out.println("Welcome to the Sales Menu!");
int k=0;
int j=0;
int count++;
while(j==0){
System.out.println("Current Inventory is Listed Below:");
String str[]=new String[3];
str[0]=null;
str[1]=null; str[2]=null;
if(k!=1){str[0]=carOne.toString();}
else if(k!=2){str[1]=carTwo.toString();}
else if(k!=3){str[2]=carThree.toString();}
for(int i=0;i<3;i++){
if(!(str[i].equals(null))){
System.out.println(str[i]);}
}
System.out.println("Did you sell a vehicle");
System.out.println("1. Yes\n2. No");
String s=sc.nextLine();
if(s.equalsIgnoreCase("Yes")){
if(count==3){
System.out.println("No vehicles currently available.Thank you! Now returning to the Main Menu...")
}
else{
System.out.println("Which vehicle was sold? Please enter the Make, Model, and Year separated by commas.");
String sold=sc.nextLine();
String arr[]=sold.split(",");
System.out.println("The vehicle list has been updated!");
amount+=15000;
if(carOne.getMake().equals(arr[0])&&carOne.getModel().equals(arr[1])&&Integer.parseInt(carOne.getYear()).equals(arr[2]){
k=1;
count++;
}
else if(carTwo.getMake().equals(arr[0])&&carTwo.getModel().equals(arr[1])&&Integer.parseInt(carTwo.getYear()).equals(arr[2]){
k=2;
count++;
}
else if(carThree.getMake().equals(arr[0])&&carThree.getModel().equals(arr[1])&&Integer.parseInt(carThree.getMake()).equals(arr[2]){
k=3;
count++;
}
else{
k=0;
}
}
}
else if(s.equalsIgnoreCase("No")){
System.out.println("Thank you! Now returning to the Main Menu...")
break;
}
}
public void buyCar(Scanner scan){
System.out.println("Current Inventory is Listed Below:");
int k=0;
int j=0;
while(j==0){
System.out.println("Current Inventory is Listed Below:");
String str[]=new String[3];
str[0]=null;
str[1]=null; str[2]=null;
if(k!=1){str[0]=carOne.toString();}
else if(k!=2){str[1]=carTwo.toString();}
else if(k!=3){str[2]=carThree.toString();}
for(int i=0;i<3;i++){
if(!(str[i].equals(null))){
System.out.println(str[i]);}
}
System.out.println("Did you purchase a vehicle");
System.out.println("1. Yes\n2. No");
String s=sc.nextLine();
if(s.equalsIgnoreCase("Yes")){
amount-=10000;
System.out.println("Please enter the vehicle Details!");
System.out.println("Make: ");
String Make=sc.nextLine();
System.out.println("Model: ");
String Model=sc.nextLine();
System.out.println("Year: ");
String Year=sc.nextInt();
int count=0;
if(count==0){
carOne.setMake(Make);
carOne.setModel(Model);
carOne.setYear(Year);
k=1;
count++;
}
else if(count==1){
carTwo.setMake(Make);
carTwo.setModel(Model);
carTwo.setYear(Year);
k=2;
count++;
}
else if(count==2){
carThree.setMake(Make);
carThree.setModel(Model);
carThree.setYear(Year);
k=3;
count++;
}
}
else if(s.equalsIgnoreCase("No")){
System.out.println("Thank you! Now returning to the Main Menu...");
break;
}
}
public void printInventory(){
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to Main Menu!\nThe Daily Transactions value is currently: "+amount);
System.out.println("Please select an Option:");
System.out.println("1. Perform Maintenance\n2. Sell Car\n3. Buy Car\n4. Print Inventory\n5. Quit");
int ch=sc.nextInt();
switch(ch){
case 1: performMaintenance();break;
case 2: sellCar();break;
case 3: buyCar();break;
case 4: printInventory();break;
case 5: System.out.println("Thank you for using the Car Dealership program!");
break;
}
}
}
Thank you!, if you have any queries post it below in the comment section i will try my best to resolve your queries and i will add it to my answer if required. Please give upvote if you like.