Calling a method in java and returning beer cost

后端 未结 3 1673
轻奢々
轻奢々 2021-01-29 13:02

What I am supposed to do:

Add some necessary statements to the printOrderCost() method in the main class so that this method computes and p

3条回答
  •  囚心锁ツ
    2021-01-29 13:29

    From the code you have supplied, the getCost method "looks" fine

    Your toString method should simply need to be appended to your return String s

    public String toString()  // not necessary to format the output
    {
        String s;
        s = brand + " ";
        s += quantity + " " ;
        s += itemCost + " ";
        s += getCost();
        return s;
    }
    

    You might also like to take a look at NumberFormat, which will allow you to control the output format, just in case you get a funny looking value ;)

提交回复
热议问题