Podcast
Questions and Answers
What is the private instance variable for score 1 in Class Exams?
What is the private instance variable for score 1 in Class Exams?
What is the constructor for Class Exams?
What is the constructor for Class Exams?
What does the method void setScore1(int sc) do in Class Exams?
What does the method void setScore1(int sc) do in Class Exams?
Sets the value of score1 to sc.
What does the method int getScore1() return in Class Exams?
What does the method int getScore1() return in Class Exams?
Signup and view all the answers
What is the return type of the method String toString() in Class Exams?
What is the return type of the method String toString() in Class Exams?
Signup and view all the answers
What private instance variable is used in Class Student for the first name?
What private instance variable is used in Class Student for the first name?
Signup and view all the answers
What does the method double getAverage() return in Class Student?
What does the method double getAverage() return in Class Student?
Signup and view all the answers
What does the method void remove() in Class ClassRoll do?
What does the method void remove() in Class ClassRoll do?
Signup and view all the answers
What does the method void save() do in Class ClassRoll?
What does the method void save() do in Class ClassRoll?
Signup and view all the answers
What is declared in Class ClassRoll to hold student names?
What is declared in Class ClassRoll to hold student names?
Signup and view all the answers
What method prompts the user for a filename in Class Main?
What method prompts the user for a filename in Class Main?
Signup and view all the answers
Study Notes
Class Exams
- Contains private instance variables:
int score1
andint score2
. - Uses a no-parameter constructor for initializing class state.
- Public methods include:
-
void setScore1(int sc)
: Updatesscore1
. -
void setScore2(int sc)
: Updatesscore2
. -
int getScore1()
: Returns the value ofscore1
. -
int getScore2()
: Returns the value ofscore2
. -
String toString()
: Returns scores in formatted string.
-
Class Student
- Private instance variables include:
String fName
,String lName
, and an instance ofExams examGrds
. - Constructor
Student(String fn, String ln)
initializesfName
,lName
, and creates anExams
object. - Public methods consist of:
-
void setScore1(int sc)
: Delegates score setting for exam 1 toexamGrds
. -
void setScore2(int sc)
: Delegates score setting for exam 2 toexamGrds
. -
String toString()
: Returns the formatted string containing name and exam scores. -
double getAverage()
: Calculates the average of exam scores. -
int compareTo(Student s)
: Compares student names alphabetically and returns comparison results.
-
Class ClassRoll
- Private variables:
ArrayList<Student> students
,String title
, andString fileName
. - Constructor
ClassRoll(String f)
reads student data from a specified input file and initializes students in anArrayList
. - Public methods include:
-
void remove()
: Prompts for student name and removes them from the list. -
void display()
: Outputs the course title and each student's records, including their average. -
void add()
: Adds a new student based on user input and prevents duplicates. -
void changeScore1()
: Changes the exam 1 score for a given student. -
void changeScore2()
: Changes the exam 2 score for a given student. -
void find()
: Displays the scores and average for a specified student. -
void sortAverage()
: Sorts students by their average score without using built-in sort methods. -
void sortNames()
: Sorts students by name in ascending order without using built-in sort methods. -
void save()
: Saves the updated list of students back to the input file.
-
Class Main
- Contains static methods:
-
void prompt()
: Displays commands to the user. -
void main(String[] args)
: Manages user input, file reading, and invokes corresponding methods for class roll management. It continues until the user entersq
orquit
.
-
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
This quiz covers key concepts related to the Class Exams in COP 2210. It includes important definitions of instance variables, constructors, and public methods associated with the class. Use these flashcards to review and reinforce your understanding of the material.