I was writing a program and I wasn't sure sure how to do letter b. I have the methods and constructor but I'm not sure how to format the float.

2. Create a class called Item.
a. Item will need instance variables itemID, itemName, inStore, and
Price (of types String, String, int and double accordingly).
b. Item will need appropriate methods and constructors. Make sure to have a
toString() method that prints the item, making sure to format the float to 2
decimal places with $.

This is what I have for the toString() method so far.

public String toString()
        return itemID + ": " + itemName + ", " + inStore + ", " + Price;

You can use the format method in the String class to convert stuff to String using printf-style formatting codes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.