Question: JAVA Implement the shop class Details Shop Class: the constructor in the Shop class sets name (one word) and initializes the revenue to 0. The
JAVA
Implement the shop class
Details
Shop Class: the constructor in the Shop class sets name (one word) and initializes the revenue to 0. The Shop toString method returns the name of the restaurant and the revenue. The toString methods should print to 2 decimal places.
To control the format for decimals in the toString method, you can use the DecimalFormat class (import java.text.DecimalFormat)
Here is an example of how it works:
public String toString() { //assume you are print some calculation value [value] that has several decimal places and you //want it to print only 2 decimal places DecimalFormat df = new DecimalFormat("#.00"); //give it the format return "Value is : " + df.format(value); //changes double value to have 2 decimal places } Write a demo program, that will use a Scanner to read the attributes to create a Shop object (name), and then print the Shop object.
Input
Example Input: HalifaxShop
Output
Example Output: HalifaxShop Revenue: $ 0.00
shop $$ revenue: double //total sales name : String Shop (name: String) + getName ():String +getRevenue (): double + setRevenue (s: double) : void + setName (n : String) : void toStringO:StringStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
