-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh10_51_OnlineShowroom.java
More file actions
95 lines (76 loc) · 2.05 KB
/
Ch10_51_OnlineShowroom.java
File metadata and controls
95 lines (76 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.Scanner;
public class Ch10_51_OnlineShowroom {
static class Showroom{
String [] Cars;
int serialNo;
String [] newCarlist;
Showroom(){
this.Cars = new String[100];
this.newCarlist = new String [Cars.length - 1];
// Two existing Cars
this.Cars[0] = "Ford Mustang GT";
this.Cars[1] = "Ford Figo Titanium";
this.serialNo = 2;
}
public void availableCars(){
int no = 1;
System.out.println("\nAvailable Cars now are: ");
for (String element : Cars){
if(element == null){
break;
}
System.out.printf("%d. %s\n" , no , element);
no++;
}
}
public void addCars(String car){
Cars[serialNo] = car;
System.out.printf("~ %s added to Showroom\n" , car);
serialNo++;
}
public void removeCars(String rCar){
for (int i = 0 , k=0; i<= Cars.length-1; i++){
if(rCar != Cars[i]){
this.newCarlist[k] = Cars[i];
k++;
}
}
System.out.println("~ As requested removing " + rCar + " from Database");
}
public void showremovedCars(){
int b=1;
System.out.println();
System.out.println("Available Cars now are:");
for (String a : newCarlist){
if(a == null){
break;
}
System.out.println(b + ". " + a);
b++;
}
}
}
public static void main(String[] args) {
Showroom obj = new Showroom();
Scanner input = new Scanner(System.in);
System.out.print("Enter your name: "); String name = input.nextLine();
// Adding cars workfield
System.out.println("Welcome: " + name);
System.out.println("\nHere's Your Recent Action Summary:");
obj.addCars("Suzuki Brezza");
obj.addCars("Hyundai Creta");
obj.addCars("Suzuki Alto");
obj.addCars("Kia Seltos");
obj.addCars("Volkwagen Polo");
obj.addCars("Skoda Octavia");
// Summary of Available Cars after adding
obj.availableCars();
System.out.println();
System.out.println("********");
System.out.println();
// Removing Cars workfield
obj.removeCars("Skoda Octavia");
// List of Available cars after removing some of them
obj.showremovedCars();
}
}