Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandru
Quries
2 Answer(s)      3 years and 3 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


Advertisement
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 Tutorials/Questions & Answers:
sql quries
sql quries  i want basic sql quries please provide
Advertisements
uploading image in the form
they logged into the screen. Im using Orcale database(sql quries to check
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email
 

 

 

DMCA.com