Question

In: Computer Science

Lab Assignment 1 2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II STUDENT AFFAIRS DUE...

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;

  • Student.
  • Course.
  • Grade.
  • StudentAffairs. It will contain the main method.

The commands and their arguments for this week are:

  • createCourse <courseCode> <capacity> <day> <studentCount> <averageGrade>
  • createStudent <studentName> <studentID>
  • addGradeStudent <studentID> <letterGrade>
  • addGradeCourse <courseCode> <grade>
  • removeGradeStudent <studentID> <letterGrade>
  • removeGradeCourse <courseCode> <grade>
  • averageGradeStudent <studentID>
  • averageGradeCourse <courseCode>
  • printGradesStudent <studentID>
  • Q

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:

  • double grade Methods:
  • Constructor : Constructor gets the letter grade and converts it to number representation with the method called convertLetter than holds that value within the grade variable.
  • double convertLetter (String letterGrade) : Gets letter grade and returns numeric version of it. (AA=4.0, BA=3.5, BB=3.0, CB=2.5, CC=2.0, DC=1.5, DD=1.0, F=0, FX=0)
  • Create Getters and Setters.

Student Class

Data Declarations:

  • Grade[] Grades : Holds the Grades of the Student.
  • String Name, String StudentID, int GradeCount Methods:
  • Constructor : Constructor gets the name of the student and the student ID. Grade array should be initialized here as well (array size is 4). GradeCount is 0 initially.
  • boolean addGrade (String letterGrade) : Adding a grade to the Grade array. Returns false if the gradeCount equals to the array size. Increase gradeCount if the grade succesfully added to the array and method should returns true.
  • boolean removeGrade (int index) : Remove a grade from the Grade array with given specific index. Returns false if the gradeCount equals to the 0. Decrease gradeCount if the grade successfully removed from the array and method should returns true. Don’t forget to be shifting array after deleting element.
  • String printGrades() : Returns all grades of student.
  • double averageGrade() : Returns average grades of student.
  • String toString( ) : The format is “<name>(<ID>)”.
  • Create Getters and Setters.

Course Class

Data Declarations:

  • String CourseCode, day
  • int studentCount, Capacity
  • double averageGrade Methods:
  • Constructor : Gets all of the data declarations.
  • boolean addGrade (double grade) : Adding a grade to the course. That means student count needs to increase by one. And average grade needs to be calculated. Return false if the capacity reached.
  • boolean removeGrade (double grade) : Removing a grade from the course. That means student count needs to decrease by one. And average grade needs to be calculated. Return false if the student count is already 0.
  • String toString( ) : The format is “<courseCode>”.
  • Create Getters and Setters.

Solutions

Expert Solution

/* 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();
       }
   }
}


Related Solutions

Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
CS 238 – Assembly Language Programming Fall 2019 Assignment 1 (Due: September 10, 2019) Submission Instructions:...
CS 238 – Assembly Language Programming Fall 2019 Assignment 1 (Due: September 10, 2019) Submission Instructions: Online submissions on Blackboard are preferred. Feel free to edit this Word document to insert your answers. Multiple online submissions on Blackboard are allowed, but only the last online submission made by the midnight of September 10 will be graded. Alternatively, a paper submission is possible, but it needs to be done in class on September 10. 1. Data can be interpreted as required...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the student will write a C++ program that implements a “fraction” object. When writing the object, the student will demonstrate mastery of implementing overloaded operators in a meaningful way for the object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Mathematical Modeling - Fractions · Operator Overloading – Binary Operators (Internal Overload) · Operator Overloading – Binary Operator (External...
Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an...
Programming assignment (75 pts): The Lab 1 development assignment was largely an exercise in completing an already started implementation. The Lab 2 development assignment will call on you to implement a program from scratch. It’s an exercise in learning more about Java basics, core Java Classes and Class/ method-level modularity. Implement a ‘runnable’ Class called “NumericAnalyzer”. Here’s the functional behavior that must be implemented. NumericAnalyzer will accept a list of 1 or more numbers as command line arguments. These numeric...
BA 211 Fundamentals of Financial Accounting Project #1 – Financial Statements make this into excel spread...
BA 211 Fundamentals of Financial Accounting Project #1 – Financial Statements make this into excel spread sheets Requirements Use the following transaction descriptions to compose the following items: ●Journal entries for all transactions through the end of year (Dec. 31) ●End of year unadjusted trial balance ●Adjusting journal entries for end of year adjusting transactions ●End of year adjusted trial balance ●Income Statement ●Statement of Retained Earnings ●Balance Sheet Transactions: 1.Dec. 1 – a new company is formed called “Lawn...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals...
................................................ ................................................ This programming lab assignment requires that you create a class and use an equals method to compare two or more objects. Your should use your QC5 as a reference. …………………………...…….. …………………………...……. Instructions LAB5 Instructions Using QC5 as a model, create a Rectangle class and a CompareUsingequalsMethod class that uses an   equals Method to determine if two rectangles are equal if and only if their areas are equal. The Rectangle class should have two instance variables length and width....
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design...
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design and implement what is known as the “Game of Life”, conceptualized by the British mathematician John Horton Conway in 1970 to simulate the evolution patterns in a population of living organisms.   The game board is seeded with an initial population pattern, and then evolves based on the set of rules defining when a cell dies or is born into life. A cell’s life cycle...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods and use your main method to test your methods. Your class should be named Array Your class will have the following methods (click on the method signatures for the Javadoc description of the methods): [ https://bit.ly/2GZXGWK ] public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods and use your main method to test your methods. Your class should be named Array Your class will have the following methods (click on the method signatures for the Javadoc description of the methods): [ https://bit.ly/2GZXGWK ] public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int...
CSE/EEE 230 Assignment 4 Fall 2019 Due Sept 30 (11:59PM) In this assignment, you are to...
CSE/EEE 230 Assignment 4 Fall 2019 Due Sept 30 (11:59PM) In this assignment, you are to complete a MIPS program so it will perform the required tasks. The main function of the code is provided. Do not change the code in the main function. There is a loop in the main function. You are to complete the program by writing two functions. Pay particular attention to the purpose of each function and how the parameters and return value are to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT