Created
November 17, 2015 07:59
-
-
Save golenishchev/c65b53600f12a6fc68b3 to your computer and use it in GitHub Desktop.
Lesson 6. Getter, setter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Computer { // Creating class Computer | |
private int powerSupply; // fields | |
private float processor; | |
private int videoCard; | |
private String motherBoard; | |
/* getter and setter methods are evil | |
BEGIN powerSupply */ | |
public int getPowerSupply() { | |
return powerSupply; | |
} | |
public void setPowerSupply(int powerSupply) { | |
this.powerSupply = powerSupply; | |
} | |
// BEGIN processor | |
public float getProcessor() { | |
return processor; | |
} | |
public void setProcessor(float processor) { | |
this.processor = processor; | |
} | |
// BEGIN videoCard | |
public int getVideoCard() { | |
return videoCard; | |
} | |
public void setVideoCard(int videoCard) { | |
this.videoCard = videoCard; | |
} | |
// BEGIN motherBoard | |
public String getMotherBoard() { | |
return motherBoard; | |
} | |
public void setMotherBoard(String motherBoard) { | |
this.motherBoard = motherBoard; | |
} | |
public static void main(String[] args) { | |
Computer myComp = new Computer(); // object myComp | |
myComp.setPowerSupply(450); | |
myComp.setProcessor(2.4f); | |
myComp.setVideoCard(11); | |
myComp.setMotherBoard("Asus P5K"); | |
System.out.println(myComp.getPowerSupply() + "\n" + myComp.getProcessor() | |
+ "\n" + myComp.getVideoCard() + "\n" + myComp.getMotherBoard()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment