-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface.java
349 lines (273 loc) · 10.5 KB
/
Interface.java
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
Template for assignment 1 SENG6110
Name: Neha
Student number: c3396115
Course: SENG6110
Assignment: 1
Date: 24/3/2022
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Pattern;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.FileWriter; // Import the FileWriter class
import java.io.IOException;
//import com.opencsv.CSVWriter;
public class Interface
{
/* Declare the Dwarf Planet variables here, as attributes of the Interface class, so that
you have access to these variables in every method below.
You should not instantiate the Dwarf Planet objects here (by using the 'new' keyword) as doing so is part of question 1 and is done
in method option01().
*/
// DwarfPlanet ceres;
// ... add more here
static Scanner console = new Scanner(System.in);
int inputNum = 0;
//private DwarfPlanet ceres,orcus,pluto,haumea,quaoar,makemak,gonggong,eris,sedna;
private int MAX_Region=5;
private int MAX_Planet=5;
private int numberOfRegions,numberofplanets,region_num;
private String region_name;
private Region c;
Region[] Kuiper=new Region[MAX_Region];
Region m= new Region();
DwarfPlanet d= new DwarfPlanet();
private int count=0;
private double smallplanet=0;
public void run() {
// Display a menu and read input values until -1 entered:
while(inputNum != -1) {
System.out.println("Select an option and press ENTER:");
System.out.println("1. Option 1:Add a Region");
System.out.println("2. Option 2:Add a dwarf planet to one of the region objects");
System.out.println("3. Option 3:Delete a Region");
System.out.println("4. Option 4:Delete a Dwarf Planet");
System.out.println("5. Option 5:List all the objects");
System.out.println("6. Option 6:List all the dwarf planets that belong to one region");
System.out.println("7. Option 7:List dwarf planets with mass greater than 4 Trillion");
System.out.println("8. Option 8: List the dwarf planet with smallest daimeter in each region ");
System.out.println("9. Option 9:Import Region and Dwarf Planet information from File ");
System.out.println("10. Option 10:Write the Region and Dwarf Planet information to File ");
//System.out.println("10. Option 10:GUI");// ... Add more options as needed. You will also have to add the corresponding methods below.
System.out.println("-1. Exit");
inputNum = console.nextInt();
switch(inputNum) {
case 1: option01(); break;
case 2: option02(); break;
case 3: option03(); break;
case 4: option04(); break;
case 5: option05(); break;
case 6: option06(); break;
case 7: option07(); break;
case 8: option08(); break;
case 9: option09(); break;
case 10: option10(); break;
case -1: System.exit(0); break;
} // end of switch(inputNum)
} // end of while(inputNum != -1)
} // end of run() method
// code for option 1
public void option01() {
System.out.println("You selected option 1 \n");
System.out.println("Creating the new Region");
String name;
Double width , population;
System.out.println("Enter the number of Regions you want to create");
numberOfRegions= console.nextInt();
for(int i=0;i<numberOfRegions;i++)
{ Kuiper[i]=new Region();
System.out.println("Enter the name of Region");
name=console.next();
//Kuiper1.setRegionName(name);
Kuiper[i].setRegionName(name);
//Kuiper[i].getRegionName();
System.out.println("Enter the width of Region");
width=console.nextDouble();
Kuiper[i].setRegionWidthAU(width);
System.out.println("Enter the Population Of Objects in Region");
population=console.nextDouble();
Kuiper[i].setPopulationOfObjects(population);
}
System.out.println("Region Created");
}
// code for option 2
public void option02() {
count=0;
System.out.println("You selected option 2 \n");
System.out.println("Enter the region name in Which you want to add Planet");
region_name=console.next();
for(int i=0;i<numberOfRegions;i++)
{if(Kuiper[i].getRegionName().equals(region_name))
{
Kuiper[i].addDwarfPlanet(region_name);
count++;}}
if(count==0){
System.out.println("Error: Region does not exist");
}}
// code for option 3
public void option03() {
count=0;
System.out.println("You selected option 3 \n");
System.out.println("Enter the region name Which you want to Delete");
region_name=console.next();
for(int i=0;i<numberOfRegions;i++)
{if(Kuiper[i].getRegionName().equals(region_name))
{
Kuiper[i]=Kuiper[i+1];
Kuiper[i+1]=null;
System.out.println("Region Deleted");
count++;
numberOfRegions--;}}
if(count==0){
System.out.println("Error:Region does not exist");}}
//Code for option 4
public void option04() {
count=0;
System.out.println("You selected option 4 \n");
System.out.println("Enter the region name in Which you want to delete the dwarf planet");
region_name=console.next();
for(int i=0;i<numberOfRegions;i++)
{if(Kuiper[i].getRegionName().equals(region_name))
{ Kuiper[i].deleteDwarfPlanet();
count++;
System.out.println("Planets Deleted");
break;}}
if(count==0){
System.out.println("Error:Region does not exist");}
}
public void option05() {
count=0;
System.out.println("You selected option 5 \n");
System.out.println("List all the data");
for(int i=0;i<numberOfRegions;i++)
{ Kuiper[i].displayRegion();
Kuiper[i].displayDwarfPlanet();
count++;
}
if(count==0)
{ System.out.println("Error:Region does not exist");}
}
public void option06() {
count=0;
System.out.println("You selected option 6 \n");
System.out.println("Enter the region name for Which you want to display planets");
region_name=console.next();
for(int i=0;i<numberOfRegions;i++)
{if(Kuiper[i].getRegionName().equals(region_name))
{
Kuiper[i].displayDwarfPlanet();
count++;
}}
if(count==0){
System.out.println("Region does not exist");
}}
public void option07() {
count=0;
System.out.println("You selected option 7 \n");
System.out.println("Listing the planets with mass greater than 4 trillion");
for(int i=0;i<numberOfRegions;i++)
{ if(Kuiper[i].getMassNumber()==0)
{ System.out.println("No planets with greater mass exist in Region"+ i);
break;}
for(int j=0;j<Kuiper[i].getMassNumber();j++)
{
System.out.println("Planet with greater mass in trillions"+ " "+ Kuiper[i].greatMass[j]+ " ");}
}}
public void option08() {
System.out.println("You selected option 8 \n");
System.out.println("Listing the planet with smallest Daimeter");
for(int i=0;i<numberOfRegions;i++)
{
System.out.println("The planet with smallest daimeter"+ Kuiper[i].smallDaimeter);
}}
public void option09()
{
System.out.println("Listing the data from the database");
String COMMA_DELIMITER = ",";
Scanner scanner = null;
try {
//Get the scanner instance
System.out.println("Displaying the data directly from file");
scanner = new Scanner(new File("C:/Users/Aradhya Arora/Downloads/input_data.csv"));
//Use Delimiter as COMMA
scanner.useDelimiter(COMMA_DELIMITER);
while(scanner.hasNext())
{
System.out.print(scanner.next()+" ");
}
}
catch (FileNotFoundException fe)
{
fe.printStackTrace();
}
finally
{
scanner.close();
}
}
public void option10()
{ FileWriter writer = null;
try {
writer = new FileWriter("output_file.csv");
writer.append("OBJECTTYPE");
writer.append(',');
writer.append("REGION");
writer.append(',');
writer.append("DAIMETER");
writer.append(',');
writer.append("MASS");
writer.append(',');
writer.append("MOONS");
writer.append('\n');
writer.append("DwarfPlanet");
writer.append(',');
writer.append("Kuiper");
writer.append(',');
writer.append("4");
writer.append(',');
writer.append("5");
writer.append(',');
writer.append("6");
writer.append('\n');
writer.append("DwarfPlanet");
writer.append(',');
writer.append("oort");
writer.append(',');
writer.append("4");
writer.append(',');
writer.append("7");
writer.append(',');
writer.append("6");
writer.append('\n');
writer.append("DwarfPlanet");
writer.append(',');
writer.append("Kuiper");
writer.append(',');
writer.append("3");
writer.append(',');
writer.append("5");
writer.append(',');
writer.append("2");
writer.append('\n');
System.out.println("CSV file is created...");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String args[])
{
Interface intFace = new Interface();
intFace.run();
}
}