-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
102 lines (71 loc) · 2.71 KB
/
Student.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
package StudentDatabaseApplication;
import java.util.Scanner;
public class Student {
private String firstName;
private String lastName;
private String courses;
private String studentID;
private int gradeLevel;
private int tuitionBalance;
private static int costOfCourse = 600;
private static int id = 1000;
// Constructor: prompt user to enter student's name and year
// It will print out the name and the year of the student
public Student() {
Scanner in = new Scanner(System.in);
System.out.print("Enter student first name: " );
this.firstName = in.nextLine();
System.out.print("Enter student last name: " );
this.lastName = in.nextLine();
System.out.print("1 - Freshmen\n2 - Sophmore\n3 - Junior\n4 - Senior\nEnter student grade level: " );
this.gradeLevel = in.nextInt();
setStudentID();
System.out.println(firstName + " " + lastName + " " + gradeLevel + " " + studentID);
}
// Generate an ID
private void setStudentID() {
// Grade Level + ID
id++;
this.studentID = gradeLevel + "" + id;
}
// Enroll in courses
public void enroll() {
// we want to get inside a loop, user hits Q to get out of the loop but they can keep enrolling as they wish
do {
System.out.print("Enter course to enroll (Q to quit): ");
Scanner in = new Scanner(System.in);
String course = in.nextLine();
if (!course.equals("Q")) {
courses = courses + "\n " + course;
tuitionBalance = tuitionBalance + costOfCourse;
}
else {
break;
}
}
while (1 != 0);
System.out.println("ENROLLED IN: " + courses);
}
// View balance
public void viewBalance() {
System.out.println("Your balance is: $" + tuitionBalance);
}
// Pay tuition
public void payTuition() {
viewBalance();
System.out.print("Enter your payment: $");
Scanner in = new Scanner(System.in);
int payment = in.nextInt();
tuitionBalance = tuitionBalance - payment;
System.out.println("Thank you for your payment of $" + payment);
viewBalance();
}
// Show status
public String toString() {
return "Name: " + firstName + " " + lastName +
"\nGrade Level: " + gradeLevel +
"\nStudent ID: " + studentID +
"\nCourses Enrolled: " + courses +
"\nBalance: $" + tuitionBalance;
}
}