How to define the getPrice method in this subclass?
How to define the getPrice method in this subclass?
I am trying to determine how I should define the getPrice method. The shirts can range from Small to XXXL and the price varies. The price is determined by the size: $22.99 for XXL or XXXL, and $19.99 for all other sizes.
There are two other classes that I have complied. But the method I need help with only goes with this code.
public class TeeShirt
private int orderNumber;
private String size;
private String color;
private double price;
public void setOrderNumber(int num)
orderNumber = num;
public void setSize(String sz)
size = sz;
public void setColor(String color)
this.color = color;
public int getOrderNumber()
return orderNumber;
public String getSize()
return size;
public String getColor()
return color;
public double getPrice()
return price;
//end
Java is to Javascript as Pain is to Painting, or Ham is to Hampster. They are completely different. It is highly recommended that aspiring coders try to learn the name of the language they're attempting to write code in. When you post a question, please tag it appropriately.
– CertainPerformance
Sep 18 '18 at 3:26
@CertainPerformance Unless someone takes it upon himself to eat hampsters :-)
– Tim Biegeleisen
Sep 18 '18 at 3:26
What's a hampster?
– shmosel
Sep 18 '18 at 3:28
And where are you stuck?
– shmosel
Sep 18 '18 at 3:35
1 Answer
1
You could assign the price on your setSize()
function depending on size type.
setSize()
public void setSize(String sz)
size = sz;
if(size.equals("XXXL")
That works! Thank you!
– Nylah.
Sep 18 '18 at 3:43
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
What's the problem?
– shmosel
Sep 18 '18 at 3:25