-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMini1.java
executable file
·82 lines (70 loc) · 1.83 KB
/
Mini1.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
import java.util.Scanner;
/**
* The main class for CS2030S Lab 01 Mini 1.
*
* @author dcsaysp
* @version CS2030 AY24/25 S1
*/
class Mini1 {
/**
* The list of companies.
*/
private Company[] companies;
/**
* The number of companies.
*/
private int numCompanies;
/**
* The number of year.
*/
private int numYears;
/**
* Different types of companies.
*/
public static final int MNC = 1;
public static final int STARTUP = 2;
public static final int SME = 3;
public static void main(String[] args) {
// Create a scanner to read from standard input.
Scanner sc = new Scanner(System.in);
Mini1 runner = new Mini1(sc);
runner.run();
}
public Mini1(Scanner sc) {
// Number of companies
this.numCompanies = sc.nextInt();
// Number of years
this.numYears = sc.nextInt();
// Initialize companies
this.companies = new Company[this.numCompanies];
// Read the data for each company from stdin
for (int i = 0; i < this.numCompanies; i++) {
int type = sc.nextInt();
if (type == Mini1.MNC) {
this.companies[i] = new MNC(sc.next(), sc.nextInt());
} else if (type == Mini1.STARTUP) {
this.companies[i] = new Startup(sc.next(), sc.nextInt(), sc.nextInt());
} else if (type == Mini1.SME) {
this.companies[i] = new SME(sc.next(), sc.nextInt(), sc.nextInt());
}
}
// Close the scanner
sc.close();
}
public void run() {
/**
* TODO: Refactor this poorly written for loop
*/
for (int i = 0; i < this.numYears; i++) {
for (int j = 0; j < this.numCompanies; j++) {
this.companies[j].oneYear();
}
}
/**
* TODO: Refactor this poorly written for loop
*/
for (int j = 0; j < this.numCompanies; j++) {
System.out.println(this.companies[j]);
}
}
}