Last active
August 29, 2015 14:02
-
-
Save borncorp/d30e5199085e9cb3303b to your computer and use it in GitHub Desktop.
SettersnGetters
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
public class Bottle { | |
String name; | |
int capacity; | |
int used; | |
String contains; | |
String color; | |
public Bottle(String namecopy, int capacitycopy, int usedcopy, String containscopy, String colorcopy) { | |
this.name=namecopy; | |
this.capacity=capacitycopy; | |
this.used=usedcopy; | |
this.contains=containscopy; | |
this.color=colorcopy; | |
System.out.println("You have created a " | |
+ colorcopy | |
+ " bottle of " | |
+ containscopy | |
+ " .\nThe capacity is " | |
+ capacitycopy | |
+ ". Currently storing " | |
+ usedcopy | |
+ "ml. The bottle is named " | |
+ namecopy); | |
} | |
public int getCapacity() { | |
return capacity; | |
} | |
public void setCapacity(int capacity) { | |
this.capacity = capacity; | |
} | |
public int getUsed() { | |
return used; | |
} | |
public void setUsed(int used) { | |
this.used = used; | |
} | |
public String getContains() { | |
return contains; | |
} | |
public void setContains(String contains) { | |
this.contains = contains; | |
} | |
public String getName() { | |
return this.name; | |
} | |
public void setName(String namecopy) { | |
this.name=namecopy; | |
} | |
public String toString() { | |
return "Bottle [name=" + getName() + ", capacity=" + getCapacity() + ", used=" | |
+ getUsed() + ", contains=" + getContains() + ", color=" + getColor() + "]"; | |
} | |
public String getColor() { | |
return this.color; | |
} | |
public void setColor(String colorcopy) { | |
this.color=colorcopy; | |
} | |
} |
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
public class SettersnGetters { | |
public static void main(String[] args) { | |
Bottle myBottle=new Bottle("Coke",600,300,"CocaCola","Black"); | |
System.out.println(); | |
System.out.println(myBottle.getName()); | |
System.out.println(myBottle.getColor()); | |
System.out.println(); | |
myBottle.setName("Aquafina"); | |
myBottle.setColor("Transparent"); | |
System.out.println(myBottle.getName()); | |
System.out.println(myBottle.getColor()); | |
System.out.println(); | |
System.out.println(myBottle.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment