Advertisement
fiveriverflow

Encapsulation

Dec 10th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. /* File name : Price.java */
  2. public class Price {
  3.  
  4.    private String itemName;
  5.    private String currencyType;
  6.    private double amount;
  7.  
  8.    public String getName() {
  9.       return itemName;
  10.    }
  11.  
  12.    public String getType() {
  13.       return currencyType;
  14.    }
  15.  
  16.    public double getAmount(){
  17.       return amount;
  18.    }
  19.  
  20.    public void setName(String name){
  21.       itemName = name;
  22.    }
  23.  
  24.    public void setType(String type){
  25.       currencyType = type;
  26.    }
  27.  
  28.    public void setIdNum(double value){
  29.       amount = value;
  30.    }
  31. }
  32.  
  33. /* File name : TestPrice.java */
  34. public class TestPrice {
  35.  
  36.    public static void main(String args[]){
  37.       Price price = new Price();
  38.       price.setName("Book");
  39.       price.setType("USD");
  40.       price.setAmount(14.99);
  41.  
  42.       System.out.print("Item Name: " + price.getName() + " Currency Type: " + price.getType() + " Item Price: " + price.getAmount());
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement