Results 1 to 4 of 4
  1. #1
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

    Default 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?

    Java 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.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  4. #4
    jigglywiggly is offline Senior Member
    Join Date
    Nov 2008
    Posts
    105
    Rep Power
    0

Similar Threads

  1. Simple question about access
    By tortelini in forum New To Java
    Replies: 6
    Last Post: 09-06-2008, 05:41 PM
  2. Simple Method Question
    By Froz3n777 in forum New To Java
    Replies: 2
    Last Post: 02-13-2008, 02:39 AM
  3. Simple append question
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-20-2007, 11:40 PM
  4. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 01:27 AM
  5. Simple question of JTable
    By carl in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •