Two's complement Base 10 Equivalent 1 1 1 1 0 0 1 1 1 1 0 0 ___________________________________ + 1 1 1 1 1 1 1 0 1 0 0 0 ___________________________________ -------------------------- Sum _________________________ ___________________________________
//***************************************************** // Student.java // // A class representing a student; holds info about // the student's name and test grades. //***************************************************** public class Student { //declare instance data ____________________________________________ // name ____________________________________________ // grade for test #1 ____________________________________________ // grade for test #2 //--------------------------------------------------- // Constructor -- creates a student object whose name // is the value passed in. //--------------------------------------------------- public Student(String studentName) { // Assign the instance variable name the value passed in // and initialize the two test grades to 0 } //--------------------------------------------------- // inputGrades: Prompts for and reads in grades for // the student's two tests. No parameters or return value. //--------------------------------------------------- public void inputGrades() { ... body of inputGrades ...(don't fill in) } //--------------------------------------------------- // getName: returns the student's name. //--------------------------------------------------- _________________________________________________ //fill in header { // fill in the body of the method (just one line!) _____________________________________________________; } //--------------------------------------------------- // getAverage: Computes and return the average of the // student's test grades. No parameters. //--------------------------------------------------- _____________________________________________________ //fill in header { // Compute and return the average (it can be done in one statement) _______________________________________________________ ; } //------------------------------------------------------ // highestScore: Returns the highest test grade - no // parameters. // ----------------------------------------------------- ______________________________________________________ // fill in header { int highGrade; // a local variable to hold the highest grade // Write an if statement to assign highGrade the highest of the // two test grades // Return the highest grade return highGrade; } }
public class StudentGrades { public static void main (String[] args) { Student student1 = new Student ("Sarah"); Student student2 = new Student ("John"); student1.inputGrades(); student2.inputGrades(); double average1 = student1.getAverage(); // Write an if ...else... statement that prints the message // "Great work!" if Sarah's average is greater than 84; "Doing // fine" if the average is between 70 and 84 (inclusive); // "Work harder" otherwise // Write an if ... else that determines who has the highest // average - use the getName method to print the name of the person } }