Student.java
//******************************************************************
// Student.java
//******************************************************************
import java.util.Scanner;
public class Student {
String name;
int test1 = 0, test2 = 0;
double average;
Scanner input = new Scanner(System.in);
public Student(String studentName)
{
name = studentName;
test1 = 0;
test2 = 0;
average = 0.0;
}
public void inputGrades() {
System.out.print( "Enter " + name + "'s score for test1: " );
test1 = input.nextInt();
System.out.print( "Enter " + name + "'s score for test2: " );
test2 = input.nextInt();
}
public double getAverage() {
average = (double)( test1 + test2) / 2;
return average;
}
public String getName() {
return name;
}
public static void main(String[] args) {
Student student1 = new Student( "Mary" );
Student student2 = new Student( "Mike" );
student1.inputGrades();
System.out.println("Average for Mary is: " + student1.getAverage() );
student2.inputGrades();
System.out.println("Average for Mike is: " + student2.getAverage() );
}
}
No comments:
Post a Comment