-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoM_Application.java
More file actions
203 lines (180 loc) Β· 6.05 KB
/
DoM_Application.java
File metadata and controls
203 lines (180 loc) Β· 6.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
ID : U1910060
Name : Abdullokh Alimov
Section: (MSC2070-002)
*/
import java.util.Scanner;
import java.util.function.ObjDoubleConsumer;
// --- Main Class ---
public class DoM_Application
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); //Object for Scanner
// Objects
CityTemperature T = new CityTemperature();
CityRainFall R = new CityRainFall();
int menu;
boolean option = true;
// Menu part
while(option){
System.out.println("--- Menu ---");
System.out.println("1. Set city wise hourly (00:00 to 23:00 ) temperature information.");
System.out.println("2. Get city wise hourly (00:00 to 23:00 ) temperature information.");
System.out.println("3. Set city wise yearly (from January to December) rainfall information.");
System.out.println("4. Get city wise yearly (from January to December) rainfall information.");
System.out.println("5. Set yearly climate data (from January to December) for city.");
System.out.println("6. Get yearly climate data (from January to December) for city.");
System.out.println("7. Exit");
System.out.println(" Your Choice: ");
menu = input.nextInt();
switch(menu){
case 1:{ // Set Data Temperature
T.setClimateData();
}
break;
case 2:{ //Get Data Temperature
T.getClimateData();
}
break;
case 3:{ //Set Data RainFall
R.setClimateData();
}
break;
case 4:{ //Get Data RainFall
R.getClimateData();
}
break;
case 5:{ //Set Data Year Temperature
T.setClimateDataYear();
}
break;
case 6:{ //Get Data Year Temperature
T.getClimateDataYear();
}
break;
case 7:{ // Exit
option = false;
}
break;
}
}
}
}
// --- Superclass ---
class City
{
// --- Data Fields ---
private int cityID;
private String cityName;
// --- Methods ---
public void setCityID(int cityID)
{
this.cityID = cityID;
}
public int getCityID()
{
return cityID;
}
public void setCityName(String cityName)
{
this.cityName = cityName;
}
public String getCityName()
{
return cityName;
}
}
// --- 1st Sub class for Temperature ---
class CityTemperature extends City
{
Scanner input = new Scanner(System.in); //Object for Scanner
// --- Data Fields ---
private double[] cityClimateData = new double[24];
double temperature;
String cityName;
int cityID;
// --- Methods ---
public void setClimateData()
{
System.out.print("Enter ID :"); cityID = input.nextInt();
System.out.print("Enter Name:"); cityName = input.next();
super.setCityID(cityID);
super.setCityName(cityName);
System.out.println(" Enter Data for Temperature from 00:00 to 24:00");
for (int i = 0; i < 24; i++)
{
System.out.print(i + ":00 "); cityClimateData[i] = input.nextDouble();
}
}
public void getClimateData()
{
System.out.println(super.getCityID()+ " " + super.getCityName()+" Date of Temperature:");
for (int i = 0; i < 24; i++){
System.out.println(i + ":00 " + cityClimateData[i] + "(C)");
temperature = temperature + cityClimateData[i];
}
temperature = (double) temperature / 24;
System.out.println("Average "+temperature+" C'");
}
// Yearly
public void setClimateDataYear()
{
System.out.print("Enter ID :"); cityID = input.nextInt();
System.out.print("Enter Name:"); cityName = input.next();
super.setCityID(cityID);
super.setCityName(cityName);
System.out.println(" Enter Data for Temperature from January to December");
for (int i = 1; i <= 12; i++)
{
System.out.print(i + ". "); cityClimateData[i] = input.nextDouble();
}
}
public void getClimateDataYear()
{
System.out.println(super.getCityID()+ " " + super.getCityName()+" Date of Temperature:");
for (int i = 1; i <= 12; i++){
System.out.println(i + ". " + cityClimateData[i] + "(C)");
temperature = temperature + cityClimateData[i];
}
temperature = (double) temperature / 12;
System.out.println("Average "+temperature+" C'");
}
}
// --- 2nd Sub class for Rainfall ---
class CityRainFall extends City
{
Scanner input = new Scanner(System.in); //Object for Scanner
// --- Data Fields ---
private double[] cityClimateData = new double[12];
double rainfall;
String cityName;
int cityID;
// --- Methods ---
public void setClimateData()
{
System.out.print("Enter ID :"); cityID = input.nextInt();
System.out.print("Enter Name:"); cityName = input.next();
super.setCityID(cityID);
super.setCityName(cityName);
System.out.println(" Enter Data for RainFall from January (1) to December (12) ");
int Order = 1;
for (int i = 0; i < 12; i++)
{
System.out.print(Order + ". "); cityClimateData[i] = input.nextDouble();
Order++;
}
}
public void getClimateData()
{
System.out.println(super.getCityID()+ " " + super.getCityName()+" Date of RainFall:");
int Order = 1;
for (int i = 0; i < 12; i++){
System.out.println(Order + ". " + cityClimateData[i] + " (mm)");
rainfall = rainfall + cityClimateData[i];
Order++;
}
rainfall = (double) rainfall / 12;
System.out.println("Average RainFall "+rainfall+" (mm)");
}
}