Skip to content

Instantly share code, notes, and snippets.

@borncorp
Last active August 29, 2015 14:02
Show Gist options
  • Save borncorp/d30e5199085e9cb3303b to your computer and use it in GitHub Desktop.
Save borncorp/d30e5199085e9cb3303b to your computer and use it in GitHub Desktop.
SettersnGetters
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;
}
}
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