Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please 1. One of the basic functionalities provided by classes is that of storing multiple pieces of data which may have different data

In java please

1. One of the basic functionalities provided by classes is that of storing multiple pieces of data which may have different data types. In this exercise, you will construct a program that prompts a user for information regarding an order for a product. Once the order is complete, your program should then calculate the total cost of the order and report that information back to the user. To complete this program: In a file named Product.java , define a class named Product to store information related to the product the user wishes to order. The class should contain: o A String variable to store the products name o An integer variable to store the number of units of product the user wishes to order o A double variable to store the price of a single unit of the product o A double variable to store the total cost of the ordered products o Appropriate getter and setter methods for each variable o Also make sure that each variable is marked as private and the getter and setter methods as public to provide correct encapsulation In a file named OrderSystem.java , define a class named OrderSystem which will interact with the user to take in their order information. The class should contain: o A private method named calcTotal that returns nothing and take a Product object as a parameter. The method should calculate the total cost of the order using the information from the Product object and then store the total cost in the appropriate variable in the Product object. o Your main method, which should: Contain an instance of an Product object Prompt the user for the name of the product and the number of units they want to order of that product, and store that information in the Product object Set the price of the Product object to 9.99 Using the calcTotal method calculate and store the total price of the order in the Product object With an appropriate message, output to the user the full statement of their order including the product name, the number of units they wanted, the price of a single unit, and the total cost of their order. Be sure that all monetary values are output with a $ in front of the value and with exactly two decimal places of precision. Remember that if you want to compile the program from the command line, you will need to include both .java files when you use javac o javac OrderSystem.java Product.java Once you have successfully compiled the program from the command line, you only need to specify the .class file that contains your main method to execute the program with java o java OrderSystem Complete the program, making sure to compile and run it to verify that it produces the correct results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Are large frame sizes better than small frame sizes? Expain.

Answered: 1 week ago