Advertisement
Guest User

Computer.java

a guest
May 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class Computer{
  2.   //fields
  3.   private int gigsRam;
  4.   private String os;
  5.  
  6.   //constructor
  7.   public Computer( int g, String o ){
  8.     gigsRam = g;
  9.     os = o;
  10.   }
  11.  
  12.   public Computer(){
  13.     gigsRam = 2;
  14.     os = "Ubuntu Linux";
  15.   }
  16.  
  17.   //accessor
  18.   public int getGigsRam(){
  19.     return gigsRam;
  20.   }
  21.  
  22.   public String getOS(){
  23.     return os;
  24.   }
  25.  
  26.   public double price(){
  27.     double thePrice = gigsRam * 400;
  28.     if( os.equals("Mac OSX") )
  29.       thePrice *= 2;
  30.     return thePrice;
  31.   }
  32.  
  33.   public static void main(String[] args){
  34.     Computer windows = new Computer(4, "Windows 10");
  35.     Computer mac = new Computer(4, "Mac OSX");
  36.     System.out.println( "The price of a " + windows.getOS() + " machine is " + windows.price() );
  37.     System.out.println( "The price of a " + mac.getOS() + " machine is " + mac.price() );
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement