Copyright © 2022 Bambang A.B. Sarif Page 1 of 3
CSIS 3280 Assignment 1: A Simple Console App
Create a PHP file following the naming convention and PHP standard recommendation (see the work submission guideline document) |
AssignmentTutorOnline
You are required to write a simple console application to record customer order of three product items, calculate
its subtotal, discount percentage and its final cost. Note that the customers’ order amount for each product are
generated randomly, and the user can choose to re-run the apps for several time. You need to define some
constant and create some functions as stated in the requirement below. You must follow the good programming
practices as we have in the class.
Requirement
1. You need to define the following constants in inc/config.inc.php
• The number of customer: 4
• The app developer: your name
• The app ID: your student ID
• The min amount: 0 (to generate the random item amount)
• The max amount: 5 (to generate the random item amount)
• The item cost: 50
2. Declare the following arrays in inc/config.inc.php
• item price array with values: 40, 60, 80 (this is the price of item A, B and C)
• discount threshold associative array with the following keys and values
key | value |
0 | 0 |
200 | 0.05 |
250 | 0.1 |
375 | 0.15 |
600 | 0.25 |
3. Create the following functions:
• displayHeader() – This will display the app header (see figures below)
• generateOrder() – This will prompt the user to enter the customers’ id. Each customer will have the
record of order amount for the three items. The amount order for each item is generated randomly
between the min and max amount using rand(). The customer order data is stored as an array of
associative arrays with the following structure
index | member |
key | value |
id | Obtained from input |
amount | An array of 3 generated order amounts |
For example, the first customer will have an index of 0. Suppose that his id (obtained from input) is
12qw and his order amount is 2, 0, and 5. Therefore, his data is stored as follow, assuming the variable
name is orderData: $orderData[0][‘id’] = ‘12qw’, $orderData[0][‘amount’] = array(2, 0, 5). Note that
the values 2, 0 and 5 are example values that should be generated randomly. This method will return
the generated array to the main file.
Copyright © 2022 Bambang A.B. Sarif Page 2 of 3
Hint: Think about creating an array of array of array. The outermost array is a normal array and within
it is is an associative array. Furthermore, one of the member of the associative array is another normal
array. You can achieve this by starting with empty array, loops and array_push() to generate the record.
• calculateAndPrintOrder($orderData, $price, $discountThreshold) – This function will calculate the
subtotal cost of the order according to the $price array, find out the discount percentage through
getDiscountPercentage($subTotal, $discountThreshold), calculate the final cost and display the
customers’ records (see the figures). The subtotal is calculated as the sum of (amount[0] * price[0])
+ (amount[1] * price[1]) + (amount[2] * price[2]). Note that the amount is the customer
order amount, for example $orderData[$i][‘amount’], with $i is the index of the order data array, and
$price is the price of each corresponding item you declared in the config.inc.php file. The final cost for
each customer is calculated as sub total * (1 – discount percent)
• getDiscountPercentage($subTotal, $discountThreshold) – This function will return the discount
percentage for the associated $subTotal using the associative array $discountThreshold you defined
in the config.inc.php. Hint: you should use foreach loop to loop through the array and use break to get
the correct discount percentage.
4. Each run of the application will be notified by a counter (see the figures below)
5. The app will ask the user whether he/she wants to re-run the app again or not. If the user chose to re-run
the app, the process will be repeated. Otherwise a thank you message will be displayed.
Figure 1. First run of the app
displayHeader()
Your name and student ID displayed
from the defined constant
The first run of the
app is notified here
Displayed in
two decimals
Notice the difference
between this display and the
requirement number 2 above
Customers’ subtotal
and discount
percentage are
calculated. Their total
cost is determined,
and their record is
displayed
generateOrder()
Notice that it will ask the user to
enter customer id. After each id
is entered, his/her order amount
will be randomly generated.
Copyright © 2022 Bambang A.B. Sarif Page 3 of 3
Figure 2. An example output for a user continue Running the app three times. The figure shows the second and
third execution. Note the user can run the app as many as he/she wants..
LAB/ASSIGNMENT PRE-SUBMISSION CHECKLIST • Did you follow the naming convention for your files?! • Did you follow the naming convention for your folder?! • Does your submission work on another computer?! • Double check **before** submitting |
Copyright © 2022 Bambang A.B. Sarif and others. NOT FOR REDISTRIBUTION. STUDENTS FOUND REDISTRIBUTING COURSE MATERIAL IS IN VIOLATION OF ACAMEDIC INTEGRITY POLICIES AND WILL FACE DISCIPLINARY ACTION BY THE COLLEGE ADMINISTRATION |
The third run of the
app is notified here
The user does not
want to continue
The number of times
the app was run is
displayed with thank
you message
Continue from
Figure 1
Can accept capital or
lower case letter
- Assignment status: Already Solved By Our Experts
- (USA, AUS, UK & CA PhD. Writers)
- CLICK HERE TO GET A PROFESSIONAL WRITER TO WORK ON THIS PAPER AND OTHER SIMILAR PAPERS, GET A NON PLAGIARIZED PAPER FROM OUR EXPERTS
