You have been commissioned by the Quick-Shop supermarket chain to write a progra
ID: 3816300 • Letter: Y
Question
You have been commissioned by the Quick-Shop supermarket chain to write a program that will
determine the retail price of at most 100 given items. Your program should ask the user to specify the
number of items (between 1 and 100).
Their pricing policy is that any item that is expected to sell in one week or less is marked up to 5
percent, and any item that is expected to stay on the shelf for more than one week is marked up 10
percent over the wholesale price. Be sure to notice that the low markup of 5 percent is used for up to
7 days and that at 8 days the markup changes to 10 percent.
Requirements:
Use a constant which represents the initial size of array (which is 100) and name it as INITIAL_SIZE.
The literal number 100 must not occur anywhere else in the program – wherever the size 100 is
needed, it must be obtained through the INITIAL_SIZE constant.
Use a variable which represents the actual size of array and name it as actual_size.
The 5 percent and 10 percent marked ups should be used as constants.
You will need three different arrays, one holding the wholesale price of the items (name it as cost)
, one holding the expected number of days until the item is sold for different items (name it as turnover) and the last one is responsible to hold the retail price of the items (name it as price).
The program must contain the following functions:
Function welcome which writes the description of the program on screen.
Function get_input is responsible to ask the user to specify for how many items (up to 100) this
program should calculate the retail price. It is also responsible to get the input for the wholesale
price of the items and the expected number of days until the item is sold.
Function retail_price is responsible to calculate the retail price of the items based on the company
policy.
Function print_output is responsible to print the wholesale price of item, the expected number of days until the item is sold, and the retail price for all items in a nice and readable format.
These four functions will be called inside the main function.
Explanation / Answer
public class MyQuickSort {
private int array[];
private int length;
public void sort(int[] inputArr) {
if (inputArr == null || inputArr.length == 0) {
return;
}
this.array = inputArr;
length = inputArr.length;
quickSort(0, length - 1);
}
private void quickSort(int lowerIndex, int higherIndex) {
int i = lowerIndex;
int j = higherIndex;
while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (array[j] > pivot) {
j--;
}
if (i <= j) {
exchangeNumbers(i, j);
//move index to next position on both sides
i++;
j--;
}
}
if (lowerIndex < j)
quickSort(lowerIndex, j);
if (i < higherIndex)
quickSort(i, higherIndex);
}
private void exchangeNumbers(int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
public static void main(String a[]){
MyQuickSort sorter = new MyQuickSort();
int[] input = {24,2,45,20,56,75,2,56,99,53,12};
sorter.sort(input);
for(int i:input){
System.out.print(i);
System.out.print(" ");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.