1. Complete the following tasks:

a) Design a class named ItemForSale that holds data about items placed for sale on Carlos’s List, a classified advertising website. Fields include an ad number, item description, asking price, and phone number. Include get and set methods for each field. Include a static method that displays the website’s motto (“Sell Stuff Locally!”). Include two overloaded constructors as follows:

• A default constructor that sets the ad number to 101, the asking price to $1, and the item description and phone number both to XXX

• A constructor that allows you to pass values for all four fields.

Create the class diagram and write the pseudocode that defines the class.

b) Design an application that declares two ItemForSale objects using a different constructor version with each object. Display each ItemForSale’s values and then display the motto.

2. Complete the following tasks:

a) Create a class named Meal that includes a string variable for the meal’s description, an array of strings that holds up to five of the Meal’s components (for example, “roasted chicken”, “mashed potatoes”, and “green beans”), and a numeric variable that holds the calorie count. Include a method that prompts the user for a value for each field. Also create two overloaded methods named display(). The first method takes no parameters and displays the Meal details. The second takes a numeric parameter that indicates how many of the Meal’s components to display, or an error message if the parameter value is less than 0 or more than 5.

b) Create an application that declares two Meal objects, sets their values, and demonstrates how both method versions can be called.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *