Program java For menu driven application to store the details of books based on the course(MBA, MSc ,MA) as a choice and display the list of corresponding course books9Min 5 books for each course. 1. MBA 2. MCA 3. MSc 4. MA 5. Exit
import java.util.ArrayList;
import java.util.Scanner;
class Book{
String course;
String book;
Book(String course,String book){
this.course=course;
this.book=book;
}
public String getCourse(){
return course;
}
public String getBook() {
return book;
}
}
public class BookBank{
public static void main(String[] a){
ArrayList<Book> list=new ArrayList<Book>();
Scanner input=new Scanner(System.in);
for(int i=0;i<10;i++){
System.out.print("Course: ");
String course=input.nextLine();
System.out.print("Book: ");
String book=input.nextLine();
list.add(new Book(course,book));
System.out.println();
}
boolean exit=false;
for(Book data: list){
System.out.println(data.getCourse()+"\t "+data.getBook());
}
do{
System.out.println("1 MBA");
System.out.println("2 MCA");
System.out.println("3 MSC");
System.out.println("4 MA");
System.out.println("5 Exit");
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 1:
for(Book data: list){
if(data.getCourse().equals("MBA")){
System.out.println(data.getCourse()+"\t "+data.getBook());
}
}
break;
case 2 :
for(Book data: list){
if(data.getCourse().equals("MCA")){
System.out.println(data.getCourse()+"\t "+data.getBook());
}
}
break;
case 3 :
for(Book data: list){
if(data.getCourse().equals("MSC")){
System.out.println(data.getCourse()+"\t "+data.getBook());
}
}
break;
case 4 :
for(Book data: list){
if(data.getCourse().equals("MA")){
System.out.println(data.getCourse()+"\t "+data.getBook());
}
}
break;
case 5 :
exit=true;
System.exit(0);
break;
default:
System.out.println("Invalid Selection!");
}
}
while(!exit);
}
}
Thanks....