Question
Could someone add the kind of the animal,weight, and age of the animal and write the code? I know that I must go with other
Could someone add the kind of the animal,weight, and age of the animal and write the code? I know that I must go with other collection framework or else add Object instead of String in place for Map. "
import java.util.*;
import java.util.Map.Entry;
public class Zoo
{
public static void main(String arg[]){
Map
m.put(100,"cow");
m.put(200,"ox");
m.put(300,"tiger");
m.put(400,"humans");
Scanner sc=new Scanner(System.in);
int choice;
do{
System.out.println("Welcome to Zoo Management");
System.out.println("1.promotion of all available animals of the zoo"+"\n"+"2. new animal added"+"\n"+" 3. search for the new animal depending on the name"+"\n"+" 4.search for an animal acording to the code "+"\n"+"5 animal processing depending on the code"+"\n"+" 6.deletion of animal depending on the code "+"\n"+"7. exit from the application");
System.out.println("enter your choice");
choice =sc.nextInt();
switch(choice){
case 1:
if(!m.isEmpty()) {
Iterator
while(it.hasNext()) {
Entry
System.out.println(obj.getKey()+""+obj.getValue());
}
}
break;
case 2:System.out.println("enter animal code and its name");
Integer code=sc.nextInt();
String name=sc.nextLine();
m.put(code,name);
//m.save();
break;
case 3: System.out.println("enter name to search");
name=sc.next();
if(!m.isEmpty()) {
Iterator
while(it.hasNext()) {
Entry
String newname=(String) obj.getValue();
if(name.equalsIgnoreCase(newname)) {
System.out.println(obj.getKey()+""+obj.getValue());
break;
}
}
}
break;
case 4:System.out.println("enter code to search");
code=sc.nextInt();
if(!m.isEmpty()) {
Iterator
while(it.hasNext()) {
Entry
Integer newcode=(Integer) obj.getKey();
if(code.equals(newcode)) {
System.out.println(obj.getKey()+""+obj.getValue());
break;
}
}
}
case 5:System.out.println("enter code to modify");
code=sc.nextInt();
if(!m.isEmpty()) {
Iterator
while(it.hasNext()) {
Entry
Integer newcode=(Integer) obj.getKey();
if(code.equals(newcode)) {
System.out.println("enter animal name");
name=sc.next();
m.put(code,name);
break;
}
}
}
case 6:System.out.println("enter code of the animal to remove");
code=sc.nextInt();
if(!m.isEmpty()) {
Iterator
while(it.hasNext()) {
Entry
Integer newcode=(Integer) obj.getKey();
if(code.equals(newcode))
{
m.remove(newcode);
break;
}
}
}
default: System.exit(0);
}
}while(choice!=0 && choice<=6);
sc.close();
}
Step by Step Solution
3.39 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
ZooManagementjava import javautilHashMap import javautilIterator import javautilMap import javautilMapEntry import javautilScanner final class SetAnimals private String animalName private String anima...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