5 Replies - 29661 Views - Last Post: 28 September 2008 - 09:21 AM Rate Topic: -----

#1 mikesmith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

Test Score Average Program

Post icon  Posted 28 September 2008 - 08:15 AM

Hello all fellow java programmers!!

I am a new student to Java and I am having some issues with a very basic beginner program;

The goal of the program is to ask the user for 5 test scores, then the program is supposed to
print out the average of the test scores, I am getting a error I dont understand when I compile it:

Here is my code:


/*	Programmer:	Micheal W. Smith
	Date:		September 27, 2008
	Program:	Code a Java program that allows the user to enter
				five test scores and outputs the average
*/

import java.util.Scanner; //allows for user to enter input into the program ( I think :+ /)

public class TestScores
{
	public static void main (String [] args);

	{
		Scanner keyboard = new Scanner(System.in);

		//Variables for Program

		double TestScore1 = 0.0;
		double TestScore2 = 0.0;
		double TestScore3 = 0.0;
		double TestScore4 = 0.0;
		double TestScore5 = 0.0;
		double averageScore;


		//Prompts for user input

		System.out.println("Please enter Test Score 1: ");

		System.out.println("Please enter Test Score 2: ");

		System.out.println("Please enter Test Score 3: ");

		System.out.println("Please enter Test Score 4: ");

		System.out.println("Please enter Test Score 5: ");

		System.out.println("Your average is: ");
		averageScore = (TestScore1 + TestScore2 + TestScore3
		+ TestScore4 + TestScore5 / 5);
	 }

}




The error I keep getting when I compile it is:

c:\source\TestScores.java: 11 missing method body, or declare abstract
public static void main (String [] args);
1 error
compiled with exit code 1

Im at a loss as to what the heck im doing wrong, the syntax for public static main void (String [] args) is correct
as far as I know, any input as to what im doing wrong would be greatly appricated.

Is This A Good Question/Topic? 0
  • +

Replies To: Test Score Average Program

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,991
  • Joined: 20-September 08

Re: Test Score Average Program

Posted 28 September 2008 - 08:20 AM

You're not reading anything. You need, e.g.

System.out.println("Please enter Test Score 1: ");
TestScore1 = Double.parseDouble(keyboard.nextLine());


Was This Post Helpful? 1
  • +
  • -

#3 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1199
  • View blog
  • Posts: 7,308
  • Joined: 07-September 06

Re: Test Score Average Program

Posted 28 September 2008 - 08:22 AM

That error is referring to this:

public static void main (String [] args);


Notice there is a semi-colon after your declaration, that means that it is the end of that portion of the code, yet you never even do anything with it, then on the next line you start a function (method), but there is no method name so it can't be started and it just blows up.

Try changing it to this:

public static void main (String [] args)


Note - No semi-colon.

Hope that helps.
Was This Post Helpful? 1
  • +
  • -

#4 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: Test Score Average Program

Posted 28 September 2008 - 08:47 AM

Also, try putting your test scores in brackets. So for example
((TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5)/5)

Was This Post Helpful? 0
  • +
  • -

#5 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: Test Score Average Program

Posted 28 September 2008 - 08:56 AM

Here is what it's supposed to look like with the Scanner class. If you need to use JOptionPane then it can be incorporated into it as well.
import java.util.Scanner;

public class AverageTestScore 
{
	public static void main(String[] args)
	{
		//create the variables
		int TestScore1;
		int TestScore2;
		int TestScore3;
		int TestScore4;
		int TestScore5;
		float AverageScore;
		
		//create keyboard for input
		Scanner Keyboard = new Scanner(System.in);
		
		//Ask the user for the 5 test scores
		System.out.println("Please enter test score 1");
		TestScore1 = Keyboard.nextInt();
		
		System.out.println("Please enter test score 2");
		TestScore2 = Keyboard.nextInt();
		
		System.out.println("Please enter test score 3");
		TestScore3 = Keyboard.nextInt();
		
		System.out.println("Please enter test score 4");
		TestScore4 = Keyboard.nextInt();
		
		System.out.println("Please enter test score 5");
		TestScore5 = Keyboard.nextInt();
		
		//Calculate the average score for the tests
		AverageScore = ((TestScore1 + TestScore2 + TestScore3 + TestScore4 + TestScore5)/5);
		
		//Display Average test Score
		System.out.println("The average score of the 5 tests is " + AverageScore);
	}

}

Was This Post Helpful? 1
  • +
  • -

#6 mikesmith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

Re: Test Score Average Program

Posted 28 September 2008 - 09:21 AM

I would like to thank all of you who took the time and effort to read my post and respond to it. Your posts greatly helped me understand a bit more of the basic java functions for this program and will help me with future coding programs. Thanx again!!! :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1