|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

07-24-2007, 02:25 AM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 40
|
|
|
Error: no class definition found
Hi, I have a program but I am having a problem getting it to run (it compiled fine).
Its error is that there is no class definition found. I really don't know what that means or how to fix it.
Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?
class Student
{
private String firstName;
private String lastName;
private Address homeAddress;
private Address schoolAddress;
private int test1;
private int test2;
private int test3;
public Student (String first, String last, Address home, Address school)
{
lastName=last;
firstName=first;
homeAddress=home;
schoolAddress=school;
test1=0;
test2=0;
test3=0;
}
public void setTestScore (int testNumber, int testScore)
{
if (testNumber == 1)
test1 = testScore;
else if (testNumber == 2)
test2 = testScore;
else
test3 = testScore;
}
public int getTestScore(int testNumber)
{
if (testNumber == 1)
return test1;
else if (testNumber == 2)
return test2;
else
return test3;
}
public double getAverage()
{
return (test1 + test2 + test3)/3;
}
public String toString()
{
String result = firstName +"\n"+ lastName +"\n"+
"HomeAddress: "+ homeAddress + "\n"+
"schoolAddress: "+ schoolAddress + "\n"+
"test1: " + "test 1" + "\n"+
"test2: " + "test 2" + "\n"+
"test3: " + "test 3" + "\n"+
"average: " +this.getAverage()+"\n";
return result;
}
}
class Course
{
static int numberStudent = 0;
String title;
Student student1;
Student student2;
Student student3;
Student student4;
Student student5;
public Course(String courseTitle)
{
title=courseTitle;
}
public void addStudent(String first, String last, Address home, Address school)
{
switch(numberStudent)
{
case 0: student1 = new Student(first,last,home,school);
case 1: student2 = new Student(first,last,home,school);break;
case 2: student3 = new Student(first,last,home,school);break;
case 3: student4 = new Student(first,last,home,school);break;
case 4: student5 = new Student(first,last,home,school);break;
default: System.out.println("No More students allowed in the class");
}
numberStudent++;
}
public String toString()
{
String results="";
results += student1.toString () +"n";
results += student2.toString () +"n";
results += student3.toString () +"n";
results += student4.toString () +"n";
results += student5.toString () +"n";
return results;
}
class Address
{
private String streetAddress;
private String city;
private String state;
private long zipCode;
public Address(String stAddress,String cityValue,String stateValue,long zip)
{
streetAddress = stAddress;
city = cityValue;
state = stateValue;
zipCode = zip;
}
}
Thanks
|
|

07-26-2007, 11:56 PM
|
|
Member
|
|
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
|
|
|
Hey I'm a beginning programmer, but it seems like the test score variables were not initialized as field varialbes, therefore when initialized in one method, they are set only for that method.
(i.e. you never initialized test 1-3 to 0 in your second method, and you never set the value for testNumber.)
That's what I think, you have a bunch of variables (i didn't exactly know where you were goin with this, so if you tell me what you're trying to do, I could perhaps help you out
|
|

07-27-2007, 12:17 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 130
|
|
|
No class definition found means that either ur bin directory haven't been put in the environment variable, u put the wrong input when u run it ex: java student, using lowercase, or missing classpath
Btw, one other possibilities are the access modifier, though, seen from ur code, seems like this isn't supposed to be the main class is it not?
If, just if, this is supposed to be a main class, the error might occur brcause u didn't put a public access for the class, default modifier, like the one ur using, are only usable in subclasses within the directory or outside right?
So, if u wanna run it from the outside, ex: cmd, it'll deny the request
Either u put the class public with a main method, or create another class that uses this class
|
|

07-27-2007, 01:16 PM
|
|
Member
|
|
Join Date: Jul 2007
Posts: 10
|
|
Originally Posted by toby
Hi, I have a program but I am having a problem getting it to run (it compiled fine).
Its error is that there is no class definition found. I really don't know what that means or how to fix it.
Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?
class Student
{
private String firstName;
private String lastName;
private Address homeAddress;
private Address schoolAddress;
private int test1;
private int test2;
private int test3;
public Student (String first, String last, Address home, Address school)
{
lastName=last;
firstName=first;
homeAddress=home;
schoolAddress=school;
test1=0;
test2=0;
test3=0;
}
public void setTestScore (int testNumber, int testScore)
{
if (testNumber == 1)
test1 = testScore;
else if (testNumber == 2)
test2 = testScore;
else
test3 = testScore;
}
public int getTestScore(int testNumber)
{
if (testNumber == 1)
return test1;
else if (testNumber == 2)
return test2;
else
return test3;
}
public double getAverage()
{
return (test1 + test2 + test3)/3;
}
public String toString()
{
String result = firstName +"\n"+ lastName +"\n"+
"HomeAddress: "+ homeAddress + "\n"+
"schoolAddress: "+ schoolAddress + "\n"+
"test1: " + "test 1" + "\n"+
"test2: " + "test 2" + "\n"+
"test3: " + "test 3" + "\n"+
"average: " +this.getAverage()+"\n";
return result;
}
}
class Course
{
static int numberStudent = 0;
String title;
Student student1;
Student student2;
Student student3;
Student student4;
Student student5;
public Course(String courseTitle)
{
title=courseTitle;
}
public void addStudent(String first, String last, Address home, Address school)
{
switch(numberStudent)
{
case 0: student1 = new Student(first,last,home,school);
case 1: student2 = new Student(first,last,home,school);break;
case 2: student3 = new Student(first,last,home,school);break;
case 3: student4 = new Student(first,last,home,school);break;
case 4: student5 = new Student(first,last,home,school);break;
default: System.out.println("No More students allowed in the class");
}
numberStudent++;
}
public String toString()
{
String results="";
results += student1.toString () +"n";
results += student2.toString () +"n";
results += student3.toString () +"n";
results += student4.toString () +"n";
results += student5.toString () +"n";
return results;
}
class Address
{
private String streetAddress;
private String city;
private String state;
private long zipCode;
public Address(String stAddress,String cityValue,String stateValue,long zip)
{
streetAddress = stAddress;
city = cityValue;
state = stateValue;
zipCode = zip;
}
}
Thanks
hi
do one thing copy this program and again past on new
window and then save it with same name
then it will work
|
|

07-27-2007, 08:01 PM
|
|
Member
|
|
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
|
|
|
haha thanks, I actually learned something
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|