Question

In: Computer Science

Define a class for the student record. The class should instance variables for Quizzes, Midterm, Final...

Define a class for the student record. The class should instance variables for Quizzes, Midterm, Final and total score for the course and final letter grade.

The class should have input and output methods. The input method should not ask for the final numeric grade, nor should it ask for final letter grade. The classes should have methods to compute the overall numeric grade and the final letter grade. These two methods will be void methods that set the appropriate instance variables.

Make sure to add default constructor.

Your program should use all the described methods. You should have set of Accessor(getter) and mutator(setter) methods for all instance variables, whether your program uses them or not.

The program should read in the students’ scores two quizzes, midterm and final and display the student’s records, which consists of all the above +final number and final letter grade.

Overall numeric grade is calculated as 50%-final exam, 25%-midterm and two quizzes together count for 25%.

For letter grade

90-100 is A

80-89 is B

70-79 is C

60-69 is D

And any grade <60 is F grade

When taking input, quiz grades are out of 10 points and midterm and final are out of 100 points.

Solutions

Expert Solution

import java.util.Scanner;

class Student {         //student class
        
        Scanner sc = new Scanner(System.in);
        
        private int quiz1;              //all the variables are declared as private
        private int quiz2;
        private int midTerm;
        private int finalTerm;
        
        private double numericGrade;
        private char letterGrade;
        
        public Student() {      //default constructor to initialize the variables
                setQuiz1(0);
                setQuiz2(0);
                setMidTerm(0);
                setFinalTerm(0);
                setNumericGrade(0.0);
                setLetterGrade('\0');
        }
        
        //getter and setter methods for all the private variables

        public int getQuiz1() {
                return quiz1;
        }

        public void setQuiz1(int quiz) {
                this.quiz1 = quiz;
        }
        
        public int getQuiz2() {
                return quiz2;
        }

        public void setQuiz2(int quiz2) {
                this.quiz2 = quiz2;
        }


        public int getMidTerm() {
                return midTerm;
        }

        public void setMidTerm(int midTerm) {
                this.midTerm = midTerm;
        }

        public int getFinalTerm() {
                return finalTerm;
        }

        public void setFinalTerm(int finalTerm) {
                this.finalTerm = finalTerm;
        }
        
        //method to get marks in quizzes, mid term and final from user 
        
        public void marksInput()
        {
                System.out.println("Enter the marks you got in the first quiz");
                setQuiz1(sc.nextInt());
                System.out.println("Enter the marks you got in the second quiz");
                setQuiz2(sc.nextInt());
                System.out.println("Enter the marks you got in the Mid Term examination");
                setMidTerm(sc.nextInt());
                System.out.println("Enter the marks you got in the final term examinations");
                setFinalTerm(sc.nextInt());
        }
        
        //getter and setter methods for letter grade and numeric grade
        
        public void setLetterGrade(char letterGrade) {
                this.letterGrade = letterGrade;
        }

        public void setNumericGrade(double numericGrade) {
                this.numericGrade = numericGrade;
        }
        
        public double getNumericGrade() {
                return numericGrade;
        }
        
        public char getLetterGrade() {
                return letterGrade;
        }

        //method to calculate numeric grade and letter grade using getter and setter methods
        
        public void calculate() {
                
                //calculating numeric grade and storing the value in variable calc-
                
                double calc = (0.5 * getFinalTerm()) +
                                          (0.25 * getMidTerm()) +
                                          ((12.5/10) * getQuiz1()) +
                                          ((12.5/10) * getQuiz2());
                setNumericGrade(calc);  //setting the numeric grade  
                
                //determining the letter grade with the help of numeric grade-
                
                if(getNumericGrade() >= 90 && getNumericGrade() <= 100)
                        setLetterGrade('A');
                else if(getNumericGrade() >=80 && getNumericGrade() <90)
                        setLetterGrade('B');
                else if(getNumericGrade() >= 70 && getNumericGrade() < 80)
                        setLetterGrade('C');
                else if(getNumericGrade() >= 60 && getNumericGrade() < 70)
                        setLetterGrade('D');
                else
                        setLetterGrade('F');
                
                
        }
        
        //method to show the final grade to the user
        
        public void showGrade() {
                
                System.out.println("Your final numeric grade is : " + getNumericGrade());
                System.out.println("Your final grade is : " + getLetterGrade());
        }
        
}
        
        //class with main method

public class Main {

        public static void main(String[] args) {
                Student st = new Student();
                st.marksInput();        //calling marksInput() method
                st.calculate();         //calling calculate() method
                st.showGrade();         //calling showGrade() method
        }

}

Related Solutions

Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
Design a class named Student that contains the followingprivate instance variables: A string data field name...
Design a class named Student that contains the followingprivate instance variables: A string data field name for the student name. An integer data field id for the student id. A double data field GPA for the student GPA. An integer data field registeredCredits. It contains the following methods: An empty default constructor. A constructor that creates a student record with a specified id and name. The get and set methods for id, name, GPA, and registeredCredits. A method called registerCredit...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named...
(java) Write a class called CoinFlip. The class should have two instance variables: an int named coin and an object of the class Random called r. Coin will have a value of 0 or 1 (corresponding to heads or tails respectively). The constructor should take a single parameter, an int that indicates whether the coin is currently heads (0) or tails (1). There is no need to error check the input. The constructor should initialize the coin instance variable to...
Define a class to represent a Temperature. Your class should contain Instance variable int fahrenheit A...
Define a class to represent a Temperature. Your class should contain Instance variable int fahrenheit A parameterized constructor; Member method to calculate the equivalent temperature in Celsius unit toCelsius() with decimal value. double toCelsius() Conversion formula: celsius= (fahrenheit - 32) * 5/9 Method definition to override the equals() method boolean equals(Object obj)
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # #...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # # - meat # - to_go # - rice # - beans # - extra_meat (default: False) # - guacamole (default: False) # - cheese (default: False) # - pico (default: False) # - corn (default: False) # #The constructor should let any of these attributes be #changed when the object is instantiated. The attributes #with a default value should be optional. Both positional #and...
SalaryCalculator in Java. The SalaryCalculator class should have instance variables of: an employee's name, reportID that...
SalaryCalculator in Java. The SalaryCalculator class should have instance variables of: an employee's name, reportID that is unique and increments by 10, and an hourly wage. There should also be some constructors and mutators, and accessor methods.
In Java The Order class should have:  Seven instance variables: the order number (an int),...
In Java The Order class should have:  Seven instance variables: the order number (an int), the Customer who made the order, the Restaurant that receives the order, the FoodApp through which the order was placed, a list of food items ordered (stored as an array of FoodItem), the total number of items ordered (an int), and the total price of the order (a double).  A class constant to set the maximum number of items that can be ordered...
public class OperationsBetween { // You must define the following: // 1.) Two private instance variables,...
public class OperationsBetween { // You must define the following: // 1.) Two private instance variables, min and max   // 2.) A constructor which takes initial values for // min and max // 3.) An instance method named sum, which sums the // values between min and max and returns the // result. For example, if min = 3 and max = 5, // then this should return 12 (3 + 4 + 5). If // min is greater than...
public class OperationsBetween { // You must define the following: // 1.) Two private instance variables,...
public class OperationsBetween { // You must define the following: // 1.) Two private instance variables, min and max // // 2.) A constructor which takes initial values for // min and max // // 3.) An instance method named sum, which sums the // values between min and max and returns the // result. For example, if min = 3 and max = 5, // then this should return 12 (3 + 4 + 5). If // min is...
The Hole Class Description: For the Hole class, there are three instance variables: the par for...
The Hole Class Description: For the Hole class, there are three instance variables: the par for the hole, the length of the hole in yards, and a Boolean valued indicator of whether the hole is one in which the players’ full drives will be measured for distance. John clarifies: The length of the hole in yards determines par for the hole. The current standard is: No more than 250 yards Par 3 251 to 470 yards Par 4 471 to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT