-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentInfo.java
More file actions
142 lines (134 loc) · 4.86 KB
/
StudentInfo.java
File metadata and controls
142 lines (134 loc) · 4.86 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
package Student_Database_App;
import java.util.ArrayList;
import java.util.Scanner;
public class StudentInfo {
private String courseEnrollment ;
private String firstName;
private String lastName;
private String collegeYear;
private String studentID;
private int courseCost = 600;
private int balance;
private int payment;
private int TotalCourseCost = 0;
private static int uniqueID = 1000;
private int studentCount;
public StudentInfo(){
this.firstName = getFirstName();
this.lastName = getLastName();
this.collegeYear = getCollegeYear();
this.studentID = getStudentID();
this.courseEnrollment = getCourseEnrollment();
this.balance =balancePayment();
}
ArrayList<String> coursesEnrolled = new ArrayList<>(5);
Scanner userInput = new Scanner(System.in);
// get no of objects to create
public int getStudentCount() {
System.out.print("Enter the number of students to add in DB : " );
studentCount = userInput.nextInt();
return studentCount;
}
public String getFirstName(){
System.out.print("Enter firstName : ");
firstName = userInput.next();
return firstName;
}
public String getLastName(){
System.out.print("Enter lastName : ");
lastName = userInput.next();
return lastName;
}
public String getCollegeYear(){
System.out.println("a -> F.E\nb -> S.E\nc -> T.E\nd -> B.E");
System.out.print("Enter a valid year : ");
collegeYear = userInput.next();
switch (collegeYear){
case "a" : {
collegeYear = "FE";
break;
}
case "b" : {
collegeYear = "SE";
break;
}
case "c" : {
collegeYear = "TE";
break;
}
case "d" : {
collegeYear = "BE";
break;
}
default: {
collegeYear = "invalid";
break;
}
}
return collegeYear;
}
public String getCourseEnrollment() {
boolean answer;
do {
System.out.println("a -> History 101\nb -> Mathematics 101\nc -> English 101\nd -> Chemistry 101\ne -> Computer Science 101");
System.out.print("Select course for enrollment : ");
courseEnrollment = userInput.next();
switch (courseEnrollment) {
case "a": {
courseEnrollment = "History 101";
break;
}
case "b": {
courseEnrollment = "Mathematics 101";
break;
}
case "c": {
courseEnrollment = "English 101";
break;
}
case "d": {
courseEnrollment = "Chemistry 101";
break;
}
case "e": {
courseEnrollment = "Computer Science 101";
break;
}
default: {
System.out.println("Invalid Course selection");
break;
}
}
this.coursesEnrolled.add(this.courseEnrollment);
this.TotalCourseCost += this.courseCost;
System.out.print("select 1 for futher enrollments and 0 to quit : ");
int response = userInput.nextInt();
answer = response == 1 ? true : false;
} while(answer);
return courseEnrollment;
}
public String getStudentID(){
uniqueID++;
return collegeYear + "" + uniqueID;
}
public int balancePayment(){
System.out.print("Enter your amount to pay : " );
payment = userInput.nextInt();
this.balance = this.TotalCourseCost - payment;
return this.balance;
}
public String display(){
return "\n###################################\n" + "\nName : " + this.firstName + " " +
this.lastName + "\nCollege Year : " + this.collegeYear + "\nStudent ID : " +
this.studentID + "\nCourses Enrolled : " + this.coursesEnrolled.toString() +
"\nTotal cost of enrolled courses : " + this.TotalCourseCost +
"\nBalance payment : " + this.balance + "\n";
}
}
// can we parse string to int & vice-versa
// debug while loop and check y its not running?
//creating static members allows to be independent of all objects & true for all objects of the class
//can add validations & checking for : [exception handing + edge cases]
// cannot enroll in same course twice
// balance must not be -ve
// max courses allowed is 5