Question
1. In the Walmart class, declare two instance variables, namely, total and count for calculating the total price and counting the number of items respectively.
1. In the Walmart class, declare two instance variables, namely, total and count for calculating the total price and counting the number of items respectively. Then, create a no-argument constructor and assign 0.0 to the total.
2. Create a function named totalPrice that takes as input two arrays for item names and their prices and updates the total price and number of items. For each item, please do the following:
(a) Create a local variable "newTotal" to compute the updated value of the total;
(b) Assign the value of newTotal to the total variable and increment the count variable;
(c) Print the the values of total and count.
3. Make the Cashier class a Thread class by implementing the Runnable interface. In the Cashier class, please do the following:
(a) Declare an object named "objWalmart" of type "Walmart" class as an instance variable;
(b) Declare a string variable "name" for the cashier's name;
(c) Define a parameterized constructor that takes as input string for the cashier's name and object of
type "Walmart" and assigns them to the respective instance variables;
(d) Override the run method in which you will create two arrays, namely an array for item names, and
an array for the item price for the desired number of items through the Scanner class, and
call the totalPrice function through the instance variable objWalmart.
4. In the main function, please do the following:
(a) Create an object of the Walmart class;
(b) Create two objects of the Cashier class using parameterized constructor in which you pass the
above instance of Walmart and the cashier's name for each of the instances, respectively;
(c) Create two threads for each Cashier object, and start both the threads.
5. For this problem, you need to submit a document named "Lastname_Solution" describing the problems encountered while running Lastname_Thread class and respective solutions according to the following:
(a) When you run the Lastname_Thread, describe the issues in a document named
"LastName_Solution" if you have any. Add your solution for (a) in the document "LastName_Solution" and
implement the solution.
(b) Do you face any other problems? If yes, describe the problem in the document "LastName_Solution".
(c) If you have encountered any other problem in (b), then add your solution to the document
"LastName_Solution" andimplement the solution
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started