The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Programming

1 reply on 1 page. Most recent reply: Nov 21, 2002 9:56 PM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Ian Andrew

Posts: 3
Nickname: sunkey
Registered: Nov, 2002

Java Programming Posted: Nov 15, 2002 7:43 AM
Reply to this message Reply
Advertisement
Below is a lab programm to be submitted by Nov. 22, 02:

Write a program that will model a University. Write a class to model a Student, each student has a name and an address. Implement a method called deplayStudent that displays the information of a student in a window. Use the static method showInputDialog in the class JOptionPane, found in the javax.swing package. Each University has a list of Students that that are enrolled. Using an array to model the list of Students, implement a University class that has 50 students enrolled. Add to your university class, a method displayAllStudents that will call the displayStudent method for all the students enrolled.

I HAVE TRIED TO WRITE THE PROGRAM MYSELF BUT GETTING ERRORS
THAT I CANNOT DEBUG. I AM NOT SURE HOW IMPLEMENT THE SOLUTION. I AM THERFORE SEEKING ASSISTANT IN COMPLETING IT IN TIME TO BE HANDED IN.

HERE WHAT I TRIED TO DO:

/* This class models the Student Object. It takes as
input two Strings the name and the address and
constructs a Student Object.
*/

import javax.swing.*;

public class Student
{
String student_name;
String student_address;

public Student(String name, String address)
{
this.student_name = name;
this.student_address = address;
}
public void displayStudent()
{
JOptionPane.showMessageDialog(null, "Name :" +
student_name + "/n" + "Address : " +
student_address);
}

public void AddStudent(Student st)
{
student_list[next_student++];
}

} // End class Student

===========================================================

* Class to model the University */

public class University
{
Student [] student_list = new Student[50];
int next_index = 0 ;

public void displayAllStudents()
{
for (int st_pos = 0; st_pos <
student_list.length; st_pos++)

student_list[st_pos].displayStudent();
}

public static void main(String [] args)
{
String inputname, inputaddress;
int counter = 0;

do
{
TextIO.put("Student Name : ");
inputname = TextIO.getlnString();

TextIO.put("\n\n Student Address : ");
inputaddress = TextIO.getlnString();

student_info[counter] = new Student
(inputname, inputaddress);

displayStudent();

TextIO.put("\n Enter Another Student Y/N ? ");
counter++;

} while ( counter < 50 || TextIO.getlnBoolean() );


TextIO.putln("\n\n\nOKcounter Student'S' were
entered. Goodbye.");

displayAllStudent();

}

}


Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Java Programming Posted: Nov 21, 2002 9:56 PM
Reply to this message Reply
I may be late helping you here, but this sticks out

public void AddStudent(Student st)
{
student_list[next_student++];
}


You're not adding the student into the array. Try ..

student_list[next_student++] = st;

Ray

Flat View: This topic has 1 reply on 1 page
Topic: Problem with Sending and getting to a class Previous Topic   Next Topic Topic: JAVA SOURCE FILE ANALYZER USING JTREE!!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use