Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class QA8308212 {
- protected static double capacity;
- protected double water;
- public QA8308212() {
- capacity = 100.;
- this.setWater(.0);
- }
- public void add(double water) {
- if (this.put(water)) { return; }
- System.out.println("OVERFLOW");
- }
- public double getWater() {
- return this.water;
- }
- protected boolean put(double water) {
- if (this.getWater() + water > capacity) {
- this.setWater(capacity);
- return false;
- }
- double addee = this.getWater();
- this.setWater(addee + water);
- return true;
- }
- protected void setWater(double water) {
- this.water = water;
- }
- @Override
- public String toString() {
- return "Tank: " + this.getWater();
- }
- public static void main(String[] args) {
- QA8308212 tank = new QA8308212();
- System.out.println(tank);
- tank.add(10.);
- System.out.println(tank);
- tank.add(20.);
- System.out.println(tank);
- tank.add(30.);
- System.out.println(tank);
- tank.add(100.);
- tank.add(200.);
- tank.add(300.);
- tank.add(400.);
- System.out.println(tank);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement