Question

In: Computer Science

Discover classes for generating a student report card that lists all classes, grades, and the grade...

Discover classes for generating a student report card that lists all classes, grades, and the grade point average
for a semester. Create a UML diagram with constructors and methods. Implement the code including Javadoc comments.

Solutions

Expert Solution

The classes that are needed for Student report card are : Course , Grade , Report, ReportTester , Student

Course.java

public class Course {
   private String name;
   private String courseNum;
   private Grade grade;
  
   /**
   * default constructor for Course object - sets name and course number to N/A and grade to null
   */
   public Course()
   {
       this.name = "N/A";
       this.courseNum = "N/A";
       this.grade = null;
   }
  
   /**
   * overloaded constructor for Course object
   * @param n - String to set as Course name
   * @param c - String to set as Course number
   * @param s - Grade object to set as course grade
   */
   public Course(String n, String c, Grade g)
   {
       this.name = n;
       this.courseNum = c;
       this.grade = g;
   }
  
   /**
   * gets the Course name
   * @return - Course name as String object
   */
   public String getName()
   {
       return name;
   }
  
   /**
   * gets the course number
   * @return - Course number as String object
   */
   public String getCourseNum()
   {
       return courseNum;
   }
  
   /**
   * gets the course letter grade
   * @return - letter grade as a String
   */
   public String getLetterGrade()
   {
       return grade.getLetter();
   }
  
   /**
   * gets the numerical grade value of Course
   * @return - grade value as a double
   */
   public double getGradeValue()
   {
       return grade.getNumber();
   }
  
   /**
   * sets the course name to a given string
   * @param s - String to set as course name
   */
   public void setName(String s)
   {
       name = s;
   }
  
   /**
   * sets the course number to a given string
   * @param s - String to set as course number
   */
   public void setCourseNum(String s)
   {
       courseNum = s;
   }
  
   /**
   * sets the course section number to a given int
   * @param s - integer to set as course number
   */
   public void setGrade(Grade s)
   {
       grade = s;
   }
}

Grade.java

public class Grade {
   private String letter;
   private double number;
  
   public Grade()
   {
       this.letter = "N/A";
   }
  
   public Grade(String l)
   {
       this.letter = l;
   }
  
   public String getLetter()
   {
       return letter;
   }
  
   public void setLetter(String l)
   {
       letter = l;
   }
  
   public double getNumber()
   {
       if(letter == "A")
       {
           return 4.0;
       }
       else if(letter == "B")
       {
           return 3.0;
       }
       else if(letter == "C")
       {
           return 2.0;
       }
       else if(letter == "D")
       {
           return 1.0;
       }
       else
       {
           return 0.0;
       }
   }
}

ReportCard.java

import java.util.ArrayList;

public class ReportCard {
   private Student stu;
   private ArrayList<Course> courses;
  
   public ReportCard()
   {
       this.stu = null;
       this.courses = null;
   }
  
   public ReportCard(Student s, ArrayList<Course> c)
   {
       this.stu = s;
       this.courses = c;
   }
  
   public double calculateGPA()
   {
       double totalPts = 0.0;
       for(Course c : courses)
       {
           totalPts += c.getGradeValue();
       }
      
       double gpa = totalPts/courses.size();
       return Math.round(gpa * 100.0) / 100.0;
   }
  
   public String toString()
   {
       String str = "";
       str += "NAME: " + stu.getName() + "\nID: " + stu.getID() + "\n";
       str += "\nCOURSES: \n";
       for(Course c : courses)
       {
           str += c.getName() + "\t\t\t" + c.getLetterGrade() + "\n";
       }
       str += "\nGPA: " + calculateGPA();
      
       return str;
   }
}

ReportCardTester.java

import java.util.ArrayList;

public class ReportCardTester {

   public static void main(String[] args) {
      
       Student test = new Student("Mariel T", "012345");
       ArrayList<Course> myCourses = new ArrayList<Course>();
      
       Course c1 = new Course("CECS 100", "8109", new Grade("A"));
       Course c2 = new Course("CECS 277", "1243", new Grade("A"));
       Course c3 = new Course("PHYS 151", "4718", new Grade("B"));
      
       myCourses.add(c1);
       myCourses.add(c2);
       myCourses.add(c3);
      
       ReportCard myReport = new ReportCard(test, myCourses);
      
       System.out.print(myReport);

   }

}

Student.java

public class Student {
   private String name;
   private String id;
  
   /**
   * default constructor for Student object - sets Student name & id to "N/A"
   */
   public Student()
   {
       this.name = "N/A";
       this.id = "N/A";
   }
  
   /**
   * overloaded constructor for Student object
   * @param n - String to set as name attribute
   * @param i - String to set as id attribute
   */
   public Student(String n, String i)
   {
       this.name = n;
       this.id = i;
   }
  
   /**
   * gets the Student's name
   * @return - name attribute as String
   */
   public String getName()
   {
       return name;
   }
  
   /**
   * gets the Student's ID
   * @return - id attribute as String
   */
   public String getID()
   {
       return id;
   }
  
   /**
   * sets the Student name attribute to a given String
   * @param n - String to set as the name
   */
   public void setName(String n)
   {
       name = n;
   }
  
   /**
   * sets the Student id attribute to a given String
   * @param n - String to set as the id
   */
   public void setID(String i)
   {
       id = i;
   }
}


Related Solutions

The following data lists the grades of 6 students selected at random: Mathematics grade: (70, 92,...
The following data lists the grades of 6 students selected at random: Mathematics grade: (70, 92, 80, 74, 65, 85) English grade: (69, 88, 75, 80, 78, 90) a). Find the regression line. b). Compute and interpret the correlation coefficient.
Create a report that lists all the customers in alphabetical order by last name. The report...
Create a report that lists all the customers in alphabetical order by last name. The report should include first name, last name, and email address of all customers. This report involves getting data from one table. The three items should be lined up in columns. Use one of the formatting functions available through Python (the % operator or the format function). Don’t use tabs to line up columns, this does not reliably work and is inflexible.1 Even though we won’t...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with A = 4, B = 3, and so on down to F = 0. Find the expected value. This is the average grade in this course. Explain how to simulate choosing students at random and recording their grades. Simulate 50 students and find the mean of their 50 grades. Compare this estimate of the expected value with the exact expected value from part (a)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT