Hello I am very new to Java and I really don't know exactly what I am doing. I know a little bit of other programming languages so I'm trying my best to figure it out for myself but I am supposed to:
Write a Java Application which will read a text file of scores from college football games and calculate the average home field advantage for that data.
import java.io.*;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class HomeField
{
public static void main(String [] args)
{
String fileName;
File inFile;
Scanner kbd, input = null;
String line;
int LineCount = 0;
int total = 0;
//Create scanner object for keyboard input
kbd = new Scanner(System.in);
//Get the filename.
System.out.print("Enter a filename: ");
fileName = kbd.nextLine();
//Open the file.
inFile = new File(fileName);
try {
input = new Scanner(inFile);
} catch (FileNotFoundException ex) {
Logger.getLogger(HomeField.class.getName()).log(Level.SEVERE, null, ex);
}
while(input.hasNextLine())
{
// read a line from text
line=input.nextLine();
// increment line counter
LineCount++;
// pull off the visting team score from col 39-42 (use substring(), trim(), parseInt()
String vscore = line.substring(38,4);
vscore=vscore.trim();
int vnum = Integer.parseInt(vscore);
// pull off the home team score from col 71-74
String hscore=line.substring(70,4);
hscore=hscore.trim();
int hnum=Integer.parseInt(hscore);
// add the difference (home - vistor) to
total=hnum-vnum;
total +=total;
}
// compute average
double average=total/LineCount;
// print out the average with an appropriate label
System.out.println("The average is: " + average);
}
}
The error that I'm getting is
java.lang.NoClassDefFoundError: HomeField/HomeField
Caused by: java.lang.ClassNotFoundException: HomeField.HomeField
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: HomeField.HomeField. Program will exit.
Exception in thread "main" Java Result: 1
Please help if you can.