473,545 Members | 4,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help!! I'm stuck with java code...API not helping.

2 New Member
hi, I'm working on an exercise, i did a lot of work already and i just can't figure where I'm going wrong, this is what I'm trying to achieve

Sample IO
*************** *************** *************** *************** *************** ****
Expand|Select|Wrap|Line Numbers
  1. Welcome to PeopleSoft 2
  2. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  3. a
  4. Enter the student number
  5. MSXMIC001
  6. Enter the name
  7. Mickey Mouse
  8. Done
  9. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  10. a
  11. Enter the student number
  12. CHPALV001
  13. Enter the name
  14. Alvin the Chipmunk
  15. Done
  16. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  17. a
  18. Enter the student number
  19. DCKDON002
  20. Enter the name
  21. Donald Duck
  22. Done
  23. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  24. l
  25. Student: DCKDON002, Donald Duck
  26. Student: CHPALV001, Alvin the Chipmunk
  27. Student: MSXMIC001, Mickey Mouse
  28. Done
  29. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  30. s
  31. Done
  32. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  33. l
  34. Student: CHPALV001, Alvin the Chipmunk
  35. Student: DCKDON002, Donald Duck
  36. Student: MSXMIC001, Mickey Mouse
  37. Done
  38. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  39. d
  40. Enter the student number
  41. DCKDON002
  42. Done
  43. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  44. l
  45. Student: CHPALV001, Alvin the Chipmunk
  46. Student: MSXMIC001, Mickey Mouse
  47. Done
  48. MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
  49. x
*************** *************** *************** *************** ***
and this is my code so far, that won't work....
*************** *************** *************** *************** *************** *************** *
Expand|Select|Wrap|Line Numbers
  1. import java.util.NoSuchElementException;
  2. import java.util.Scanner;
  3.  
  4. public class LinkedList2
  5. {    private class Node
  6.     {
  7.             private String name;
  8.             private String stuName;
  9.             private Node link;
  10.  
  11.  
  12.     public Node()
  13.     {
  14.         link = null;
  15.         name = null;
  16.         stuName = null;
  17.     }
  18.  
  19.     public Node(String newStuName, String newName, Node linkValue)
  20.     {
  21.         setData(newStuName, newName);
  22.         link = linkValue;
  23.     }
  24.     public void setData(String newStuName, String newName)
  25.     {
  26.         name = newName;
  27.         stuName = newStuName;
  28.     }
  29.     public void setLink(Node newLink)
  30.     {
  31.         link = newLink;
  32.     }
  33.     public String getStuName()
  34.     {
  35.         return stuName;
  36.     }
  37.     public String getName()
  38.     {
  39.         return name;
  40.     }
  41.     public Node getLink()
  42.     {
  43.         return link;
  44.     }
  45.     }//end of node inner class
  46.  
  47.     public class List2Iterator//inner class for iterators for linkedlist2
  48.     {    
  49.         private Node position;
  50.         private Node previous;
  51.  
  52.         public List2Iterator()
  53.         {
  54.             position = head;
  55.             previous = null;
  56.         }
  57.         public void restart()
  58.         {
  59.             position = head;
  60.             previous = null;
  61.         }
  62.         public String next()
  63.         {
  64.             if(!hasNext())
  65.                 throw new NoSuchElementException();
  66.             String toReturn = position.stuName;
  67.             previous = position;
  68.             position = position.link;
  69.             return toReturn;
  70.         }
  71.         public boolean hasNext()
  72.         {
  73.             return(position != null);
  74.         }
  75.         public String peek()
  76.         {
  77.             if(!hasNext())
  78.                 throw new IllegalStateException();
  79.                 return position.stuName;
  80.         }
  81.         public void addHare(String newData)
  82.         {
  83.             if(position == null && previous != null)//if at end o list
  84.  
  85.             previous.link = new Node(newData, null);
  86.             else if(position == null || previous == null)
  87.             LinkedList2.this.addToStart(newData);
  88.  
  89.             else{
  90.                 Node temp = new Node(newData, position);
  91.                 previous.link = temp;
  92.                 previous = temp;
  93.             }
  94.         }
  95.         public void changeHare(String newData)
  96.         {
  97.             if(position == null)
  98.                 throw new IllegalStateException();
  99.                 else
  100.                 position.stuName = newData;
  101.         }
  102.         public void delete()
  103.         {
  104.             if(position == null)
  105.                 throw new IllegalStateException();
  106.                 else if(previous == null)
  107.                 {
  108.                     head = head.link;
  109.                     position = head;
  110.                 }
  111.                 else
  112.                 {
  113.                     previous.link = position.link;
  114.                     position = position.link;
  115.                 }
  116.         }
  117.     }
  118.         private Node head;
  119.  
  120.         public List2Iterator iterator()
  121.         {
  122.             return new List2Iterator();
  123.         }
  124.         public LinkedList2()
  125.         {
  126.             head = null;//adds node at the stat of the list with the specified data
  127.         }
  128.         public void addToStart(String itemStuName, String itemName)
  129.         {
  130.         head = new Node1(itemStuName, itemName, head);
  131.         }
  132.         }
  133.         public boolean deleteHeadNode()
  134.         {
  135.             if(head != null){
  136.  
  137.                 head = head.link;
  138.                 return true;
  139.             }
  140.             else 
  141.             return false;
  142.         }
  143.         /*public int size()//return number of nodes in the list
  144.         {
  145.             int count = 0;
  146.             Node position = head;
  147.             while(position != null)
  148.             {
  149.                 count++;
  150.                 position = position.link;
  151.             }
  152.             return count;
  153.         }*/
  154.         public boolean contains(String stuName, String name)
  155.         {
  156.         return (find(stuName, name) != null); 
  157.         }
  158.         private Node find(String target)
  159.         {
  160.             Node position = head;
  161.             String itemAtPosition;
  162.             while (position != null)
  163.             {
  164.                 itemAtPosition = position.stuName;
  165.                 if(itemAtPosition.equals(target))
  166.                     return position;
  167.                     position = position.link;
  168.             }
  169.             return null; //target wan not found
  170.         }
  171.         public void outPutList()
  172.         {
  173.             Node position = head;
  174.             while(position != null);
  175.             {
  176.                 System.out.println(position.stuName);
  177.                 position = position.link;
  178.             }
  179.         }
  180.         public boolean isEmpty()
  181.         {
  182.             return(head == null);
  183.         }
  184.         public void clear()
  185.         {
  186.             head = null;
  187.         }
  188.         public boolean equals(Object otherObject)
  189.         {
  190.             if(otherObject == null)
  191.                 return false;
  192.                 else if(getClass() != otherObject.getClass())
  193.                     return false;
  194.                 else{
  195.                     LinkedList2 otherList = (LinkedList2)otherObject;
  196.                     if(size() != otherList.size())
  197.                         return false;
  198.                         Node position = head;
  199.                         Node otherPosition = otherList.head;
  200.                         while(position != null)
  201.                         {    
  202.                             if((!(position.item.equals(otherPosition.stuName))))
  203.                                 return false;
  204.                             position = position.link;
  205.                             otherPosition = otherPosition.link;
  206.                         }
  207.                         return true;//a mis match was not found
  208.                     }
  209.         }
  210.  
  211.  
  212.         public static void main(String[] args)
  213.         {
  214.             Scanner keyboard = new Scanner(System.in);
  215.  
  216.             LinkedList2 list = new LinkedList2();
  217.             LinkedList2.List2Iterator i = list.iterator();
  218.  
  219.             System.out.println("Welcome to PeopleSoft 2");
  220.  
  221.             int choice = keyboard.nextInt();
  222.             while(choice !== 5)
  223.             {
  224.                 System.out.println("MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it");            
  225.                 switch(choice)
  226.                 {
  227.                     case 1:
  228.                     System.out.println("Enter the student number");
  229.                     stuNum = keyboard.next();
  230.                     System.out.println("Enter the Student name");
  231.                     name = keyboard.next();
  232.                     list.addToStart(studentNum,name);
  233.                     System.out.println("Done");
  234.                     break;
  235.  
  236.                     case 2:
  237.                     System.out.println("Enter student number");
  238.                     stuName = keyboard.next();
  239.                     i.restart();
  240.                     i.next();
  241.                     System.out.println("Will delete the node for; " + i.peek());
  242.                     i.delete();
  243.                     System.out.println("Done");
  244.                     break;
  245.  
  246.                     case 3:
  247.                     System.out.println("list now contains:");
  248.                     i.restart();
  249.                     while(i.hasNext())
  250.                     System.out.println("Student: " + i.next());
  251.                     System.out.println();
  252.                     System.out.println("Done");
  253.                     break;
  254.  
  255.                     case 5:
  256.                     System.exit(0);
  257.                     break;
  258.  
  259.                     default:
  260.                     System.out.println("Error,please check your input again");
  261.                     break;    
  262.                 }
  263.             }        
  264.  
  265.  
  266.  
  267.         }
  268.  
  269.  
  270. }
*************** *************** *************** *************** *************** *************** **
please help me see where I'm going wrong.
Sep 17 '08 #1
3 1743
JosAH
11,448 Recognized Expert MVP
and this is my code so far, that won't work....
What doesn't work? We are not going to do your homework for you but we're
willing to help you to solve any problem; please help us to help you and specify
what doesn't actually work.

kind regards,

Jos
Sep 17 '08 #2
BlueroY
2 New Member
hi again, sorry I did not give enough information,
when i compile, I get about 70 lines of errors saying "enum expected" what i really have trouble with is letting the user enter all the information. I'm also having trouble writing a suitable delete() method....the one in my code is from my textbook example, actualy almost of all the code...all I really need is how do let the user enter all the data and do I need an array for (studentNumber and name)?..I'm a bit frustrated now.
Sep 17 '08 #3
JosAH
11,448 Recognized Expert MVP
If your program doesn't compile you definitely can't run it. Can you show us the
first compiler error diagnostic? (copied verbatim, including the offending line number).

kind regards,

Jos
Sep 17 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2639
by: Charles A. Lackman | last post by:
How do I retrieve a value from an ASP.NET Textbox in Java Script. The following code returns Null, What am I doing wrong? var AName = document.GetElementById("txtName.Value") Changing "Value" to "Text" also returns Null, Also, if I remove "Value" is returned. txtName is a ASPX textbox that the visitor places their name into.
2
1357
by: Gawn | last post by:
Hi I am from Thainald and new to PHP/MySQL. I am doing a news website and I can't do the related news, while I can for latest news. My code for latest news is "SELECT * FROM news WHERE news_id!=$news_id AND cat=$cat ORDER BY news.published DESC". This work OK for latest news. Code for related news is "SELECT * FROM news WHERE...
1
1209
by: capdownlondon | last post by:
Im using the following code to duplicate a record varCnt(retrieved from a combo box on the form) many times, and it only duplicates the record with the fields present on the form for that record. The duplicate fields are and (upto target 5) and then it duplicates the but adds 1 to each duplicate for this field. But if the targets are...
5
1728
by: ri58776 | last post by:
Does anyone have java code of serializing and deserializing graph??? I am using structure typedef struct Node{ struct Node *Left; struct Node *right; inr value; }Node; and function void savegraph(FILE *out,const node *r) which save text format of the graph with node and arcs.
1
2587
by: skippychalmers | last post by:
Hey... new here. Could really use some help with a preg_split i'm trying to run. Basically, I have a string. In it is the tag: ''. Its a sort of bbcode feature I'm adding to a forum. There's one line of code that is key to the operation of the whole thing. It'll be within the tags, and should look like: run (anystring.app) I want to...
8
2233
by: The Bicycling Guitarist | last post by:
I *almost* have a tribute slideshow done for my late pet cat, found dead the same day I finally found a place to rent where I could keep her. There are a few minor errors that I don't know how to fix yet. If anyone could take a look and drop me some hints, I'd be most grateful. I hope I'm not posting this inappropriately or to the wrong...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.