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
*************** *************** *************** *************** *************** **** - Welcome to PeopleSoft 2
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
a
-
Enter the student number
-
MSXMIC001
-
Enter the name
-
Mickey Mouse
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
a
-
Enter the student number
-
CHPALV001
-
Enter the name
-
Alvin the Chipmunk
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
a
-
Enter the student number
-
DCKDON002
-
Enter the name
-
Donald Duck
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
l
-
Student: DCKDON002, Donald Duck
-
Student: CHPALV001, Alvin the Chipmunk
-
Student: MSXMIC001, Mickey Mouse
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
s
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
l
-
Student: CHPALV001, Alvin the Chipmunk
-
Student: DCKDON002, Donald Duck
-
Student: MSXMIC001, Mickey Mouse
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
d
-
Enter the student number
-
DCKDON002
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
l
-
Student: CHPALV001, Alvin the Chipmunk
-
Student: MSXMIC001, Mickey Mouse
-
Done
-
MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it
-
x
*************** *************** *************** *************** ***
and this is my code so far, that won't work....
*************** *************** *************** *************** *************** *************** * - import java.util.NoSuchElementException;
-
import java.util.Scanner;
-
-
public class LinkedList2
-
{ private class Node
-
{
-
private String name;
-
private String stuName;
-
private Node link;
-
-
-
public Node()
-
{
-
link = null;
-
name = null;
-
stuName = null;
-
}
-
-
public Node(String newStuName, String newName, Node linkValue)
-
{
-
setData(newStuName, newName);
-
link = linkValue;
-
}
-
public void setData(String newStuName, String newName)
-
{
-
name = newName;
-
stuName = newStuName;
-
}
-
public void setLink(Node newLink)
-
{
-
link = newLink;
-
}
-
public String getStuName()
-
{
-
return stuName;
-
}
-
public String getName()
-
{
-
return name;
-
}
-
public Node getLink()
-
{
-
return link;
-
}
-
}//end of node inner class
-
-
public class List2Iterator//inner class for iterators for linkedlist2
-
{
-
private Node position;
-
private Node previous;
-
-
public List2Iterator()
-
{
-
position = head;
-
previous = null;
-
}
-
public void restart()
-
{
-
position = head;
-
previous = null;
-
}
-
public String next()
-
{
-
if(!hasNext())
-
throw new NoSuchElementException();
-
String toReturn = position.stuName;
-
previous = position;
-
position = position.link;
-
return toReturn;
-
}
-
public boolean hasNext()
-
{
-
return(position != null);
-
}
-
public String peek()
-
{
-
if(!hasNext())
-
throw new IllegalStateException();
-
return position.stuName;
-
}
-
public void addHare(String newData)
-
{
-
if(position == null && previous != null)//if at end o list
-
-
previous.link = new Node(newData, null);
-
else if(position == null || previous == null)
-
LinkedList2.this.addToStart(newData);
-
-
else{
-
Node temp = new Node(newData, position);
-
previous.link = temp;
-
previous = temp;
-
}
-
}
-
public void changeHare(String newData)
-
{
-
if(position == null)
-
throw new IllegalStateException();
-
else
-
position.stuName = newData;
-
}
-
public void delete()
-
{
-
if(position == null)
-
throw new IllegalStateException();
-
else if(previous == null)
-
{
-
head = head.link;
-
position = head;
-
}
-
else
-
{
-
previous.link = position.link;
-
position = position.link;
-
}
-
}
-
}
-
private Node head;
-
-
public List2Iterator iterator()
-
{
-
return new List2Iterator();
-
}
-
public LinkedList2()
-
{
-
head = null;//adds node at the stat of the list with the specified data
-
}
-
public void addToStart(String itemStuName, String itemName)
-
{
-
head = new Node1(itemStuName, itemName, head);
-
}
-
}
-
public boolean deleteHeadNode()
-
{
-
if(head != null){
-
-
head = head.link;
-
return true;
-
}
-
else
-
return false;
-
}
-
/*public int size()//return number of nodes in the list
-
{
-
int count = 0;
-
Node position = head;
-
while(position != null)
-
{
-
count++;
-
position = position.link;
-
}
-
return count;
-
}*/
-
public boolean contains(String stuName, String name)
-
{
-
return (find(stuName, name) != null);
-
}
-
private Node find(String target)
-
{
-
Node position = head;
-
String itemAtPosition;
-
while (position != null)
-
{
-
itemAtPosition = position.stuName;
-
if(itemAtPosition.equals(target))
-
return position;
-
position = position.link;
-
}
-
return null; //target wan not found
-
}
-
public void outPutList()
-
{
-
Node position = head;
-
while(position != null);
-
{
-
System.out.println(position.stuName);
-
position = position.link;
-
}
-
}
-
public boolean isEmpty()
-
{
-
return(head == null);
-
}
-
public void clear()
-
{
-
head = null;
-
}
-
public boolean equals(Object otherObject)
-
{
-
if(otherObject == null)
-
return false;
-
else if(getClass() != otherObject.getClass())
-
return false;
-
else{
-
LinkedList2 otherList = (LinkedList2)otherObject;
-
if(size() != otherList.size())
-
return false;
-
Node position = head;
-
Node otherPosition = otherList.head;
-
while(position != null)
-
{
-
if((!(position.item.equals(otherPosition.stuName))))
-
return false;
-
position = position.link;
-
otherPosition = otherPosition.link;
-
}
-
return true;//a mis match was not found
-
}
-
}
-
-
-
public static void main(String[] args)
-
{
-
Scanner keyboard = new Scanner(System.in);
-
-
LinkedList2 list = new LinkedList2();
-
LinkedList2.List2Iterator i = list.iterator();
-
-
System.out.println("Welcome to PeopleSoft 2");
-
-
int choice = keyboard.nextInt();
-
while(choice !== 5)
-
{
-
System.out.println("MENU: (A)dd student, (D)elete, (L)ist, (S)ort, e(X)it");
-
switch(choice)
-
{
-
case 1:
-
System.out.println("Enter the student number");
-
stuNum = keyboard.next();
-
System.out.println("Enter the Student name");
-
name = keyboard.next();
-
list.addToStart(studentNum,name);
-
System.out.println("Done");
-
break;
-
-
case 2:
-
System.out.println("Enter student number");
-
stuName = keyboard.next();
-
i.restart();
-
i.next();
-
System.out.println("Will delete the node for; " + i.peek());
-
i.delete();
-
System.out.println("Done");
-
break;
-
-
case 3:
-
System.out.println("list now contains:");
-
i.restart();
-
while(i.hasNext())
-
System.out.println("Student: " + i.next());
-
System.out.println();
-
System.out.println("Done");
-
break;
-
-
case 5:
-
System.exit(0);
-
break;
-
-
default:
-
System.out.println("Error,please check your input again");
-
break;
-
}
-
}
-
-
-
-
}
-
-
-
}
*************** *************** *************** *************** *************** *************** **
please help me see where I'm going wrong.
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
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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...
|
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.
|
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...
| |
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...
|
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...
|
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...
|
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. ...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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
| |