初学者的问题 我写了三个程序 如何运行
程序一 StudentBody.java
public class StudentBody
{
//-----------------------------------------------------------------
// Creates some Address and Student objects and prints them.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Address school = new Address ("800 Lancaster Ave.", "Villanova",
"PA", 19085);
Address jHome = new Address ("21 Jump Street", "Lynchburg",
"VA", 24551);
Student john = new Student ("John", "Smith", jHome, school, "1", 70, "2", 67, "3", 81);
Address mHome = new Address ("123 Main Street", "Euclid", "OH",
44132);
Student marsha = new Student ("Marsha", "Jones", mHome, school, "1", 70, "2", 67, "3", 81);
Address BHome = new Address ("55 Main Road", "Hobart", "TAS",
7000);
Student Baker = new Student ("Jane", "Baker", BHome, school);
System.out.println (john);
System.out.println ();
System.out.println (marsha);
System.out.println ();
System.out.println (Baker);
}
}
程序二 Student.java
public class Student
{
private String firstName, lastName;
private Address homeAddress, schoolAddress;
private int testscore1, testscore2, testscore3, scoreval, averagescore;
//-----------------------------------------------------------------
// Sets up this Student object with the specified initial values.
//-----------------------------------------------------------------
public Student (String first, String last, Address home,
Address school,String test1, int tests1,String test2, int tests2,String test3, int tests3)
{
firstName = first;
lastName = last;
homeAddress = home;
schoolAddress = school;
testscore1=0;
testscore2=0;
testscore3=0;
getTestScore(test1, tests1);
getTestScore(test2, tests2);
getTestScore(test3, tests3);
average();
}
public String getTestScore (String testnum, int testscore)
{
if ((testscore<0) || (testscore>100))
{
scoreval=0;
}
else{
scoreval=testscore;
}
if (testnum.equals("1"))
{
testscore1=scoreval;
}
else{
if (testnum.equals("2"))
{
testscore2=scoreval;
}
else{
if (testnum.equals("3"))
{
testscore3=scoreval;
}
}
}
}
public String average ( )
{
averagescore=(testscore1+testscore2+testscore3)/3;
}
//-----------------------------------------------------------------
// Returns this Student object as a string.
//-----------------------------------------------------------------
public String toString()
{
String result;
result = firstName + " " + lastName + "\n";
result += "Home Address:\n" + homeAddress + "\n";
result += "School Address:\n" + schoolAddress + "\n";
result += "For Test 1: record a score of " + testscore1 + "\n";
result += "For Test 2: record a score of " + testscore2 + "\n";
result += "For Test 3: record a score of " + testscore3 + "\n";
result += "The average test score of " + averagescore;
return result;
}
}
程序三 Address.java
public class Address
{
private String streetAddress, city, state;
private long zipCode;
//-----------------------------------------------------------------
// Sets up this Address object with the specified data.
//-----------------------------------------------------------------
public Address (String street, String town, String st, long zip)
{
streetAddress = street;
city = town;
state = st;
zipCode = zip;
}
//-----------------------------------------------------------------
// Returns this Address object as a string.
//-----------------------------------------------------------------
public String toString()
{
String result;
result = streetAddress + "\n";
result += city + ", " + state + " " + zipCode;
return result;
}
}
如何测试我写得有没有问题 怎么运行啊 我已经装了JDK1.4