Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class called Student to holds information about a student. The class co

ID: 3638344 • Letter: D

Question

Design a class called Student to holds information about a student. The class contains
following instance variables and methods:

• A student’s first name and last name.

• A student’s id number. The format should be xxx-xxx where each “x” should be a digit. For example, a valid id number is 123-456. Note that there is a dash symbol in the middle.

• A student’s mid-I exam score and mid-II exam score.

• A student’s average of mid-I and mid-II exam scores.

• A student’s letter grade for the average.

• A method called readStudentName() that reads a student’s first name and last name from a user.

• A method called readStudentId() that reads a student’s id number from a user.

• A method called readStudentScores() that reads a student’s exam scores from a user.

• A method called displayStudentInfo() that displays a student’s first name, last name, id, mid-I score, mid-II score, average, and letter grade. Note that if a student average is between 90 and 100, the grade is A. If the average is greater than or equal to 80 but less than 90, the grade is B. If the average is greater than or equal to 70 but less than 80, the grade is C. If the average is less than 70, the grade is F.

• A method called displayStudentAverage() that displays a student’s mid-I score, mid-II score, and average.

• A method called updateID() that changes the id number of a student that is given as an argument. If the argument doesn’t have a correct format, the method should not update the id number.

• A method called updateScores() that changes the values of mid-I and mid-II exam scores that are given as arguments. If each argument doesn’t have a correct value between 0 and 100, the method should not update the scores.


The following code presents a class named StudentDemo that uses the class Student. If there’s any problem in the demo program, change it to fix the error.

public class StudentDemo {
public static void main(String[] args)
{
Student tom = new Student();
tom.readStudentName();
tom.readStudentId();
tom.readStudentScores();
tom.displayStudentInfo();
tom.displayStudentAverage();
tom.updateID (“111-222”);
tom.updateID (“111444”);
tom.updateScores (100.0, 90.0);
tom.updateScores (99.0, 105.0);
tom.displayStudentInfo();
}
}



This is a sample result of the execution:
Enter first name: Tom
Enter last name: Smith
Enter ID (xxx-xxx): 123456
Incorrect format. Try again: 123-abc
Incorrect format. Try again: 123-456
Enter mid-I exam score: 90.5
Enter mid-II exam score: 89.5

===== Student Information ====
Name: Tom Smith
ID: 123-456
Scores: 90.5 89.5
Average: 90.0 (A)

===== Student Average ====
Scores: 90.5 89.5
Average: 90.0 (A)

===== Student Information ====
Name: Tom Smith
ID: 111-222
Scores: 100.0 90.0
Average: 95.0 (A)

Explanation / Answer

import javax.swing.JOptionPane; public class OddEven { /** * "input" is the number that the user gives to the computer */ private int input; // a whole number("int" means integer) /** * This is the constructor method. It gets called when an object of the OddEven type * is being created. */ public OddEven() { /* * In most Java programs constructors can initialize objects with default values, or create * other objects that this object might use to perform its functions. In some Java programs, the * constructor may simply be an empty function if nothing needs to be initialized prior to the * functioning of the object. In this program's case, an empty constructor would suffice, even if * it is empty. A constructor must exist, however if the user doesn't put one in then the compiler * will create an empty one. */ } /** * This is the main method. It gets called when this class is run through a Java interpreter. * @param args command line arguments (unused) */ public static void main(final String[] args) { /* * This line of code creates a new instance of this class called "number" (also known as an * Object) and initializes it by calling the constructor. The next line of code calls * the "showDialog()" method, which brings up a prompt to ask you for a number */ OddEven number = new OddEven(); number.showDialog(); } public void showDialog() { /* * "try" makes sure nothing goes wrong. If something does, * the interpreter skips to "catch" to see what it should do. */ try { /* * The code below brings up a JOptionPane, which is a dialog box * The String returned by the "showInputDialog()" method is converted into * an integer, making the program treat it as a number instead of a word. * After that, this method calls a second method, calculate() that will * display either "Even" or "Odd." */ this.input = Integer.parseInt(JOptionPane.showInputDialog("Please Enter A Number")); this.calculate(); } catch (final NumberFormatException e) { /* * Getting in the catch block means that there was a problem with the format of * the number. Probably some letters were typed in instead of a number. */ System.err.println("ERROR: Invalid input. Please type in a numerical value."); } } /** * When this gets called, it sends a message to the interpreter. * The interpreter usually shows it on the command prompt (For Windows users) * or the terminal (For *nix users).(Assuming it's open) */ private void calculate() { if ((this.input % 2) == 0) { JOptionPane.showMessageDialog(null, "Even"); } else { JOptionPane.showMessageDialog(null, "Odd"); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote