-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCarSystem_BB.java
More file actions
93 lines (84 loc) · 2.97 KB
/
CarSystem_BB.java
File metadata and controls
93 lines (84 loc) · 2.97 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
import java.util.*;
class car_system
{
Scanner sc = new Scanner(System.in);
car_system[] arr = new car_system[100];
int currentindex=0;
int noofcars;
String RegistrationNo;
String Model;
double Mileage;
double fuelcapacity;
void AddCars()
{
System.out.print("Enter number of cars you want to add");
noofcars = sc.nextInt();
for(int i=currentindex ;i<currentindex + noofcars;i++)
{
arr[i] = new car_system();
System.out.println("--------------------------------");
System.out.println("Enter Details for Car no " + i);
System.out.print("Enter Registration no for car: " + i);
arr[i].RegistrationNo = sc.next();
System.out.print("Enter Model no for car: " + i);
arr[i].Model = sc.next();
System.out.print("Enter Mileage for car: " + i);
arr[i].Mileage = sc.nextDouble();
System.out.print("Enter Fuel Capacity for car: " + i);
arr[i].fuelcapacity = sc.nextDouble();
System.out.println("---------------------------------");
}
currentindex = noofcars + currentindex;
}
void distanceinfulltank(String RegNo)
{
for(int i =0;i<currentindex;i++)
{
if(arr[i].RegistrationNo.equals(RegNo)) {
System.out.println("Car Found in Database");
System.out.println("This Car can run upto " + arr[i].Mileage * arr[i].fuelcapacity + "Kms");
}
}
}
void carwithhighmileage(double Milg)
{
for(int i =0;i<currentindex;i++)
{
if(arr[i].Mileage > Milg) {
System.out.println("Car no " + i + "have Mileage" + arr[i].Mileage);
}
}
}
public static void main(String args[])
{
//your code goes here
Scanner sc = new Scanner(System.in);
car_system obj = new car_system();
while(true)
{
System.out.println(" Select Your Purpose from Below :");
System.out.print("1] Add cars \n" +
"2] check distance can be cover in full tank for any car\n"+
"3] Cars with high Mileage \n" +
"4] Exit" );
int choice = sc.nextInt();
if(choice==1){
obj.AddCars();
}
if(choice==2){
System.out.print("Enter Registration no of car: ");
String regno = sc.next();
obj.distanceinfulltank(regno);
}
if(choice==3){
System.out.print("Enter your Expected Mileage: ");
double milgg = sc.nextDouble();
obj.carwithhighmileage(milgg);
}
if(choice==4){
break;
}
}
System.out.print("----------Program Ended----------");
}
}