Part (1) Create a class named Item, that includes two private members: Type (String), and Price(double). The Item class should also include: one set method, two get methods and default constructor to initialize Type to “None” and Price to 0.0. Part (2) Write a static method named findAvg that takes as parameter an array of type Item. The method should find and output the average price of all items in the array. The method prototype is: public static void findAvg (Item [] list) Write the main method to do the following: Declare an array of type Item of size 5; Ask the user to enter type and price for each item in the array Call the findAvg method to output the average price of all items.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Part (1)
Create a class named Item, that includes two private members: Type (String), and Price(double). The Item class should also include: one set method, two get methods and default constructor to initialize Type to “None” and Price to 0.0.
Part (2)
- Write a static method named findAvg that takes as parameter an array of type Item. The method should find and output the average price of all items in the array. The method prototype is:
public static void findAvg (Item [] list)
- Write the main method to do the following:
- Declare an array of type Item of size 5;
- Ask the user to enter type and price for each item in the array
- Call the findAvg method to output the average price of all items.
Step by step
Solved in 3 steps with 2 images