LAB
EXERCISE 11: Sales Amount
Goal:
In this exercise, you will learn how to:
1. Insert the Main
Method (Main Entry Point to the Java Program)
2 Import a Java Class Library
3. Declare Variables
4. Create a Method which will return
data
5. Use the While Loop statement
to test the conditional expression BEFORE each iteration.
6. Use the Relational Operator in the While
conditional expression
7. Use an Increment Assignment Operator
8. Use a Running Total
9. Create an Object from the Class
10.Call the Object’s Method
Program
Specifications:
Description:
This program prompts the user to enter the daily sales amount from Monday (day
1) to Sunday (day 7). The daily sales
amount is accumulated using a running total.
The weekly sales total is then displayed on the console.
A. Pre-requisites:
1.
Create a folder on your desktop Exercise-11
2. Launch Java EE- Eclipse
Note: You will need to use the Java
Perspective Workbench for this exercise
3. Setup your Eclipse Workspace to point to the Exercise-11
folder
a. Select File-> Switch Workspace
b. Browse and select your Exercie-11 folder as your Workspace.
B. Requirements:
1. Create
a Java Project and name it as SalesAmount
2. Create
the first Class that will have the Main Method
a.
Name the Class as MainApp
b.
Choose the main method to insert into the
class
3. Create
the second Class that will have the Constructor and Methods
a.
Name the Class as Sales
b.
Do not select the main method stub
C. Requirements
for the Sales Class:
1. Insert
the import java.util.Scanner class
which will allow data to be inputted from the console.
2. a.
Declare the variable- salesDailyAmount
and salesTotal using the double data type
b. Declare the variable- day using the integer
data type and initialize to 1
3. Create
a Method called totalAmount () that will prompt the user to input the daily sales
amount from Monday (day 1) to Sunday (day 7), accumulate the total sales and
return the result.
a. Declare
the scanner input class objects - Scanner inputAmt = new Scanner(System.in)
b. Used
the While Loop to perform the following iteration:
1. Prompt the user to input the daily
sales amount
2. Accumulate the total sales using a
Running Total
3. Increment the day of the week.
4. Perform steps 1-3 until it reaches
day 7.
c.
Close the scanner input class object
d. Return
the salesTotal result to the calling object’s method.
D. Requirements for the MainApp Class:
1. Add
comments (documentation) – Program Description, Author and Date
2. Create
the instance of object called weeklyAmt
from the Sales class
3. Declare
totalAmt variable as double and assign the return value from
the weeklyAmt.totalAmount() object’s method
4. Display
the returned result on the console.
Below is the code you can copy and paste.
System.out.print("Total Weekly
Sales Amount: "); |
E. Test:
1. Save your Java code
2. Compile and run your Java program.
3. Verify there is no syntax, logical or run-time
errors.
4. Use the following set of test data to
determine if the application is calculating properly:
Day Sales
Amount
1 1500
2 2500
3 1000
4 3000
5 1550
6 3500
7 2550
Total Weekly Sales Amount:
$15,600.00
F. Submit your exercise in the Canvas Lab
Exercise #11 Drop Box.
1. Submit the screen shot of the Eclipse
Workbench window showing the Console output screen.
You can use Paint (save as JPG) or Word to paste the screenshot.
2. Zip up and submit the compressed SalesAmount subfolder that is in the Exercise-11
folder.
NOTE: Right click on the subfolder and select
Send to “Compress Folder”. The file will
have a file extension of .zip.