In: Computer Science
Lab Assignment 1
2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II
STUDENT AFFAIRS
DUE DATE: 14.10.2020 – 23:59
In this lab, we will create a model course registration application. Please check out the example run of the program first.
You are asked to implement the classes;
The commands and their arguments for this week are:
where letterGrade can be (AA, BA, BB, CB, CC, DC, DD, F, FX).
In order to store the students and the courses, create 2 Arrays for them in the StudentAffairs class. You need to take commands from user until you see the “Q” command. For this purpose, you need to create while loop. Stopping condition of this command is “Q” command from user. Each command needs to be differentiated either if clause or switch case. After each command differentiated, specific information subcommands will be taken that belongs the specific main command parsed with space. Each command has specific things to do and command line output that will inform the user. Look at the demo video for better understanding. However, at first you need to create Student, Course and Grade classes.
Grade Class
Data Declarations:
Student Class
Data Declarations:
Course Class
Data Declarations:
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Student{
Grade[] grades;
String name;
String studentId;
staatic int gradecount = 0;
public Sudent(String name,String studentId){
this.name = name;
this.studentId = studentId;
this.grades = new Grade[4];
}
boolean addGrade(String letterGrade){
if(this.grades < 4){
grades[gradecount] = new Grade(letterGrade);
gradecount++;
return true;
}else{
return flase;
}
}
boolean removeGrade(int index){
if(gradecount == 0){
return flase;
}else{
for(int i = 0;i<gradecount-1;i++){
if(i >= index){
Grade temp = this.grades[i];
this.grades[i] = this.grades[i+1];
this.grades[i+1] = temp;
}
}
gradecount = gradecount - 1;
}
}
String printGrade(){
String send_all = "";
for(int i = 0;i<gradecount;i++){
send_all = send_all + " " + grades[i].grade;
}
return send_all;
}
double averageGrade(){
double avg = 0;
for(int i = 0;i<gradecount;i++){
avg = avg + grades[i].convertLetter();
}
avg = avg/gradecount;
return avg;
}
String toString(){
return this.name + this.studentId;
}
}
class Course{
String CourseCode;
String day;
int StudentCount;
int Capacity;
double averageGrade;
public Course(String CourseCode,String day,int StudentCount,int
Capacity,doubleAverageGrade){
this.CourseCode = CourseCode;
this.day = day;
this.StudentCount = StudentCount;
this.Capacity = Capacity;
this.averageGrade = averageGrade;
}
boolean addGrade(double grade){
if(StudentCount > Capacity){
return flase;
}else{
this.averageGrade = (this.averageGrade + grade)/2;
this.StudentCount = this.StudentCount + 1;
return true;
}
}
boolean removeGrade(double grade){
if(StudentCount == 0){
return flase;
}else{
this.averageGrade = this.averageGrade - grade;
this.StudentCount = this.StudentCount - 1;
return true
}
}
String toString(){
return this.CourseCode;
}
}
class Grade{
double grade;
String letter_grade;
public Grade(String letter_grade){
this.letter_grade = letter_grade
}
double convertLetter(){
if(this.letter_grade.equals("AA"))
this.grade = 4.0;
else if(this.letter_grade.equals("BA"))
this.grade = 3.5;
else if(this.letter_grade.equals("BB"))
this.grade = 3.0;
else if(this.letter_grade.equals("CB"))
this.grade = 2.5;
else if(this.letter_grade.equals("CC"))
this.grade = 2.0;
else if(this.letter_grade.equals("DC"))
this.grade = 1.5;
else if(this.letter_grade.equals("DD"))
this.grade = 1.0;
else if(this.letter_grade.equals("F"))
this.grade = 0;
else
this.grade = 0;
return letter_grade;
}
}
/* Name of the class has to be "Main" only if the class is public.
*/
class StudentAffair
{
public static void main (String[] args) throws
java.lang.Exception
{
Scanner sc = new
Scanner(System.in);
while(true){
String s = sc.nextLine();
if(s.equals("Q")
break;
Course c = new
Course("aaa","asdf",12,2,3.5);
Grade g = new Grade("AB");
Student s = new
Student("ABCD","123");
c.addGrade(2.4);
c.removeGrade(2.1);
s.addGrade("AA");
s.removeGrade(2);
s.printGrade();
}
}
}