Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

GETTING ERROR: \"Cannot find symbol - Class LinkedList\" import java.util.*; //P

ID: 3860848 • Letter: G

Question

GETTING ERROR: "Cannot find symbol - Class LinkedList"

import java.util.*;
//Plant.java
class Plant{
String name;
int id;
String color;
Plant(){
}
void SetID(int id)
{
  this.id = id;
}
int GetID()
{
return this.id;
}
void SetName(String name)
{
  this.name = name;
}
void SetColor(String color)
{
this.color = name;
}
public void Show(){
System.out.println("ID:"+id+" Name:"+name+" Color:"+color);
}
}
//Flower.java
class Flower extends Plant{
  
String thorns;
String smell;
void SetSmell(String smell)
{
this.smell = smell;
}
void SetThorns(String thorn)
{
this.thorns = thorn;
}
public void Show(){
super.Show();   
System.out.println("thorns:"+thorns+"Smell:"+smell);
}
  
}
//Fungus.java
class Fungus extends Plant{
  
boolean poisonous;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
public void Show(){
super.Show();   
System.out.println("poisonous:"+poisonous);
}
  
}
//Weed.java
class Weed extends Plant{
  
boolean poisonous;
String edible;
String medicinal;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
void SetEdible(String edible)
{
this.edible = edible;
}
void SetMedicinal(String medicinal)
{
this.medicinal = medicinal;
}
public void Show(){
super.Show();   
System.out.println("poisnous:"+poisonous+"edible:"+edible+"medicinal:"+medicinal);
}
  
}
//Mid.java
public class Mid{
  
static LinkedList <Plant> plants;
  
public static Plant SearchPlant(int id)
{
for(Plant p:plants){   
if ( p.GetID() == id ) {
return p;   
}
}
return null;
}
  
public static void main(String []args){
plants=new LinkedList <Plant>();
boolean continueChoice = false;
Scanner scanner = new Scanner(System.in);
int choice = 0;
do {
try{
System.out.println("Choose Plant:1. Flower 2. Fungus 3.Weed Enter Option:");
int plantCh = scanner.nextInt();
if ( plantCh < 1 || plantCh > 3 )
{
System.out.println("Wrong Choice Entered! Try Again");
continue;
}
System.out.println("Choose Operation:1. Add 2. Remove 3. Search 4. Show Enter Option:");
int op = scanner.nextInt();   
switch(op)
{
case 1://Add
int id;
System.out.println("Enter ID:");
id = scanner.nextInt();
scanner.nextLine(); //This is needed to pick up the new line   
  
System.out.println("Enter Name:");
String name = scanner.nextLine();
System.out.println("Enter Color:");
String color = scanner.nextLine();
  
Plant p = null;
if ( plantCh == 1 )
{
p = new Flower();
System.out.println("Enter thorns:");
String thorns = scanner.nextLine();
((Flower)p).SetThorns(thorns);
// p.SetThorns(thorns);
System.out.println("Enter Smell:");
String smell = scanner.nextLine();
((Flower)p).SetSmell(smell);
  
}
else if(plantCh == 2 )
{ p = new Fungus();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Fungus)p).SetPoisonous(poison);
  
  
}
else {
p = new Weed();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Weed)p).SetPoisonous(poison);
  
System.out.println("Enter Edible:");
String edible = scanner.nextLine();   
((Weed)p).SetEdible(edible);
  
System.out.println("Enter Medicinal:");
String medicinal = scanner.nextLine();   
((Weed)p).SetMedicinal(medicinal);
}
p.SetID(id);
p.SetName(name);
p.SetColor(color);   
plants.add(p);
  
break;
case 2://Remove
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantOBJ = SearchPlant(id);
if ( plantOBJ != null ) {
plants.remove(plantOBJ);
System.out.println("Flower ID: "+id+"removed");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}
}
break;
case 3://Search
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
if ( SearchPlant(id) != null ) {
System.out.println("Flower ID: "+id+"found");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}   
  
break;
  
case 4://Show
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantObj = SearchPlant(id);
if ( SearchPlant(id) != null) {
plantObj.Show();
}
else
{
System.out.println("Flower ID: "+id+"not found");
}   
}
break;
  
  
default:
System.out.println("Wrong choice");
  
}
System.out.print("Do you want to continue (true or false): ");
continueChoice = scanner.nextBoolean();
}
catch(Exception e)
{
e.printStackTrace();
}
}
while(continueChoice);
}
}

Explanation / Answer

The code is working perfectly fine for me.

Just add

import java.util.LinkedList;

below your package name. It will then do not show the errors like tose. For safe side add

import java.util.*;

for executing the program.

Working Code:-

import java.util.*;
class Plant{
String name;
int id;
String color;
Plant(){
}
void SetID(int id)
{
this.id = id;
}
int GetID()
{
return this.id;
}
void SetName(String name)
{
this.name = name;
}
void SetColor(String color)
{
this.color = name;
}
public void Show(){
System.out.println("ID:"+id+" Name:"+name+" Color:"+color);
}
}
//Flower.java
class Flower extends Plant{

String thorns;
String smell;
void SetSmell(String smell)
{
this.smell = smell;
}
void SetThorns(String thorn)
{
this.thorns = thorn;
}
public void Show(){
super.Show();
System.out.println("thorns:"+thorns+"Smell:"+smell);
}

}
//Fungus.java
class Fungus extends Plant{

boolean poisonous;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
public void Show(){
super.Show();
System.out.println("poisonous:"+poisonous);
}

}
//Weed.java
class Weed extends Plant{

boolean poisonous;
String edible;
String medicinal;
void SetPoisonous(boolean poisonous)
{
this.poisonous = poisonous;
}
void SetEdible(String edible)
{
this.edible = edible;
}
void SetMedicinal(String medicinal)
{
this.medicinal = medicinal;
}
public void Show(){
super.Show();
System.out.println("poisnous:"+poisonous+"edible:"+edible+"medicinal:"+medicinal);
}

}
//Mid.java
public class Mid{

static LinkedList <Plant> plants;

public static Plant SearchPlant(int id)
{
for(Plant p:plants){
if ( p.GetID() == id ) {
return p;
}
}
return null;
}

public static void main(String []args){
plants=new LinkedList <Plant>();
boolean continueChoice = false;
Scanner scanner = new Scanner(System.in);
int choice = 0;
do {
try{
System.out.println("Choose Plant:1. Flower 2. Fungus 3.Weed Enter Option:");
int plantCh = scanner.nextInt();
if ( plantCh < 1 || plantCh > 3 )
{
System.out.println("Wrong Choice Entered! Try Again");
continue;
}
System.out.println("Choose Operation:1. Add 2. Remove 3. Search 4. Show Enter Option:");
int op = scanner.nextInt();
switch(op)
{
case 1://Add
int id;
System.out.println("Enter ID:");
id = scanner.nextInt();
scanner.nextLine(); //This is needed to pick up the new line

System.out.println("Enter Name:");
String name = scanner.nextLine();
System.out.println("Enter Color:");
String color = scanner.nextLine();

Plant p = null;
if ( plantCh == 1 )
{
p = new Flower();
System.out.println("Enter thorns:");
String thorns = scanner.nextLine();
((Flower)p).SetThorns(thorns);
// p.SetThorns(thorns);
System.out.println("Enter Smell:");
String smell = scanner.nextLine();
((Flower)p).SetSmell(smell);

}
else if(plantCh == 2 )
{ p = new Fungus();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Fungus)p).SetPoisonous(poison);


}
else {
p = new Weed();
System.out.println("Enter poisnous:");
boolean poison = scanner.nextBoolean();
((Weed)p).SetPoisonous(poison);

System.out.println("Enter Edible:");
String edible = scanner.nextLine();
((Weed)p).SetEdible(edible);

System.out.println("Enter Medicinal:");
String medicinal = scanner.nextLine();
((Weed)p).SetMedicinal(medicinal);
}
p.SetID(id);
p.SetName(name);
p.SetColor(color);
plants.add(p);

break;
case 2://Remove
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantOBJ = SearchPlant(id);
if ( plantOBJ != null ) {
plants.remove(plantOBJ);
System.out.println("Flower ID: "+id+"removed");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}
}
break;
case 3://Search
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
if ( SearchPlant(id) != null ) {
System.out.println("Flower ID: "+id+"found");
}
else
{
System.out.println("Flower ID: "+id+"not found");
}

break;

case 4://Show
{
System.out.println("Enter Plant ID:");
id =scanner.nextInt();
Plant plantObj = SearchPlant(id);
if ( SearchPlant(id) != null) {
plantObj.Show();
}
else
{
System.out.println("Flower ID: "+id+"not found");
}
}
break;


default:
System.out.println("Wrong choice");

}
System.out.print("Do you want to continue (true or false): ");
continueChoice = scanner.nextBoolean();
}
catch(Exception e)
{
e.printStackTrace();
}
}
while(continueChoice);
}
}

Output:-

Choose Plant:1. Flower
2. Fungus
3.Weed
Enter Option:
1
Choose Operation:1. Add
2. Remove
3. Search
4. Show
Enter Option:
1
Enter ID:
123
Enter Name:
cactus
Enter Color:
green
Enter thorns:
yes
Enter Smell:
noSmell
Do you want to continue (true or false): true
Choose Plant:1. Flower
2. Fungus
3.Weed
Enter Option:
1
Choose Operation:1. Add
2. Remove
3. Search
4. Show
Enter Option:
4
Enter Plant ID:
123
ID:123
Name:cactus
Color:cactus
thorns:yesSmell:noSmell
Do you want to continue (true or false): false