Advertisement
ismail5g

Question-6

Apr 14th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3. class library{
  4.     public int bookid;
  5.     protected String name;
  6.     private double price;
  7.     void setprice(double a){
  8.         price=a;
  9.     }
  10.     double getprice(){
  11.         return price;
  12.     }
  13. }
  14. class use{
  15.     public static void main(String[] args){
  16.         Scanner input= new Scanner(System.in);
  17.         library ob = new library();
  18.         System.out.println("Enter Book Name: ");
  19.         ob.name= input.next();
  20.         System.out.println("Enter Book ID: ");
  21.         ob.bookid=input.nextInt();
  22.         System.out.println("Enter Book Price: ");
  23.         double b=input.nextDouble();
  24.         ob.setprice(b);
  25.         System.out.println("Name: "+ob.name+" ID: "+ob.bookid+" Price: "+ob.getprice());
  26.     }
  27. }
  28.  
  29.  
  30. Output:
  31.  
  32. Enter Book Name:
  33. Programming
  34. Enter Book ID:
  35. 12334
  36. Enter Book Price:
  37. 570
  38. Name: Programming ID: 12334 Price: 570.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement