Question
JAVA PROGRAM - File saving and loading 1. Using the code below implement an option to save the plants to a file . You must
JAVA PROGRAM - File saving and loading
1. Using the code below implement an option to save the plants to a file. You must also be able to load the saved information from a previously saved file.
2. Use the file class and/or scanner class for file saving/loading methods
3. You MUST submit a sample file that can be loaded into your program without any changes (except the file path)
package flowerpack;
import java.util.ArrayList; import java.util.Scanner;
public class FlowerPack { public static void main(String[] args) { try{ ArrayList
} } if(flag==0) { System.out.println("plant not found") ; } break; case 3: input.nextLine(); System.out.print("Enter the name of the plant you want to search : "); name=input.nextLine(); int f=0; for(Plant plant:flowerPack) { if(plant.getName().equalsIgnoreCase(name)) { System.out.println("plant found sucessfully") ; f=1; break; } } if(f==0) { System.out.println("plant not found") ; } break; case 4: input.nextLine(); System.out.print("Enter the name of the plant you want to filter: "); name=input.nextLine(); f=0; for(Plant plant:flowerPack) { if(plant.getName().equalsIgnoreCase(name)) { System.out.println("Name: " + plant.getName() + "\tID: " + plant.getID()) ; f=1; } } if(f==0) { System.out.println("NO plant of this name in List") ; } break; case 5: System.exit(0); } } }catch(Exception e) { System.out.println(e); } }
}
*************
package flowerpack;
public class Plant { String name; String ID; Plant(String name,String ID) { this.name=name; this.ID=ID; } public String getName() { return name; } public String getID() { return ID; } } class Flower extends Plant { String color; boolean thorns; boolean smell; public Flower(String name, String ID,String color,boolean thorns,boolean smell) { super(name, ID); this.color=color; this.thorns=thorns; this.smell=smell; }
} class Fungus extends Plant { String Color; boolean Poisonous; public Fungus(String name, String ID,String Color,boolean Poisonous) { super(name, ID); this.Color=Color; this.Poisonous=Poisonous; }
} class Weed extends Plant { String Color; boolean Poisonous; boolean Edible; boolean Medicinal; public Weed(String name, String ID,String Color,boolean Poisonous,boolean Edible, boolean Medicinal) { super(name, ID); this.Color=Color; this.Poisonous=Poisonous; this.Edible=Edible; this.Medicinal=Medicinal; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started