Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will create an invoice for a customer order based on their requests. Your program should prompt the user for their requested



Write a program that will create an invoice for a customer order based on their requests. Your program should prompt the user for their requested items based on a stock number then store the associated information in an array to be displayed in the invoice.


  1. Define a Java class as described below.All variables should be declared as private and all methods as public.Save the class definition in a file with an appropriate filename.

Class Name: Inventory


Instance Variables: itemName- String

price- double

quantity - integer


Instance Methods:Adefault constructor


Aconstructorthat accepts three arguments, one for each of the fields.


gettermethods for each of the class fields.


toString()A method to display the fields of an instance of the class in to be displayed on the order sheet.


Compile and debug the above code.


  1. Then, create a class,TestInventory that contains amain() with static methods to create an invoice using the above class. Save the class in a file with an appropriate file name.
  • Declare four initialized arrays, one for the Stock Number, and three associated arrays for the Item Name, Price and Quantity. Initialize the Item Name array with your own String values:


Stock Number

Item Name

Price

Quantity

0372


$2.79

68

1596


13.50

12

2117


7.52

29

4580


30.42

40

8529


16.58

6


  • Create a method that will prompt the user for the number of items the user wishes to order and create an order array that will store instances of the Inventory class.
  • Using the arrays, create a static method that will populate the above array with the items ordered by the user. This method should:

-promptuser for the requested stock number and quantity of items to purchase;

-using a loop, search the Stock Number and Quantity arrays for a valid order

(Your program should handle invalid stock numbers and quantities entries and prompt the user fora new entry.)

- update the Quantity array to reflect the decreased available amount

- extract the corresponding item name and price;

-instantiate an instance of the Inventoryobject and insert it into the orderarray.

  • Call a static method to create an order invoice displaying the contents of theorderarray using thetoStringinstance method. The invoice should also display the extended price of the items along with a final total


Compile and execute the program. Check your output!!

Instructions for your tutor:

The Array, ArrayList or List class may not be used to complete this. Please comment on your progress so i can understand what to do

Step by Step Solution

3.45 Rating (164 Votes )

There are 3 Steps involved in it

Step: 1

First lets create the Inventory class public class Inventory private String itemName private double price private int quantity Default constructor pub... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing A Practical Approach with Data Analytics

Authors: Raymond N. Johnson, Laura Davis Wiley, Robyn Moroney, Fiona Campbell, Jane Hamilton

1st edition

1119401747, 978-1119401742

More Books

Students also viewed these Programming questions