-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompSciStudent.java
More file actions
197 lines (162 loc) · 4.55 KB
/
CompSciStudent.java
File metadata and controls
197 lines (162 loc) · 4.55 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
import java.util.Scanner;
/**
This class holds data for a computer science student.
*/
public class CompSciStudent extends student
{
// Required hours
private final int MATH_HOURS = 20; // Math hours
private final int CS_HOURS = 40; // Comp sci hours
private final int GEN_ED_HOURS = 60; // Gen ed hours
private final int MAX_MATH_HOURS = 30;
private final int MAX_CS_HOURS = 50;
private final int MAX_GENed_HOURS = 80;
// Hours taken
private int mathHours; // Math hours taken
private int csHours; // Comp sci hours taken
private int genEdHours; // General ed hours taken
boolean math = true;
boolean cs = true;
boolean genED = true;
Scanner scan = new Scanner(System.in);
/**
The Constructor sets the student's name,
ID number, and the year admitted.
@param n The student's name.
@param id The student's ID number.
@param year The year the student was admitted.
*/
public CompSciStudent(String n, String id, int year)
{
super(n, id, year);
}
public void setMathHours()
{
while(math)
{
System.out.println("How many hours of math credits do you have?");
//this.mathHours = scan.nextInt();
try
{
mathHours = Integer.parseInt(scan.next());
math = false;
}
catch(NumberFormatException e)
{
System.out.println("Inncorect data type input!");
math = true;
}
if(mathHours < 0 || mathHours > MAX_MATH_HOURS)
{
System.out.println("Invalid range of hours. Input must be greater than 0 and less than 100!");
math = true;
}
}
}
public void setCSHours()
{
while(cs)
{
System.out.println("How many hours of computer science credits do you have?");
try
{
csHours = Integer.parseInt(scan.next());
cs = false;
}
catch(NumberFormatException e)
{
System.out.println("Inncorect data type input!");
cs = true;
}
if(csHours < 0 || csHours > MAX_CS_HOURS)
{
System.out.println("Invalid range of hours. Input must be greater than 0 and less than 100!");
cs = true;
}
}
}
public void setGenEDHours()
{
while(genED)
{
System.out.println("How many hours of general education credits do you have?");
try
{
genEdHours = Integer.parseInt(scan.next());
genED = false;
}
catch(NumberFormatException e)
{
System.out.println("Inncorect data type input!");
genED = true;
}
if(genEdHours < 0 || genEdHours > MAX_GENed_HOURS)
{
System.out.println("Invalid range of hours. Input must be greater than 0 and less than 100!");
genED = true;
}
}
}
/**
The setMathHours method sets the number of
math hours taken.
@param math The math hours taken.
*/
public int getMathHours()
{
return mathHours;
}
/**
The setCsHours method sets the number of
computer science hours taken.
@param cs The computer science hours taken.
*/
public int getCsHours()
{
return csHours;
}
/**
The setGenEdHours method sets the number of
general ed hours taken.
@param genEd The general ed hours taken.
*/
public int getGenEdHours()
{
return genEdHours;
}
/**
The getRemainingHours method returns the
the number of hours remaining to be taken.
@return The hours remaining for the student.
*/
@Override
public int getRemainingHours()
{
// I think I fixed this method by putting a maximum on each of the hour inputs so that all of the hours are not one subject \
// and then the program still says they have all of their hours.
int reqHours, // Total required hours
remainingHours; // Remaining hours
// Calculate the required hours.
reqHours = MATH_HOURS + CS_HOURS + GEN_ED_HOURS;
// Calculate the remaining hours.
remainingHours = reqHours - (mathHours + csHours
+ genEdHours);
return remainingHours;
}
/**
The toString method returns a string containing
the student's data.
@return A reference to a String.
*/
@Override
public String toString()
{
String str;
str = super.toString() +
"\nMajor: Computer Science" +
"\nMath Hours Taken: " + mathHours +
"\nComputer Science Hours Taken: " + csHours +
"\nGeneral Ed Hours Taken: " + genEdHours;
return str;
}
}