Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Computer{
- //fields
- private int gigsRam;
- private String os;
- //constructor
- public Computer( int g, String o ){
- gigsRam = g;
- os = o;
- }
- public Computer(){
- gigsRam = 2;
- os = "Ubuntu Linux";
- }
- //accessor
- public int getGigsRam(){
- return gigsRam;
- }
- public String getOS(){
- return os;
- }
- public double price(){
- double thePrice = gigsRam * 400;
- if( os.equals("Mac OSX") )
- thePrice *= 2;
- return thePrice;
- }
- public static void main(String[] args){
- Computer windows = new Computer(4, "Windows 10");
- Computer mac = new Computer(4, "Mac OSX");
- System.out.println( "The price of a " + windows.getOS() + " machine is " + windows.price() );
- System.out.println( "The price of a " + mac.getOS() + " machine is " + mac.price() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement