Thread: Compile Trouble
View Single Post
  #1 (permalink)  
Old 04-17-2008, 09:21 AM
adelgado0723 adelgado0723 is offline
Member
 
Join Date: Apr 2008
Posts: 6
adelgado0723 is on a distinguished road
Compile Trouble
netbeans says that it won't compile because of the GetData commands. Please help tell me why it won't run.
Code:
public class Student { private String id, firstname, lastname; Student(String i, String f, String l) { id = i; firstname = f; lastname = l; } String getid() { return id; } String getfirstname() { return firstname; } String getlastname() { return lastname; } }
Code:
import java.util.ArrayList; public class Admissions { Student student; ArrayList<Student> list; int index; boolean found; //2a Admissions() { list = new ArrayList<Student>(); } //2b void add(Student s) { list.add(s); } //2c int size() { return list.size(); } //2d boolean empty() { return list.isEmpty(); } Student get(int i) { return list.get(i); } //2e void search(String id) { int i = 0; int length = list.size(); while (i < length && !found) { student = list.get(i); if (student.getid().equalsIgnoreCase(id)) { found = true; } else { i++; } } index = i; } //2f Student remove(int i) { return list.remove(i); } int getIndex() { return index; } Student getStudent() { return student; } boolean inList() { return found; } ArrayList getList() { return list; } }
Code:
import javax.swing.JOptionPane; import java.util.ArrayList; import javax.swing.JTextArea; import javax.swing.JScrollPane; class Registration { public static void main(String[] arg) { boolean done = false; final String menu = "1. Add Student \n2. Drop Student \n3. Print Report\n4. Exit"; Admissions adm = new Admissions(); Admissions drop = new Admissions(); while (!done) { int option = GetData.getInt(menu); switch (option) { case 1: String last = GetData.getWord("Enter Lastname"); String first = GetData.getWord("Enter Firstname"); String id = GetData.getWord("Enter id number"); Student student = new Student(last, first, id); adm.add(student); break; case 2: if (!adm.empty()) { id = GetData.getWord("Enter id number"); adm.search(id); if (!adm.inList()) { id = "ID number " + id; JOptionPane.showMessageDialog(null, "student not registered", "Registration", JOptionPane.INFORMATION_MESSAGE); } else { int index = adm.getIndex(); Student s = (Student) adm.remove(index); drop.add(s); } } else { JOptionPane.showMessageDialog(null, "List is empty", "Registration", JOptionPane.INFORMATION_MESSAGE); } break; case 3: ArrayList list = adm.getList(); String str = "Students who are registered\n" + report(list); JTextArea text = new JTextArea(str, 10, 30); JScrollPane pane = new JScrollPane(text); display(pane, "Report", JOptionPane.INFORMATION_MESSAGE); break; case 4: display("Done!!!", "Terminating Admission", JOptionPane.WARNING_MESSAGE); done = true; break; default: display("", "Wrong option", JOptionPane.ERROR_MESSAGE); break; } } } static String report(ArrayList list) { int length = list.size(); String str = ""; for (int i = 0; i < length; i++) { Student s = (Student) list.get(i); str = str + s.getid() + " " + s.getfirstname() + "\n"; } return str; } static void display(String info, String heading, int type) { JOptionPane.showMessageDialog(null, info, heading, type); } static void display(JScrollPane pane, String heading, int type) { JOptionPane.showMessageDialog(null, pane, heading, type); } }
Reply With Quote
Sponsored Links