-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
123 lines (104 loc) · 4.01 KB
/
Student.java
File metadata and controls
123 lines (104 loc) · 4.01 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
import java.util.Scanner;
public class Student {
private String ID;
private static int idCounter = 0;
private String contactInformation;
private String[] enrolledCourses;
private int coursePrice = 600;
public String studentFirstName;
public String studentLastName;
public String gradeYear;
public Student() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter student first name: ");
this.studentFirstName = sc.nextLine();
System.out.print("Enter student last name: ");
this.studentLastName = sc.nextLine();
System.out.print("Enter grade year: Freshman Sophomore Junior Senior\n");
this.gradeYear = sc.nextLine();
System.out.print("Enter your phone number: (999)-999-");
this.contactInformation = sc.nextLine();
String id = this.generateID(studentFirstName, studentLastName, gradeYear);
System.out.println("Your student ID is: " + id);
enrollCourse();
}
private static String generateID(String studentFirstName, String studentLastName, String gradeYear) {
String firstNameAbbreviation = studentFirstName.substring(0, 1).toUpperCase();
String lastNameAbbreviation = studentLastName.substring(0, 1).toUpperCase();
String gradeLevel = gradeYear.substring(0, 1).toUpperCase();
int uniqueNumber = idCounterNumber();
return firstNameAbbreviation + lastNameAbbreviation + gradeLevel + uniqueNumber;
}
private static int idCounterNumber() {
int counter = idCounter;
idCounter++;
return counter;
}
public void enrollCourse() {
Enroll newEnroll = new Enroll();
this.enrolledCourses = newEnroll.enrollCourses();
}
class Enroll {
public String[] enrollCourses() {
Scanner sc = new Scanner(System.in);
System.out.println("\nWould you like to enroll into your courses: YES NO");
String enrollment = sc.nextLine();
if (enrollment.toLowerCase().equals("yes"))
{
System.out.print("Enter the number of courses you would like to enroll: ");
int numberOfCourses = sc.nextInt();
sc.nextLine();
String[] enrolledCourses = new String[numberOfCourses];
System.out.println("Enter the course you would like to enroll: PHYS180 BIO120");
for (int i = 0; i < numberOfCourses; i++)
{
enrolledCourses[i] = sc.nextLine();
}
System.out.println("\nYou've successfully enrolled in " + enrolledCourses.length + " courses.");
return enrolledCourses;
}
else
{
return new String[0];
}
}
}
public double calculateTuition(String[] enrolledCourses) {
if (enrolledCourses.length == 0)
{
System.out.print("You've yet enrolled in any courses yet...");
return 0.0;
}
else
{
return enrolledCourses.length * coursePrice;
}
}
public void checkStatus() {
if (enrolledCourses == null)
{
enrollCourse();
}
double tuition = calculateTuition(enrolledCourses);
if (tuition == 0.0)
{
if (studentFirstName == null || studentLastName == null)
{
Student stud = new Student();
stud.enrollCourse();
}
enrollCourse();
}
else
{
String id = generateID(studentFirstName, studentLastName, gradeYear);
System.out.println("\nYour id is: " + id);
System.out.println("Your tuition amount is: $" + tuition);
System.out.println("The courses you've enrolled in are: " );
for (int i = 0; i < enrolledCourses.length; i++)
{
System.out.println(enrolledCourses[i]);
}
}
}
}