Advertisement
devankransteuber

Untitled

Feb 21st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. //http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-092-introduction-to-programming-in-java-january-iap-2010/lecture-notes/
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7.  
  8. public class bookLibrayModel {
  9.  
  10.     public static void main(String args[]){
  11.            
  12.             String[] books = {"Plants", "Dictionary", "Math", "Science"};
  13.            
  14.             boolean available= true;
  15.            
  16.             int bookNum = 0;
  17.            
  18.             int action;
  19.            
  20.             books[0] = available;
  21.             books[1] = available;
  22.             books[2] = available;
  23.             books[3] = available;
  24.            
  25.             Scanner myScanner = new Scanner(System.in);
  26.            
  27.             System.out.println("Please select a numbered option: \n 1.Check availablity of books \n 2.Return a book");
  28.            
  29.                 action = myScanner.nextInt();
  30.            
  31.                
  32.             if(action == 1){
  33.                 System.out.println("Please choose a numbered book: \n 1.Plants \n 2.Dictionary \n 3.Math \n 4.Science");
  34.                 bookNum = myScanner.nextInt();
  35.             }if(bookNum == 1){
  36.                 System.out.println("Book is available:"+ books[0]);
  37.             }else if(bookNum == 2){
  38.                 System.out.println("Book is available:"+ books[1]);
  39.             }else if(bookNum == 3){
  40.                 System.out.println("Book is available:"+ books[2]);
  41.             }else if(bookNum == 4){
  42.                 System.out.println("Book is availavble:"+ books[3]);
  43.             }
  44.  
  45.             if(action == 2){
  46.                 System.out.println("Please select a numbered book to return: \n1.Plants \n2.Dictionary \n3.Math \n4.Science");
  47.                 bookNum = myScanner.nextInt();
  48.             }if(bookNum == 1){
  49.                 available = !available;
  50.                 System.out.println(books[0]);
  51.             }
  52.        
  53.            
  54.            
  55.            
  56.     }
  57.    
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement