Question
The code for the grade generator is posted below: 1 import java.util.Scanner; 2 3 /** 4 * Driver program that takes the user's name, activity
The code for the grade generator is posted below:
1 import java.util.Scanner; 2 3 /** 4 * Driver program that takes the user's name, activity average, 5 * quiz average, project average, and exam averages as input 6 * and calculates their final grade in COMP 1210. 7 */ 8 public class GradeGenerator { 9 10 /** 11 * Takes user name, activity average, quiz average, project 12 * average, and exam scores via standard input and 13 * calculates the final grade for COMP 1210. 14 * 15 * @param args Command line arguments (not used). 16 */ 17 public static void main(String[] args) { 18 double actvAvg, quizAvg, projAvg, exam1Score, 19 exam2Score, finalExamScore; 20 String name; 21 Grade comp1210Grade; 22 Scanner stdInReader = new Scanner(System.in); 23 24 // get user input for name 25 System.out.print("Enter your name: "); 26 name = stdInReader.nextLine(); 27 28 // get user input for activity, quiz & project averages 29 System.out.print("Enter your activity average: "); 30 actvAvg = Double.parseDouble(stdInReader.nextLine()); 31 System.out.print("Enter your quiz average: "); 32 quizAvg = Double.parseDouble(stdInReader.nextLine()); 33 System.out.print("Enter your project average: "); 34 projAvg = Double.parseDouble(stdInReader.nextLine()); 35 36 // get user input for exam scores 37 System.out.print("Enter your exam 1 score: "); 38 exam1Score = Double.parseDouble(stdInReader.nextLine()); 39 System.out.print("Enter your exam 2 score: "); 40 exam2Score = Double.parseDouble(stdInReader.nextLine()); 41 System.out.print("Enter your final exam score: "); 42 finalExamScore = Double.parseDouble(stdInReader.nextLine()); 43 44 // the line below, creates the Grade object with the name read in 45 comp1210Grade = new Grade(name); 46 47 /* 48 ------------------------------------------------------------- 49 Fill in the code below to complete your Activity 50 ------------------------------------------------------------- 51 */ 52 53 // set the lab averages for activity and quiz 54 55 // set the project average 56 57 // set exam scores 58 59 // calculate COMP 1210 grade 60 double courseAvg = comp1210Grade.calculateGrade(); 61 // print out COMP 1210 62 System.out.print("Your average for COMP 1210 is: " 63 + courseAvg); 64 } 65 }
Goals: By the end of this activity you should be able to do the following Understand the basic syntax of the Java programming language Have a better understanding of classes and methods Have a better understanding of how to use the viewer canvas in jGRASP Description: In this activity you will create two classes. First, you will create a class called Grade which will represent your grade in COMP 1210. The second class, which will be called GradeGenerator, is a driver program that will calculate your course average. Words underlined and highlighted in blue represent concepts and terminology that will be important for Exam 1 on Wednesday. Boxed-in text does not have to be read in lab, but explains the highlighted concepts in context as an exam review. See pages 3 - 5 for important information related to all future projects (highlighted in red) Directions: Part 1: Grade.java - skeleton code (minimal code required to compile the class and methods with the specified method signatures) Create your Grade class and declare the following instance variables using the private access (or visibility modifier o examl, exam2, and finalExam: double values to hold exam grades o activity Avg: double that holds the activity average o quizAvg: double that holds the quiz average o projectAvg: double that holds the project average o studentName: String representing student name Read the boxed-in portions after lab to help study for Exam1! Instance variables are declared inside of the class, but not inside of a method. Instance variables are available to any instance method in the class. They should be private to avoid violating encapsulation (see class notes / textbook). When an object is created, space is set aside for the instance variables, and the variables are assigned initial values An access (or visibility) modifier specifies whether a member of a class can be accessed and modified from outside of the class (public) or inside of the class only (private). The protected visibility modifier will be further discussed in chapter 9 with respect to inheritance Which of your instance variables are reference tvpes, which are primitive tvpes, and what is the difference between the two? You will now declare three constants representing the three possible exams. Declare the three constants with public visibility . public static final int EXAM 1 = 1, EXAM 2 2, FINAL = 3; Constants are fields in a class that contain a value that never changes. Constant names are capitalized and are declared as static (they exist even when an object has not be created and can be accessed using the class name, similar to static methods) and final (the value cannot be changed after it has been assigned). An example of a public constant: Math.PI Why do public instance variables violate encapsulation while public constants do not? Goals: By the end of this activity you should be able to do the following Understand the basic syntax of the Java programming language Have a better understanding of classes and methods Have a better understanding of how to use the viewer canvas in jGRASP Description: In this activity you will create two classes. First, you will create a class called Grade which will represent your grade in COMP 1210. The second class, which will be called GradeGenerator, is a driver program that will calculate your course average. Words underlined and highlighted in blue represent concepts and terminology that will be important for Exam 1 on Wednesday. Boxed-in text does not have to be read in lab, but explains the highlighted concepts in context as an exam review. See pages 3 - 5 for important information related to all future projects (highlighted in red) Directions: Part 1: Grade.java - skeleton code (minimal code required to compile the class and methods with the specified method signatures) Create your Grade class and declare the following instance variables using the private access (or visibility modifier o examl, exam2, and finalExam: double values to hold exam grades o activity Avg: double that holds the activity average o quizAvg: double that holds the quiz average o projectAvg: double that holds the project average o studentName: String representing student name Read the boxed-in portions after lab to help study for Exam1! Instance variables are declared inside of the class, but not inside of a method. Instance variables are available to any instance method in the class. They should be private to avoid violating encapsulation (see class notes / textbook). When an object is created, space is set aside for the instance variables, and the variables are assigned initial values An access (or visibility) modifier specifies whether a member of a class can be accessed and modified from outside of the class (public) or inside of the class only (private). The protected visibility modifier will be further discussed in chapter 9 with respect to inheritance Which of your instance variables are reference tvpes, which are primitive tvpes, and what is the difference between the two? You will now declare three constants representing the three possible exams. Declare the three constants with public visibility . public static final int EXAM 1 = 1, EXAM 2 2, FINAL = 3; Constants are fields in a class that contain a value that never changes. Constant names are capitalized and are declared as static (they exist even when an object has not be created and can be accessed using the class name, similar to static methods) and final (the value cannot be changed after it has been assigned). An example of a public constant: Math.PI Why do public instance variables violate encapsulation while public constants do notStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started