-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.java
More file actions
92 lines (65 loc) · 2.02 KB
/
student.java
File metadata and controls
92 lines (65 loc) · 2.02 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
package studentdatabase;
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=0;
private static int costOfCourse = 600;
private static int id = 1000;
//Constructor: prompt user to enter student's name and year
public student() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter student first name: ");
this.firstName = sc.nextLine();
System.out.println("Enter student last name: ");
this.lastName = sc.nextLine();
System.out.println("1. Fresher\n2. Sophmore\n3. Junior\n4. Senior\nEnter student class level: ");
this.gradeYear = sc.nextInt();
setStudentID();
}
//Generate an ID
private void setStudentID() {
//Grade level + ID
id++;
this.studentID = gradeYear + "" + id;
}
//Enroll in courses
public void enroll() {
//Get inside a loop, user hits 0
do {
System.out.print("Enter course to enroll (Q to quit) :");
Scanner sc = new Scanner(System.in);
String course=sc.next();
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: Rs." + tuitionBalance + "\n");
}
//Pay Tuition
public void payTuition() {
viewBalance();
System.out.print("Enter your payment: Rs.");
Scanner sc = new Scanner(System.in);
int payment=sc.nextInt();
tuitionBalance = tuitionBalance - payment;
System.out.println("Thank you for your payment of Rs." + payment);
viewBalance();
}
//Show status
public String showInfo() {
return "Name: " + firstName + " " +lastName + "\nGrade Level: " +gradeYear+
"\nStudent ID: " + studentID + "\nCourses Enrolled:"+
courses + "\nBalance: Rs." + tuitionBalance;
}
}