Need Help with new Classes / methods

Hi, I need to create a class called Proposition. It include a Proposition object with 3 variables
Name, Description, Value
This is the constructor I wrote:
private String name;
private String description;
private boolean value;
public Proposition(){
          name = "name";
          description = "description";
          value = false;
}Now I need a method that give values to the 3 variables in the proposition object:
     public Proposition setProp(String line){
          StringTokenizer ST1 = new StringTokenizer(line, ".");
          String ValidLine = ST1.nextToken()+".";
          StringTokenizer ST2 = new StringTokenizer(ValidLine, "=");
          name = CutSpace(ST2.nextToken());
          description = (ST2.nextToken()).trim();
          value = false;
          return name;
          return description;
          return value;
     }An example of String line is: v = we are in Vancouver.
When I run the program, I got error message with the 3 return statements saying found String/Boolean while Proposition is needed. I'm not quite sure how to write the return statements. Can any1 help?
Thx!

Your setProp() method should not be returning anything. After all it is setting not getting. So just declare it as
public void setProp(String line){and remove the return statements.

Similar Messages

  • Need Help with a getText method

    Gday all,
    I need help with a getText method, i need to extract text from a JTextField. Although this text then needs to converted to a double so that i can multiply a number that i have already specified. As you may of guessed that the text i need to extract already will be in a double format.e.g 0.1 or 0.0000004 etc
    Thanks for your help
    ps heres what i have already done its not very good though
    ToBeConverted.getText();
    ( need help here)
    double amount = (and here)
    total = (amount*.621371192);
    Converted.setText("= " + total);

    Double.parseDouble( textField.getText() );

  • Need help with new itouch

    Please bare with me, while I 'try' to explain.
    I have my itunes account linked to my iphone and macbook. I have bought my daughter an itouch for Xmas. Now I have set up a seperate itunes account for her on my other Windows laptop. So she is able to purchase apps without them going and clogging up my itunes... NOW this is the bit i need help with...
    How can i transfer any music i have on my itunes to her itunes? and vice versa?
    Thanks in advance

    Right, I have now gone down the line of setting up a new user on my macbook, her own ID and then with the help of Mr google, I followed the steps of sharing my music, by moving my itunes media folder to a shared folder.
    Now i got my music on her itunes libary but when i did a test download of an app, it wont show in the library. I have even done the 'transfer purchases'. and its still not showing. I am slowing loosing the will to live with it! I really need help.

  • Need help with new 8310

    Just upgraded from earlier blackberry and have two problems I need help with!
    First, in rearranging the icons my browser icon disappeared and I can't get it back even when I use the show all function.  Any ideas?
    Second, unlike my earlier blackberry, messages I sent from my office laptop are not appearing in my messages.  What setting do I need to tweak?  I like my blackberry to show all the messages sent from or received by the laptop.
    Thanks.
    Lauren

    My BB setting was to not hide sent messages, but the problem I think has to do with the settings on syncing with my computer.  Messages I send from the blackberry show up as sent - but I want the BB to match completely with the email on my computer - show every email received and every email sent.  That was how the old BB was set up.  Any ideas on what else to tweak either on the desktop or the BB?  Thanks for your help.

  • Need help with a Class.

    Ok hey guys i got A project for school and i need help. I asked my teacher and he num so yea. here it is
    this is my blog class
    /* Project Name: .java
                 Name:
                Class: Programing 2 #0047-02 Pds 5&6
      Variable List:
                   Info:
    import java.util.Scanner;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class blog
         String date2;
         String user;
         String Entry;
         public void GetInfo(String Iuser,String IEntry)
              DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
              Date date = new Date();
              date2 = dateFormat.format(date);
              user = Iuser;
              Entry = IEntry:
         public void ShowInfo()
              System.out.println(date2 + " " + user + " Said: " + Entry);
    }This is my test class
    /* Project Name: .java
                 Name: Josh
                Class: Programing 2 #0047-02 Pds 5&6
      Variable List:
                   Info:
    import java.util.Scanner;
    public class test
         String user;
         String Entry;
         public static void main (String[] args)
         {     System.out.println("Welcome Please Eneter UserName");
              Scanner kb = new Scanner(System.in);
              user = kb.next();
              System.out.println("Please Enter Your Entry");
              Entry = kb.next();
              blog info = new blog();
              blog.GetInfo(user,Entry);
              blog.ShowInfo();
    }So what is sopost to do in the test it ask user to import user name and entery. It send it to blog Class, then it send it out. Here is my errors
    G:\VOC T2\Java\Chap4\test.java:21: non-static variable user cannot be referenced from a static context
              user = kb.next();
              ^
    G:\VOC T2\Java\Chap4\test.java:25: non-static variable Entry cannot be referenced from a static context
              Entry = kb.next();
              ^
    G:\VOC T2\Java\Chap4\test.java:29: non-static variable user cannot be referenced from a static context
              blog.GetInfo(user,Entry);
                           ^
    G:\VOC T2\Java\Chap4\test.java:29: non-static variable Entry cannot be referenced from a static context
              blog.GetInfo(user,Entry);
                                ^
    G:\VOC T2\Java\Chap4\test.java:29: GetInfo(java.lang.String,java.lang.String,java.lang.String) in blog cannot be applied to (java.lang.String,java.lang.String)
              blog.GetInfo(user,Entry);
                  ^
    G:\VOC T2\Java\Chap4\test.java:31: non-static method ShowInfo() cannot be referenced from a static context
              blog.ShowInfo();
                  ^
    6 errors
    Tool completed with exit code 1 Plez help

    -- "non-static X cannot be referenced from a static context" --
    You get this error because static members don't require an instance of the object to be accessed; they belong to the class. But a non-static member belongs to an instance (an individual object). There's no way for the static method to know which instance's variable to use or method to call, and thus, the compiler happily tells you that you can't access an instance member (non-static) from a class context (static).
    [The Java? Tutorial - Understanding Instance and Class Members|http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html]
    ~

  • NEED HELP WITH USING STATIC METHOD - PLEASE RESPOND ASAP!

    I am trying to set a value on a class using a static method. I have defined a servlet attribute (let's call it myAttribute) on my webserver. I have a serlvet (let's call it myServlet) that has an init() method. I have modified this init() method to retrieve the attribute value (myAttribute). I need to make this attribute value accessible in another class (let's call it myOtherClass), so my question revolves around not knowing how to set this attribute value on my other class using a static method (let's call it setMyStuff()). I want to be able to make a call to the static method setMyStuff() with the value of my servlet attribute. I dont know enough about static member variables and methods. I need to know what to do in my init() method. I need to know what else I need to do in myServlet and also what all I need in the other class as well. I feel like a lot of my problems revolve around not knowing the proper syntax as well.
    Please reply soon!!! Thanks in advance.

    class a
    private static String aa = "";
    public static setVar (String var)
    aa = var;
    class b
    public void init()
    a.aa = "try";
    public static void main(String b[])
    b myB = new b ();
    b.init();
    hope this help;
    bye _drag                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help with JComponent class

    Hi,
    I'm trying to create a class that has all the characteristics of several GUI components such as JButton, JLabel, JRadioButton .... combined into one big class. But when I run the codes, the object of this new class is not visible on a frame like a JButton or a JLabel would be. Someone, please give me some hints. Thanks.
    The ButtonWrapper class extends JButton and the CheckBoxWrapper class extends JCheckBox and they both work without any problems. The GuiWrapper class (listed below) is the class that has the visibility problem when added to a container of a frame.
    import java.awt.*;
    import javax.swing.*;
    public class GuiWrapper extends JComponent{
      public GuiWrapper(String ptype, String p2, String p3) {
         if(ptype.toLowerCase() == "button"){
           ButtonWrapper b = new ButtonWrapper(p2, p3);
         if(ptype.toLowerCase() == "checkbox"){
           CheckBoxWrapper c = new CheckBoxWrapper(p2, p3);
    }

    Okay, so, for starters, I think this is a Really Bad Idea. If your developers can't handle using the API/tutorial to learn how the components work, your project will fail. This UberClass will not help in the long run. It will also almost certainly turn into a maintainence nightmare for you.
    Of course, since you're going to do it anyway... I suspect your issue lies with paintComponent. If I recall correctly, paintComponent doesn't render anything by default for a JComponent. You'll need to override paintComponent and have it invoke the renderer for the relevant child component.

  • I need help with this recursion method

         public boolean findTheExit(int row, int col) {
              char[][] array = this.getArray();
              boolean escaped = false;
              System.out.println("row" + " " + row + " " + "col" + " " + col);
              System.out.println(array[row][col]);
              System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   System.out.println("possible:" + " " + possible(row,col));
                   array[row][col] = '.';
              if (checkBorder(row, col)){
                   System.out.println("check border:" + " " + checkBorder(row,col));
                   escaped = true;
              else {
                    System.out.println();
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         }I am having difficulties with this recursion method. What I wanted here is that when :
    if escaped = findTheExit(row+1, col);  I am having trouble with the following statement:
    A base case has been reached, escaped(false) is returned to RP1. The algorithm backtracks to the call where row = 2 and col = 1 and assigns false to escaped.
    How do I fix this code?
    I know what's wrong with my code now, even though that if
    if (possible(row, col))
    [/code[
    returns false then it will go to if (escaped == false)
                   escaped = findTheExit(row, col+1);
    how do I do this?

    Okay I think I got the problem here because I already consult with the instructor, he said that by my code now I am not updating my current array if I change one of the values in a specific row and column into '.' . How do I change this so that I can get an update array. He said to me to erase char[][] array = getArray and replace it with the array instance variable in my class. But I don't have an array instance variable in my class. Below is my full code:
    public class ObstacleCourse implements ObstacleCourseInterface {
         private String file = "";
         public ObstacleCourse(String filename) {
              file = filename;
         public boolean findTheExit(int row, int col) {
              boolean escaped = false;
              //System.out.println("row" + " " + row + " " + "col" + " " + col);
              //System.out.println(array[row][col]);
              //System.out.println("escaped" + " " + escaped);
              if (possible(row, col)){
                   //System.out.println("possible:" + " " + possible(row,col) + "\n");
                   array[row][col] = '.';
                   if (checkBorder(row, col)){
                   escaped = true;
                   else {
                    escaped = findTheExit(row+1, col);
                    if (escaped == false)
                    escaped = findTheExit(row, col+1);
                    else if (escaped == false)
                    escaped = findTheExit(row-1, col);
                    else if (escaped == false)
                    escaped = findTheExit(row, col-1);
              if (escaped == true)
                   array[row][col] = 'O';
              return escaped;
         public char[][] getArray() {
              char[][] result = null;
              try {
                   Scanner s = new Scanner(new File(file));
                   int row = 0;
                   int col = 0;
                   row = s.nextInt();
                   col = s.nextInt();
                   String x = "";
                   result = new char[row][col];
                   s.nextLine();
                   for (int i = 0; i < result.length; i++) {
                        x = s.nextLine();
                        for (int j = 0; j < result.length; j++) {
                             result[i][j] = x.charAt(j);
              } catch (Exception e) {
              return result;
         public int getStartColumn() {
              char[][] result = this.getArray();
              int columns = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             columns = j;
              return columns;
         public int getStartRow() {
              char[][] result = this.getArray();
              int row = -1;
              for (int i = 0; i < result.length; i++) {
                   for (int j = 0; j < result[i].length; j++) {
                        if (result[i][j] == 'S')
                             row = i;
              return row;
         public boolean possible(int row, int col) {
              boolean result = false;
              char[][] array = this.getArray();
              if (array[row][col] != '+' && array[row][col] != '.')
                   result = true;
              return result;
         public String toString() {
              String result = "";
              try {
                   Scanner s = new Scanner(new File(file));
                   s.nextLine();
                   while (s.hasNextLine())
                        result += s.nextLine() + "\n";
              } catch (Exception e) {
              return result;
         public boolean checkBorder(int row, int col) {
              char[][] array = this.getArray();
              boolean result = false;
              int checkRow = 0;
              int checkColumns = 0;
              try {
                   Scanner s = new Scanner(new File(file));
                   checkRow = s.nextInt();
                   checkColumns = s.nextInt();
              } catch (Exception e) {
              if ((row + 1 == checkRow || col + 1 == checkColumns) && array[row][col] != '+')
                   result = true;
              return result;
    I thought that my problem would be not to read the file using the try and catch everytime in the method. How do I do this?? Do I have to create an array instance variable in my class?

  • Need help with new url address

    i'm very new to iweb and .mac - i've worked with websites before but never actually registered for a domain and need help setting up my iweb or .mac website with a new address.
    Can someone please help me with this...prices? where do i go? i just don't want to create a site for our student ministry at church without having a web/myname.com address.
    Thanks in advance!
    Chris

    You'll find there are a lot of good ones. Godaddy is one that I used to use. I am very happy with bluehost.com great prices and excellent service
    Produce | Shoot | Edit
    Take Two Visual Media
    http://www.take2vm.com

  • Need help with new Time Capsule/Airport express setup!

    I just hooked up a 500g time capsule to replace an airport extreme, and now my airport utility on my MacbookPro Retina no longer recognizes the airport expresses I had on my network for airplay purposes.  Can anyone help with this issue?

    Instead of a switch you need a wireless router, because your modem will only assign one public ip address to the switch and that ip address will be forwarded to any one computer at a given time...You should replace the switch with a wireless router and it should resolve your concern...

  • Need Help with new site glitches PLEASE!!!

    I need help trouble shooting a website. The site is
    www.farrowandwatkins.com. Nav buttons on Mac they display correctly
    which is aligned at top and bottom of content to left on Home page.
    However, when viewed on PC, the buttons spread to fill the
    distance of the "Patients" Page. All the pages spread to this
    length also, but are not suppose to.
    Nav buttons have padding of 10 on bottom, except last one.
    Please help if you can

    First guess would be that there doesn't seem to be a fixed
    height or width on the cell for the 'patients' button.

  • I need help with my remove method on a BST!

    Guys I need some help here, I have to create a remove method for a BST and below is my code:
    public boolean remove(OrderedMap map, K keyOfelementToRemove) {
              boolean result = false;
              if (root == null)
                   result = false;
              else {
                   MapNode curr = root;
                   MapNode prev = root;
                   while (curr.key.equals(keyOfelementToRemove) == false) {
                        prev = curr;
                        if (keyOfelementToRemove.compareTo(curr.key) < 0)
                             curr = curr.left;
                        else if (keyOfelementToRemove.compareTo(curr.key) > 0)
                             curr = curr.right;
                        if (curr == null)
                             break;
                   if (curr == null)
                        return result;
                   else if (curr == root && curr.left == null)
                        root = root.right;
                   else if (curr.left == null) {
                        if (curr.right == null)
                             curr = null;
                        else if (curr == prev.left)
                             prev = curr.right;
                        else if (curr == prev.right){
                             prev = curr.right;
                   else if (curr.left != null) {
                        MapNode temp = curr.left;
                        while (temp.right != null)
                             temp = temp.right;
                        K change = temp.key;
                        temp = null;
                        curr.key = change;
              size--;
              return result;
         }the algorithm that my instructor provides is:
    private boolean remove( BinaryTreeNode t, Comparable elementToRemove )
    Set result to false
    Traverse the tree t until elementToRemove is found. Use curr and prev to find the element
    leaving curr referring the node you want to remove. It may be the case that curr is null indicating
    that elementToRemove was not found. Now there are four cases to consider :
    Case 1: Not found
    return result (false)
    Case 2: The root is to be removed, but it has no left child.
    root = root's right subtree (assuming root refers the the root node in your BST)
    Case 3: The node is further down tree with no left child. Now must adjust one of the parent's links
    if curr is on the left side of prev,
    move parent's left link down to down to curr's right child
    else
    curr is on the right side of prev, so move parent's right down to down to curr's right child
    Case 4: curr has a left child.
    We can no longer ignore the left subtree. So find the maximum in the left subtree and
    move that object to the node referenced by curr . Then eliminate the maximum in the
    left subtree, which is now being reference from the original node to remove.
    however for case 3 and 4 it doesn't work, can someone please tell me why? I don't know where I made a mistake and I tried finding it but I still dont know

    I am sorry about the double post. I'll try not to do this again. My problem here seems to be that prev and curr aren't updating the BST outside this method, which means that it only changes locally but not permanently. I will post the code of the other headings:
    public class OrderedMap<K extends Comparable<K>, V> {
         private class MapNode {
              // Links to other BSTs
              private MapNode left;
              private MapNode right;
              ArrayList<V> temp1 = new ArrayList<V>();
              // The references to the key/value pair of the mapping
              private K key;
              @SuppressWarnings("unused")
              private V value;
              public MapNode(K theKey, V theValue) {
                   key = theKey;
                   value = theValue;
                   left = null;
                   right = null;
         } // end class MapNode
         private MapNode root;
         private int size;
         public OrderedMap() { // Create an empty tree
              root = null;
              size = 0;
         public int size() {
              return size;
         }

  • Need help with a class project

    I'm new to Java and I'm having problems converting a small program to be more functional. Here is my original codeimport java.util.Arrays;
    public class Product
    // initialize arrays
       private int cdNums[] = { 0,0,0,0 };
       private String cdNames[] = { "null", "null", "null", "null" };
       private int cdUnits[] = { 0,0,0,0 };
       private double cdValue[] = { 0.0, 0.0, 0.0, 0.0 };
       private double inventoryValue[] = { 0.0, 0.0, 0.0, 0.0 };
    // initialize instance variable
       private double totalValue = 0;
       private int count;
       public Product( int invNumber[], String albumName[], int invUnits[], double invValue[] )
             cdNums = invNumber;  // store inventory number
             cdNames = albumName;  //store album name
             cdUnits = invUnits;  //store number of units
             cdValue = invValue; // store unit price
       public double calcInventoryValue()
             // calculate Inventory value
                for ( int count = 0; count < cdNums.length; count++ )
                       totalValue =0; // initialize totalValue
                       totalValue =( cdUnits[ count ] * cdValue [ count ] );
               System.out.printf( "%s%d%s%s%s%d%s%.2f%s%.2f\n", "Item #", cdNums[ count ], " is: ", cdNames[ count ], " with ", cdUnits [ count ], " units priced at $", cdValue [ count ], " gives value of $", totalValue );
             return totalValue;
          } // end calcinventoryValue method
    } // end classand the test application: import java.util.Arrays;
    public class ProductTest
       public static void main( String args[] )
            int invNumber [] = { 1,2,3,4 };
            String albumName[] = { "Wish You Were Here", "Abacab", "Animals", "Security" };
            int invUnits[] = { 200, 150, 50, 500 };
            double invValue[] = { 14.99, 9.99, 23.49, 12.99 };
         Product myProduct = new Product (invNumber, albumName, invUnits, invValue );       
            myProduct.calcInventoryValue();
         } // end main
    } // end class ProductTestWhat I want to do is convert it to read in user input instead of static lists. Here is what I have so far:
    import java.util.Arrays;
    public class Product
    // initialize arrays
       private int cdNums[];
       private String cdNames[];
       private int cdUnits[];
       private double cdValue[];
       private double inventoryValue[];
    // initialize instance variable
       private double runValue = 0;
       private double totalValue = 0;
       private int count;
       public Product( int invNumber[], String albumName[], int invUnits[], double invValue[] )
             cdNums = invNumber;  // store inventory number
             cdNames = albumName;  //store album name
             cdUnits = invUnits;  //store number of units
             cdValue = invValue; // store unit price
       public double calcInventoryValue()
             // calculate Inventory value
                totalValue = 0; // Initialize totalValue variable
                for ( int count = 0; count < cdNums.length; count++ )
                       runValue =0; // initialize runValue
                       runValue =( cdUnits[ count ] * cdValue [ count ] );
               System.out.printf( "%s%d%s%s%s%d%s%.2f%s%.2f\n", "Item #", cdNums[ count ], " is: ", cdNames[ count ], " with ", cdUnits [ count ], " units priced at $", cdValue [ count ], " gives value of $", runValue );
                     totalValue = totalValue += runValue;
              calcTotalValue( totalValue );
             return totalValue;
          } // end calcinventoryValue method
        public double calcTotalValue( double totalValue )
             System.out.printf( "%s%.2f\n", "The total value of the inventory is: $", totalValue );
              return totalValue;
           } // end calcTotalValue method
    } // end classand the new test application:
    import java.util.Arrays;
    import java.util.Scanner;
    public class ProductTest
       public static void main( String args[] )
            double totalValue = 0;
          do 
            { //  open dowhile
             int count = 0; // initialize counter
             Scanner input = new Scanner( System.in ); // call scanner to get input
             for ( int count = 0; count > 0; count++ )
               {  // open for loop
                         System.out.printf ( "%s%d%s\n", "Please enter the inventory # of Item ", count, " or 0 to quit: " );  // prompt for inventory number or sentinel value
                          int invNumber[ count ] = input.nextInt();  // get user input of Item Number
                 if ( invNumber[ count ] != 0 )  // check for sentinel
                   {  // open if
                         System.out.printf ( "%s%d\n","Please enter the album name of Item #", invNumber[ count ] );  // prompt for album name
                         String albumName[ count ] = input.nextLine();  // get input album name
                         System.out.printf ( "%s%d\n", "Please enter the number of units in stock for Item #", invNumber[ count ] );  // prompt for number of units in stock
                         int invUnits[ count ] = input.nextint();  // input rate of payment
                         System.out.printf ( "%s%.2f\n", "Please enter the unit price for Item #", invNumber[ count ] );  // prompt for unit price
                         double unitValue = input.nextDouble();  // input rate of payment
                         System.out.println();  // print blank line for readability
                   } // close if
                else
                   {  // open else
                      Product myProduct = new Product (invNumber, albumName, invUnits, invValue );       
                         myProduct.calcInventoryValue();
                   } // close else
               } // close for loop           
           } while ( invNumber != 0 );  // loop back to inputting employee name and close dowhile
        } // end main
    } // end class ProductTestthe compiler is telling me for ProductTest that it is expecting "]" for the following line: int invNumber[ count ] = input.nextInt();Do I need to store the data in a variable first and then feed it into the array? What do I need to do to complete this code?

    OK, yeah. Change the Product constructor so that it takes scalar values (as opposed to arrays) -- a single int for units in stock, and single String for name, etc.
    Then you can create multiple objects of that class, one for each CD or whatever.
    It makes sense to hardcode values in the ProductTest class, but not really in the Product class. Your ProductTest class is almost there. You know how in the main method you create a single Product object with those arrays? Change it so that you have a loop. Loop through the prices, album names, etc., and create a Product for each set of values. Then put the Product objects in an array, or better yet (and if you've covered it in class) into a Collection like a java.util.HashSet or a java.util.ArrayList.
    You said you wanted to make it take values from user input, rather than hardcoded lists. Once you've made the above change, move on to doing that. You can read user input with a java.util.Scanner. Or you can use a java.io.BufferedReader. Did the prof say to use one particular method or another?

  • Need help with a remove method..

    Hello. I'm getting started on a project here to implement a recursive remove method that will remove any number from a list. I was given a test that the method must pass, but I'm having some trouble getting started. This is my second interaction with the idea of recursion and it's a bit difficult for me.
    Here is the test I'm writing the method for:
    public void testRemove() {
              int element=0;
              boolean inList = false;
              for (int i = -10; i < 11; i++)list.insert(i);
              int numElements = list.length();
              list.remove(element);
              for (int e : list) {
                   if ( e == element ) inList = true;
              assertTrue(!inList && (list.length()==(numElements-1)));
              element = -10;
              inList = false;
              list.remove(element);
              for (int e : list) {
                   if ( e == element ) inList = true;
              assertTrue(!inList && (list.length()==(numElements-2)));
              element = 10;
              inList = false;
              list.remove(element);
              for (int e : list) {
                   if ( e == element ) inList = true;
              assertTrue(!inList && (list.length()==(numElements-3)));
              //does remove work when element's value greater than value of last item in list
              element = 20;
              inList = false;
              list.remove(element);
              for (int e : list) {
                   if ( e == element ) inList = true;
              assertTrue(!inList && (list.length()==(numElements-3)));
              //does remove work when element's value less than value of first item in list
              element = -20;
              inList = false;
              list.remove(element);
              for (int e : list) {
                   if ( e == element ) inList = true;
              assertTrue(!inList && (list.length()==(numElements-3)));
              System.out.printf("%s\n", "testRemove " + list.toString());
         }Now, clearly I need to test whether or not the number being removed is in the list (too low/too high), but I'm stuck trying to implement this.
    If anyone can give me any ideas or direction it would be greatly appreciated.

    Thanks for the quick reply, from what I had gathered and what you posted I'm starting to see where I need to go from here. I had gotten as far as if list is null return null, and the cod that you posted makes sense, but implementing it into the source code I already have will be troubling for me. The code as you presented it I have no trouble understanding, for example:
    if (list.data == data) return list.next;
    list.next=remove(list.next, data);Is clear to me, however I don't know how to implement that into my code. This is the code for the insert method:
         private Node<ElementType> insertp(Node<ElementType> list, ElementType element) {
              if ( (list == null) || ( element.compareTo(list.getElement() ) < 0 ) ) {
                   // test for insert at head or before current node
                   Node<ElementType> newNode = new Node<ElementType>(element, null);
                   newNode.setNext(list);
                   return newNode;
              else if (list.getNext() == null) { // list with one element
                   Node<ElementType> newNode = new Node<ElementType>(element, null);
                   list.setNext(newNode);         // element goes at end
              else if ( element.compareTo(list.getNext().getElement()) < 0 ) { // insert after list
                   Node<ElementType> newNode = new Node<ElementType>(element, list.getNext());
                   //newNode.setNext(list.getNext());
                   list.setNext(newNode);
              else {
                   insertp(list.getNext(), element); // find insertion point
              return list;
         }I'm still struggling to understand all of the code there. the element.compareTo() and everything. If you (or some one else) can explain to me what is going on with those methods, I may be able to implement it myself. Also, this may be of some use, these are the methods I have available to me:
    public class Node<E> {
      // Instance variables:
      private E element;
      private Node<E> next;
      /** Creates a node with null references to its element and next node. */
      public Node() {
        this(null, null);
      /** Creates a node with the given element and next node. */
      public Node(E e, Node<E> n) {
        element = e;
        next = n;
      // Accessor methods:
      public E getElement() {
        return element;
      public Node<E> getNext() {
        return next;
      // Modifier methods:
      public void setElement(E newElem) {
        element = newElem;
      public void setNext(Node<E> newNext) {
        next = newNext;
      public String toString() {
           return element.toString();
    }

  • Need help with project (calling methods) please!!

    Hi there i have a project for uni requiring me to create a java program that creates a random No. and lets the user have three guesses to find the No. When the users guesses correct he gets a message telling him hes won and if he doesnt get it correct he gets a message telling him the correct No then terminates.
    The code has to call an outside method called[b] Public Static Boolean CheckGuess
    I have tried to create this and got it to compile with no errors (eventually) but i keep getting a message saying i have whenever i type any number in. I think the problem is the way i am calling the method i havnt got much experience this is all pretty new to me any help would be really appreciated. Thanks.
    import javax.swing.*;
    import java.util.*;
    public class Coursework1{
         public static void main(String args[]){
              int randomnumber,usersguessint,checkguess,guessvalid,attempts;
              String usersguess,output;
              boolean match;
              //create random number generator
              Random numGenerator = new Random();
              //generate a random number between 1 & 10 inclusive
              randomnumber = Math.abs(numGenerator.nextInt(9))+1;
              //initialize variable attempts
              for ( attempts = 0; attempts < 3; attempts++ ) {
                   //ask user for his first guess
                   usersguess=JOptionPane.showInputDialog("Please enter your guess between 1 & 10");
                   //convert users guess to integer
                   usersguessint = Integer.parseInt(usersguess);
                        //validate input
                        while (usersguessint<1||usersguessint>10){
                        usersguess=JOptionPane.showInputDialog("You entered an incorrect number \nPlease enter a numberbetween 1 & 10");
                         //convert users guess to integer
                        usersguessint = Integer.parseInt(usersguess);
                        } //end while loop
                             //call boolean method
                             if (match=true){
                             //display text area in JoptionPane
                             output="You won";
                             JOptionPane.showMessageDialog(null,output,"You Won",JOptionPane.INFORMATION_MESSAGE);
                             break;}
                             else{
                             output="Try again";     
                             JOptionPane.showInputDialog("Try again");
                                  }     //end if
                   } //end for
              }//end main
                             //user defined method
                             public static boolean checkGuess(int usersguessint,int randomnumber){
                             boolean match = false;
                             if (usersguessint == randomnumber){
                             match = true;
                             return match;
                             }//end method
         }//endclass

    Thank you very much that worked a treat the program is working better now. I have just realised that my for loopcontaining my counter may be in the wrong place as the program is running though both messages 3 times e.g
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    "Please enter your guess between 1 & 10"
    "Try again"
    I want my program to run like
    "Please enter your guess between 1 & 10"
    "Try again"
    "Try again"
    "Try again"
    Do u think if i placed my for stament (counter) in between the two messages it would eliminate this problem.

Maybe you are looking for

  • Media Encoder CS6 won't render queued project from Pr CS6

    What's up with Adobe? All of a sudden, Pr CS6 no longer works with AME. I Queue from Pr and AME launches with file in Queue. I press Render button, and it takes several minutes before anything shows up in a the Encoding tab. When it does, I get an en

  • I can't restore my i pod, i get error 80000001

    i can't restore my i pod its locked becouse i lost my password, geting error 800001.

  • Opentext Document presentment

    Hi All, We currently print the bills using FPCOPARA and generate the PDFs using the smartforms. We generate 200K+ invoices and statements every bill run. And Credit Memos. These individual PDFs are generated and saved in some central location. Also e

  • Novice user - Need help publishing

    When I publish my site, everything shows up except the Flash movies. When I click on the error message on the IE screen, it gives me the following: Line: 215 Char: 1 Error: Object expected Code: 0 Any help would be greatly appreciated.

  • Re: Function taskbar doesn't work on Windows 7

    hi, i upgraded to Windows 7 from Vista, since that the function task bar I press FN bottom does`t appear. I have Qosmio G30 Any help appreciated,