chandru
Quries
2 Answer(s)      a year and 10 months ago
Posted in : Java Beginners

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

View Answers

August 3, 2011 at 3:21 PM


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);
        }
}

August 3, 2011 at 7:54 PM


Thanks....









Related Pages:
sql quries
sql quries  i want basic sql quries please provide
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.