craigtb
04-04-2007, 10:37 PM
Ok once again with the same program. I was trying to run it jsut to see if it printed out correctly. but it gave me some wierd error. ill post all files that are needed and the error im getting.
import java.util.Scanner;
class Project8Driver
{
static int age, id;
static double gpa;
static String schoolName, name;
static Scanner scan = new Scanner(System.in);
static int userChoice = 1;
static int counter = 1;
static Student[] ListOfStudents = new Student[20];
final static int LIMIT = 14;
static int[] activity = new int[LIMIT];
static int[] exercise = new int[LIMIT];
static int[] project = new int[LIMIT];
public static void main(String[]args)
{
// gather general info
/* System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();*/
//int userChoice = 1;
while (userChoice != 0)
{
menu();
userChoice = scan.nextInt();
menuSwitch(userChoice);
}
}
public static void menuSwitch(int choice)
{
int num;
switch(choice)
{
case 4:
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.println("Please enter your expected graduation year");
int graduationYear = scan.nextInt();
ListOfStudents[counter] = new MiddleSchool(name, age, schoolName, id, gpa, graduationYear);
counter++;
break;
case 3:
/*int gradYear, numOfCreditsRemaining, satScore, apCredits;
System.out.print("Please enter your expected graduation year: ");
gradYear = scan.nextInt();
System.out.print("Please enter the number of credits remaining for you to graduate: ");
numOfCreditsRemaining = scan.nextInt();
System.out.print("Please enter your SAT score: ");
satScore = scan.nextInt();
System.out.print("Please enter your number of AP credits: ");
apCredits = scan.nextInt(); */
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.print("What year do you plan to graduate? ");
int gradYear = scan.nextInt();
System.out.print("How many credits do you need to aquire before you can graduate? ");
int credLeft = scan.nextInt();
System.out.print("What did you score on the SAT? ");
int SAT = scan.nextInt();
System.out.print("How many AP credits do you have? ");
int apCred = scan.nextInt();
ListOfStudents[counter] = new HighSchool(name, age, schoolName, id, gpa, gradYear, credLeft, SAT, apCred);
counter++;
case 1:
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.print("What is your current major? ");
String major = scan.next();
System.out.print("What is your current minor? ");
String minor = scan.next();
boolean time;
System.out.print("Are you a full time or part time student? (1 - full time, 2 - part time) ");
int pTime = scan.nextInt();
if (pTime == 1)
time = true;
else
time = false;
System.out.print("Please enter your exam 1 grade: ");
int examOne = scan.nextInt();
System.out.print("Please enter your exam 2 grade: ");
int examTwo = scan.nextInt();
// create for loop to gather grades and put them in an array
for (int i = 1; i <= 14; i++)
{
System.out.print("Please enter Activity grade for Activity " + i +" : ");
activity[i-1] = scan.nextInt();
}
for (int j = 1; j <= 14; j++)
{
System.out.print("Please enter Exercise grade for Exercise "+j+" : ");
exercise[j-1] = scan.nextInt();
}
for (int k = 1; k <= 14; k++)
{
System.out.print("Please enter project grade for Project " + k +" : ");
project[k-1] = scan.nextInt();
}
break;
case 5:
System.out.println(ListOfStudents);
default:
System.out.println("Invalid choice");
}
}
public static void menu()
{
System.out.println("*************");
System.out.println("1: College - Undergraduate");
System.out.println("2: College - Graduate");
System.out.println("3: High School");
System.out.println("4: Middle School");
System.out.println("5: Print");
System.out.print("\nEnter your choice: ");
}
}
class Student
{
String sName, nameSchool;
int age, id;
double gpa;
Student(String sName, int age, int id, String nameSchool, double gpa)
{
this.sName = sName;
this.age = age;
this.id = id;
this.nameSchool = nameSchool;
this.gpa = gpa;
}
public String toString()
{//String s1 = "";
return"Name: "+sName+"\tAge: "+age+"\tID: "+id+"\tSchool's name: "+nameSchool+"\tGPA: "+gpa;
//for(i;i<end of arry)
//{
//s1 += array[i] + " "
}
}
class MiddleSchool extends Student
{
int gradYear1;
public MiddleSchool(String name, int age, String schoolName, int id, double gpa, int gradYear)
{
super(name, age, id, schoolName, gpa);
gradYear1 = gradYear;
}
public String toString()
{
String temp = super.toString();
return temp + gradYear1;
}
}
this is the output i get when i try and print it
"[LStudent;@8965fb"
import java.util.Scanner;
class Project8Driver
{
static int age, id;
static double gpa;
static String schoolName, name;
static Scanner scan = new Scanner(System.in);
static int userChoice = 1;
static int counter = 1;
static Student[] ListOfStudents = new Student[20];
final static int LIMIT = 14;
static int[] activity = new int[LIMIT];
static int[] exercise = new int[LIMIT];
static int[] project = new int[LIMIT];
public static void main(String[]args)
{
// gather general info
/* System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();*/
//int userChoice = 1;
while (userChoice != 0)
{
menu();
userChoice = scan.nextInt();
menuSwitch(userChoice);
}
}
public static void menuSwitch(int choice)
{
int num;
switch(choice)
{
case 4:
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.println("Please enter your expected graduation year");
int graduationYear = scan.nextInt();
ListOfStudents[counter] = new MiddleSchool(name, age, schoolName, id, gpa, graduationYear);
counter++;
break;
case 3:
/*int gradYear, numOfCreditsRemaining, satScore, apCredits;
System.out.print("Please enter your expected graduation year: ");
gradYear = scan.nextInt();
System.out.print("Please enter the number of credits remaining for you to graduate: ");
numOfCreditsRemaining = scan.nextInt();
System.out.print("Please enter your SAT score: ");
satScore = scan.nextInt();
System.out.print("Please enter your number of AP credits: ");
apCredits = scan.nextInt(); */
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.print("What year do you plan to graduate? ");
int gradYear = scan.nextInt();
System.out.print("How many credits do you need to aquire before you can graduate? ");
int credLeft = scan.nextInt();
System.out.print("What did you score on the SAT? ");
int SAT = scan.nextInt();
System.out.print("How many AP credits do you have? ");
int apCred = scan.nextInt();
ListOfStudents[counter] = new HighSchool(name, age, schoolName, id, gpa, gradYear, credLeft, SAT, apCred);
counter++;
case 1:
System.out.print("Please enter your name: ");
name = scan.next();
System.out.print("Please enter your age: ");
age = scan.nextInt();
System.out.print("Please enter your school's name: ");
schoolName = scan.next();
System.out.print("Please enter your ID: ");
id = scan.nextInt();
System.out.print("Please enter your current GPA: ");
gpa = scan.nextDouble();
System.out.print("What is your current major? ");
String major = scan.next();
System.out.print("What is your current minor? ");
String minor = scan.next();
boolean time;
System.out.print("Are you a full time or part time student? (1 - full time, 2 - part time) ");
int pTime = scan.nextInt();
if (pTime == 1)
time = true;
else
time = false;
System.out.print("Please enter your exam 1 grade: ");
int examOne = scan.nextInt();
System.out.print("Please enter your exam 2 grade: ");
int examTwo = scan.nextInt();
// create for loop to gather grades and put them in an array
for (int i = 1; i <= 14; i++)
{
System.out.print("Please enter Activity grade for Activity " + i +" : ");
activity[i-1] = scan.nextInt();
}
for (int j = 1; j <= 14; j++)
{
System.out.print("Please enter Exercise grade for Exercise "+j+" : ");
exercise[j-1] = scan.nextInt();
}
for (int k = 1; k <= 14; k++)
{
System.out.print("Please enter project grade for Project " + k +" : ");
project[k-1] = scan.nextInt();
}
break;
case 5:
System.out.println(ListOfStudents);
default:
System.out.println("Invalid choice");
}
}
public static void menu()
{
System.out.println("*************");
System.out.println("1: College - Undergraduate");
System.out.println("2: College - Graduate");
System.out.println("3: High School");
System.out.println("4: Middle School");
System.out.println("5: Print");
System.out.print("\nEnter your choice: ");
}
}
class Student
{
String sName, nameSchool;
int age, id;
double gpa;
Student(String sName, int age, int id, String nameSchool, double gpa)
{
this.sName = sName;
this.age = age;
this.id = id;
this.nameSchool = nameSchool;
this.gpa = gpa;
}
public String toString()
{//String s1 = "";
return"Name: "+sName+"\tAge: "+age+"\tID: "+id+"\tSchool's name: "+nameSchool+"\tGPA: "+gpa;
//for(i;i<end of arry)
//{
//s1 += array[i] + " "
}
}
class MiddleSchool extends Student
{
int gradYear1;
public MiddleSchool(String name, int age, String schoolName, int id, double gpa, int gradYear)
{
super(name, age, id, schoolName, gpa);
gradYear1 = gradYear;
}
public String toString()
{
String temp = super.toString();
return temp + gradYear1;
}
}
this is the output i get when i try and print it
"[LStudent;@8965fb"