-
Super simple question
Hello, I am just confused by the wording of the question.
e) The OilTank class, below, includes six methods. Which ones can be used to change the state of an OilTank object?
Code:
public class OilTank{
private int capacity; // capacity of tank
private String who; // tank owner
private double price; // price per gallon of oil
private int quantity; // gallons of oil in tank
public OilTank(String who, int cap, double price, int quant){
this.who = who;
capacity = cap;
this.price = price;
quantity = quant;
}
public int getCapacity(){return capacity;}
public String getWho(){return who;}
public double getPrice(){return price;}
public int getQuantity(){return quantity;}
public void setQuantity(int amt){ quantity = amt;}
public void fillTank(){quantity = capacity; }
}
So I just said
public void setQuantity(int amt){ quantity = amt;}
public void fillTank(){quantity = capacity; }
public OilTank(String who, int cap, double price, int quant){
this.who = who;
capacity = cap;
this.price = price;
quantity = quant;
}
Is that what this is asking? Just want to make sure I am doing the right thing.
-
The state of an object is defined by it's fields -- what values do they hold? A method will change an object's state if it changes any one of these fields. So on quick glance, I think you have it right. Nice job.
edit: you are including the constructor in your list which isn't a method. I'd remove that.
-
dam fujaninja you are fast, i was just about to ans.
i agree, but the question ask for the six methods.
--"he OilTank class includes six methods."--
so i don't think the constructor counts, right?
-
Yeah I was confused whether it counted or not.