I'm having a hard time trying to get this working
So here are the files that I have. What I'm trying to do is take a MutableString object that is from a string. It will then take the object and create a LinkedList based off the characters.
This is my Tester
import java.util.*;
public class MutableStringTester
{
public static void main(String[] args)
{
MutableString string = new MutableString();
Scanner kb = new Scanner(System.in);
int choice = 0;
while(choice != 9)
{
choice = displayMenu(kb);
if(choice == 1)
{
String newString = "Hellow World";
MutableString string = new MutableString(newString);
System.out.println(newString);
}
if(choice == 2)
{
System.out.println();
System.out.println();
}
if(choice == 3)
{
System.out.println();
System.out.println();
}
if(choice == 4)
{
System.out.println();
System.out.println();
}
if(choice == 5)
{
System.out.println();
System.out.println();
}
if(choice == 6)
{
System.out.println();
System.out.println();
}
if(choice == 7)
{
System.out.println();
System.out.println();
}
if(choice == 8)
{
System.out.println();
System.out.println();
}
}
System.out.println();
System.out.println("Goodbye!");
}
private static int displayMenu(Scanner kb)
{
int choice = 0;
while (choice < 1 || choice > 9)
{
System.out.println("Please make a valid selection");
System.out.print("1) Create a new string\n" +
"2) Sort the string\n" +
"3) Print the string\n" +
"4) Print in reverse order\n" +
"5) Create a substring\n" +
"6) Delete the string\n" +
"7) Delete all instances of character\n" +
"8) Compare with another string\n" +
"9) Quit\n");
choice = kb.nextInt();
kb.nextLine();
}
return choice;
}
private static String readString(Scanner kb)
{
System.out.print("Please enter a string: ");
String s = kb.nextLine();
return s;
}
}
This is my MutableString class file
public class MutableString// implements Comparable
{
private LinkedList theString;
public MutableString()
{
this.theString = new LinkedList();
}
public MutableString(String theString)
{
this.theString = new LinkedList();
}
}
This is my LinkedList class file
import java.util.*;
public class LinkedList
{
public class LinkList
{
private class Node
{
private char data;
private Node next;
public Node(char data)
{
this.data = data;
}//end node
}//end Node
int size;
Node head;
}
public void addAll(char string)
{
add(string);
}//end addAll
//adds data to the end of the link list
public void add(char data)
{
Node curr = head;
Node newNode = new Node(data);
if(head == null)
{
head = newNode;
}//end if
else
{
while(curr.next != null)
{
curr = curr.next;
}//end while
curr.next = newNode;
}//end else
size++;
}//end add
public String toString()
{
String s = "";
if(head == null)
{
s = "The list is empty";
}//end if
for(Node curr = head; curr != null; curr = curr.next)
{
s = s + curr.data + "\n";
}//end for
return s;
}//end toString
}
The issue is that the LinkedList file isn't recognizing anything. Any help would be much appreciated. I'm having a really difficult time on this. It will print out the memory location of the linked list, but I can't get the characters into the Linked List.

New Topic/Question
Reply



MultiQuote




|