Student - System.out.print"Enter" name"'s...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// **************************************************************** // Student.java // // Define a student class that stores name, score on test 1, and // score on test 2. Methods prompt for and read in grades, // compute the average, and print student's name. // **************************************************************** import java.util.Scanner; public class Student { //declare instance data String name; int test1; int test2; //---------------------------------------------------- //constructor //---------------------------------------------------- public Student(String studentName) { name = studentName; test1 = 0; test2 = 0; } //---------------------------------------------------- //inputGrades: prompt for and read in student's grades for test1 and test2. //Use name in prompts, e.g., "Enter's Joe's score for test1". //---------------------------------------------------- public void inputGrades() { Scanner scan = new Scanner(System.in);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.print("Enter " + name + "'s score for test 1: "); test1 = scan.nextInt(); System.out.print("Enter " + name + "'s score for test 2: "); test2 = scan.nextInt(); } //----------------------------------------------------//getAverage: compute and return the student's test average //----------------------------------------------------public double getAverage() { return (double)(test1 + test2)/2; } //----------------------------------------------------//getName: returns the student's name //----------------------------------------------------public String getName() { return name; } //----------------------------------------------------//toString: returns a String representing the Student object //----------------------------------------------------public String toString() { return "Name: " + name + " Test 1: " + test1 + " Test 2: " + test2; } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

Student - System.out.print"Enter" name"'s...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online