n my code there is a syntax error. i am trying to take out each character from inputted string and store each character into a linked list. i keep getting a syntax error stating that "non static method insertFirst(char) cannot be referenced in a static context" I have no idea why this is happening and i need help. I cannot change anything in the link and linkedlist objects i have instructions to rely rigidly to the textbooks code and i cannot change the data types. i would prefer you to explain the problem and solution in words. language is in Java CODE   MAIN FUNCTION import java.util.Scanner; /** * Write a description of class test here. * * @author (your name) * @version (a version number or a date) */ public class test { // instance variables - replace the example below with your own public static void main(String[] args) { Scanner input = new Scanner(System.in); linkedList list = new linkedList(); char character; System.out.println("please enter a string."); String inString = input.nextLine(); for(int i = 0; i < inString.length(); i++) { character = inString.charAt(i); linkedList.insertFirst(character); } } } LINKED LIST OBJECT /** * Write a description of class linkedList here. * * @author (your name) * @version (a version number or a date) */ public class linkedList { private link first; public linkedList() { first = null; } public boolean isEmpty() { return (first==null); } public void insertFirst(char id) { link newLink = new link(id); newLink.next = first; first = newLink; } public link deleteFirst() { link temp = first; first = first.next; return temp; } public void displayList() { System.out.print("List (first -->last): "); link current = first; while(current != null) { current.displayLink(); current = current.next; } System.out.println(""); } } LINK OBJECT import java.util.Scanner; /** * Write a description of class test here. * * @author (your name) * @version (a version number or a date) */ public class test { // instance variables - replace the example below with your own public static void main(String[] args) { Scanner input = new Scanner(System.in); linkedList list = new linkedList(); char character; System.out.println("please enter a string."); String inString = input.nextLine(); for(int i = 0; i < inString.length(); i++) { character = inString.charAt(i); linkedList.insertFirst(character); } } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

in my code there is a syntax error. i am trying to take out each character from inputted string and store each character into a linked list. i keep getting a syntax error stating that "non static method insertFirst(char) cannot be referenced in a static context" I have no idea why this is happening and i need help. I cannot change anything in the link and linkedlist objects i have instructions to rely rigidly to the textbooks code and i cannot change the data types. i would prefer you to explain the problem and solution in words. language is in Java

CODE

 

MAIN FUNCTION

import java.util.Scanner;
/**
* Write a description of class test here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class test
{
// instance variables - replace the example below with your own
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
linkedList list = new linkedList();
char character;

System.out.println("please enter a string.");

String inString = input.nextLine();

for(int i = 0; i < inString.length(); i++)
{
character = inString.charAt(i);
linkedList.insertFirst(character);
}
}
}

LINKED LIST OBJECT


/**
* Write a description of class linkedList here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class linkedList
{
private link first;
public linkedList()
{
first = null;
}

public boolean isEmpty()
{
return (first==null);
}

public void insertFirst(char id)
{
link newLink = new link(id);
newLink.next = first;
first = newLink;
}

public link deleteFirst()
{
link temp = first;

first = first.next;

return temp;
}

public void displayList()
{
System.out.print("List (first -->last): ");
link current = first;
while(current != null)
{
current.displayLink();
current = current.next;
}
System.out.println("");
}
}

LINK OBJECT

import java.util.Scanner;
/**
* Write a description of class test here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class test
{
// instance variables - replace the example below with your own
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
linkedList list = new linkedList();
char character;

System.out.println("please enter a string.");

String inString = input.nextLine();

for(int i = 0; i < inString.length(); i++)
{
character = inString.charAt(i);
linkedList.insertFirst(character);
}
}
}

Expert Solution
Step 1 ku

Static methods are those methods which can be called in main() without any instance of the class. This means they can be called directly like a normal function call without creating a object of the class and using it to call the method.

While non-static methods are those which cannot be called independently. They have to be called through a object of the class.

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY