S
SpeedRunner
Guest
I've tried everything I could but I can't get line 128 to work for ANYTHING.
I'm well aware that the variable needs to be sent with the method call... I just cannot figure out a good variable to put in there. The only thing that makes sense is a value, not a variable! I cannot edit anything above the Roster class, by the way.
Code:
C:\Documents and Settings\Marshall\My Documents\My Downloads\RosterTest.java:128: unexpected type
required: variable
found : value
prev.setNext(cur) = cur.getNext();
^
1 error
Tool completed with exit code 1
Code:
import javax.swing.*;
public class RosterTest
{
public static void main(String[] args)
{
String input;
Roster myRoster = new Roster();
do
{
input = menu();
if(input == null || input.equalsIgnoreCase("q"))
{
JOptionPane.showMessageDialog(null,"Goodbye!");
}
else if(input.equalsIgnoreCase("a"))
{
doAdd(myRoster);
}
else if(input.equalsIgnoreCase("f"))
{
doFind(myRoster);
}
else if(input.equalsIgnoreCase("r"))
{
doRemove(myRoster);
}
else if(input.equalsIgnoreCase("l"))
{
JOptionPane.showMessageDialog(null,myRoster);
}
else
{
JOptionPane.showMessageDialog(null,"Invalid - try again!");
}
}while(input != null && !input.equalsIgnoreCase("q"));
System.exit(0);
}
public static String menu()
{
String s = "MENU\na - add\nf - find\nr - remove"
+ "\nl - list\nq - quit\nEnter a letter:";
return JOptionPane.showInputDialog(s);
}
public static void doAdd(Roster myRoster)
{
String name = JOptionPane.showInputDialog(
"Enter student name:");
int number = Integer.parseInt(JOptionPane
.showInputDialog("Enter student number:"));
double gpa = Double.parseDouble(JOptionPane
.showInputDialog("Enter student gpa:"));
boolean added = myRoster.add(new Student(name,number,gpa));
if(!added)
{
JOptionPane.showMessageDialog(null,"Student with number " +
number + " already exists!");
}
}
public static void doFind(Roster myRoster)
{
int number = Integer.parseInt(JOptionPane
.showInputDialog("Enter student number:"));
Student foundStu = myRoster.find(number);
if(foundStu == null)
{
JOptionPane.showMessageDialog(null,"No student with number "
+ number + "!");
}
else
{
JOptionPane.showMessageDialog(null,foundStu);
}
}
public static void doRemove(Roster myRoster)
{
int number = Integer.parseInt(JOptionPane
.showInputDialog("Enter student number:"));
Student removedStu = myRoster.remove(number);
if(removedStu == null)
{
JOptionPane.showMessageDialog(null,"No student with number "
+ number);
}
else
{
JOptionPane.showMessageDialog(null,"Removed student: " + removedStu);
}
}
}
class Roster
{
private Student head;
public Roster()
{
}
public Student find(int toFind)
{
Student cur = head;
while(cur != null)
{
if(toFind == cur.getNumber())
{
return cur;
}
cur = cur.getNext();
}
return null;
}
public Student remove(int toKill)
{
Student prev = null;
Student cur = head;
while(cur != null)
{
if(cur.getNumber() == toKill)
{
prev.setNext(cur) = cur.getNext();
}
prev = cur;
cur.getNext();
}
return null;
}
public boolean add(Student addStu)
{
Student prev = null;
Student cur = head;
while(cur != null && addStu.getNumber() < cur.getNumber())
{
prev = cur;
cur.getNext();
}
addStu = cur;
prev = addStu;
return false;
}
public String toString()
{
return null;
}
}
class Student
{
private String name;
private int number;
private double gpa;
private Student next;
public Student(String nam, int num, double g)
{
name = nam;
number = num;
gpa = g;
}
public Student getNext()
{
return next;
}
public int getNumber()
{
return number;
}
public void setNext(Student n)
{
next = n;
}
public String toString()
{
return(name + number + gpa);
}
}
I'm well aware that the variable needs to be sent with the method call... I just cannot figure out a good variable to put in there. The only thing that makes sense is a value, not a variable! I cannot edit anything above the Roster class, by the way.