Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2008, 09:21 AM
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); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-17-2008, 09:32 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 508
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Can you post the reported exceptions?

Be specific....

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-18-2008, 06:37 PM
Member
 
Join Date: Apr 2008
Posts: 26
fireball2008 is on a distinguished road
Send a message via AIM to fireball2008
First of all what is Getdata and where is this thing come from,
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-18-2008, 08:56 PM
bobleny's Avatar
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
Are there any more classes? With what you gave us, I see 5 error in Registration; all pertaining to the GetData object.

I don't know what it is that you are trying to do, but I do know, that you are calling on an object, GetData, that doesn't exist. So, you will have to create it.

If your simply trying to ask the user to enter in the last name, then you might try:
Code:
String last = JOptionPane.showInputDialog(null, "Enter Lastname");
Based on the information you provided, that is the best answer I can give you.

Good luck!
__________________
--
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
--
Cheer up, the worst has yet to come...
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-20-2008, 07:26 PM
Member
 
Join Date: Apr 2008
Posts: 1
Christian121 is on a distinguished road
^If done that way, how would you alternate the code "int option = GetData.getInt(menu);" ?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-21-2008, 03:02 AM
bobleny's Avatar
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
Simple, you use the Integer.parseInt() method.
Code:
String stroption = JOptionPane.showInputDialog(null, menu, "Choose an Option:", JOptionPane.QUESTION_MESSAGE); int option = Integer.parseInt(stroption);
If you really want to get fancy to avoid any error, use a try catch statement:
Code:
String stroption = JOptionPane.showInputDialog(null, menu, "Choose an Option:", JOptionPane.QUESTION_MESSAGE); int option; try { option = Integer.parseInt(stroption); } catch(Exception E) { option = 0; }
And life is good....
__________________
--
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
--
Cheer up, the worst has yet to come...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling trouble capacitator CLDC and MIDP 4 06-10-2008 11:12 PM
[SOLVED] trouble learnig swing monir6464 AWT / Swing 5 05-08-2008 07:01 AM
trouble with program jimJohnson New To Java 1 04-03-2008 10:29 AM
Having trouble with array ice22 New To Java 3 11-13-2007 04:06 AM
JTree trouble Alantie Vala AWT / Swing 3 08-01-2007 12:12 AM


All times are GMT +3. The time now is 11:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org