-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
83 lines (67 loc) · 2.13 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
package studentdatabesapp;
import java.util.Scanner;
public class Student {
private String firstName;
private String lastName;
private int gradeYear;
private String studentID;
private String courses = "";
private int tuitionBalance;
private static int costOfCourse = 600;
private static int id = 1000;
//Constructor: prompt user to enter student's name and year
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 class level: ");
this.gradeYear = in.nextInt();
setStudentID();
}
//Generate an ID
private void setStudentID() {
//Grade level + ID
id++;
this.studentID = gradeYear + "" + id;
}
// Enroll in courses
public void enroll() {
// Get inside loop, user hits 0
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);
}
// 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: " + gradeYear +
"\nStudent ID: " + studentID +
"\nCourses Enrolled:" + courses +
"\nBalance: $" + tuitionBalance;
}
}