Welcome to Dream.In.Code
Become a Java Expert!

Join 136,905 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,750 people online right now. Registration is fast and FREE... Join Now!




program will not run

 
Reply to this topicStart new topic

program will not run

scorpionviolinist
28 Mar, 2008 - 07:02 AM
Post #1

New D.I.C Head
*

Joined: 29 Feb, 2008
Posts: 36

I can compile the class and the program, but when I try to run Grades.java, it will not run. I don't understand the error message I am getting, and it is a little lengthy.

CODE
// ****************************************************************



CODE
// ****************************************************************


I am not sure how to add code tags... please let me know. But here are the programs:

//**********************************************************
// 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 return a string containing student’s info.
//**********************************************************
import java.util.Scanner;

public class Student
{
//declare instance data
String name;
int test1;
int test2;

//-----------------------------------------------
//constructor
//-----------------------------------------------
public Student(String studentName)
{
//add body of constructor
name = studentName;
}

//-----------------------------------------------
//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)
{
//add body of inputGrades
System.out.println ("Enter " + name + "'s score for test 1");
test1 = scan.nextInt();
System.out.println ("Enter " + name + "'s score for test 2");
test2 = scan.nextInt();
}

//-----------------------------------------------
//getAverage: compute and return the student's test average
//-----------------------------------------------

//add header for getAverage
public double getAverage()
{
//add body of getAverage
double average = ((test1 + test2) / 2);
return average;
}

//-----------------------------------------------
//getName: print the student's name
//-----------------------------------------------

//add header for getName
public String getName()
{
//add body of getName
return name;
}

}


and:

//**********************************************************
// Grades.java
//
// Use Student class to get test grades for two students
// and compute averages
//
//**********************************************************
import java.util.Scanner;


public class Grades
{
public static void main(String[] args)
{
int test1, test2;
Scanner scan = new Scanner (System.in);

Student student1 = new Student("Mary");
//create student2, "Mike"
Student student2 = new Student("Mike");

//input grades for Mary
System.out.println("Enter test 1 score for Mary: ");
student1.inputGrades(scan);

//print average for Mary
System.out.println("Mary's average is: " + student1.getAverage());

System.out.println();

//input grades for Mike
student2.inputGrades(scan);

//print average for Mike
System.out.println("Mike's average is: " + student2.getAverage());

}
}




User is offlineProfile CardPM
+Quote Post

pbl
RE: Program Will Not Run
28 Mar, 2008 - 09:52 AM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,154



Thanked: 205 times
Dream Kudos: 75
My Contributions
QUOTE(scorpionviolinist @ 28 Mar, 2008 - 08:02 AM) *

I can compile the class and the program, but when I try to run Grades.java, it will not run. I don't understand the error message I am getting, and it is a little lengthy.


Post the message it's the best solution.

I cut & paste your code. Works well for me. Just a System.out.println() not neccessary in Grades it is coming from your version version the prompt is done in Student.

CODE

          //input grades for Mary
useless--->     System.out.println("Enter test 1 score for Mary: ");
          student1.inputGrades(scan);    



User is online!Profile CardPM
+Quote Post

scorpionviolinist
RE: Program Will Not Run
28 Mar, 2008 - 03:33 PM
Post #3

New D.I.C Head
*

Joined: 29 Feb, 2008
Posts: 36

Thank you... I figured it out.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:47PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month