Question

In: Computer Science

A certain store gives its customers a discount on the goods they buy based on a...

A certain store gives its customers a discount on the goods they buy based on a peculiar manner.

The discount percentage is equal to each customer's remainder of weight to age, weight % age.

The maximum discount percentage allowed is 10.

If the remainder is greater than 10, the discount percentage is recomputed as the remainder of 10.

For example, a customer whose weight is 175 lbs and age 61, buys an item costing $60.97. The discount percentage = 175 % 61 = 53. As 53 is greater than 10, the discount percentage is recomputed as 53 % 10 = 3 percent.

Therefore, the discount amount is 0.03(60.97) = $1.83.

Write a class file called lastname_discount.java. Write methods to compute and return the discount percentage, the discount amount for each customer and the sum of all the discount amounts.

Write a demo file called lastname_discount_demo.java. Add two integer arrays containing the weight and age of customers and a double array containing the cost of goods (any number of customers greater than 10). Write an object to pass the three arrays into the class file and print the information returned by the three methods specified in the previous paragraph.

Extend the story line as you like (any reasonable) by clearly defining what it is. Add a fourth method (type your creation as a comment above the fourth method). Print the results of this fourth method below the first three outputs.

Solutions

Expert Solution

Short Summary:

  • Implemented discount and demo class.
  • Implemented another method to print customer details who gets high discount amount.

Source Code:

lastname_discount.java File:


public class lastname_discount {  
   private int[] weights;
   private int[] ages;
   private double[] costs;
  
   private double[] discounts;
  
   /**
   * @param weights
   * @param ages
   * @param costs
   */
   public lastname_discount(int[] weights, int[] ages, double[] costs) {
       this.weights = weights;
       this.ages = ages;
       this.costs = costs;
       this.discounts = new double[costs.length];
       calculateDiscounts();
   }
  
   /**
   * Calculate discounts for each customer and store in a double array
   */
   private void calculateDiscounts() {
       for(int index = 0; index < weights.length; index++) {
           int remainder = (weights[index] % ages[index]) % 10;
           discounts[index] = remainder;
       }
   }
  
  
   /**
   * @param index - customer index
   * @return discount percentage for the corresponding customer
   */
   public double getCustomerDiscountPercentage(int index) {
       return discounts[index];
   }
  
   /**
   * @param index - customer index
   * @return discount amount for the corresponding customer
   */
   public double getCustomerDiscountAmount(int index) {
       return costs[index] * discounts[index] / 100;
   }
  
   /**
   * @return sum of discounts of all customers
   */
   public double sumOfAllDiscountsAmount() {
       double sum = 0;
       for(int index = 0; index < discounts.length; index++) {
           sum += discounts[index] * costs[index];
       }
       return sum;
   }
  
   /**
   * Prints the customer details who gets highest discount amount
   */
   public void printHighDiscountCustomer() {
       int highIndex = 0;
       for(int index = 0; index < discounts.length; index++) {
           // if customer gets high amount than previous highest
           if (getCustomerDiscountAmount(index) > getCustomerDiscountAmount(highIndex)) {
               highIndex = index;
           }
       }
       // Print the customer details for highIndex
       System.out.println("Customer Weight: " + weights[highIndex]
               + ", Age: " + ages[highIndex] + ", Cost of goods: $" + costs[highIndex]
               + ", Discount Percentage: " + getCustomerDiscountPercentage(highIndex) + "%"
               + ", Discount Amount: $ " + getCustomerDiscountAmount(highIndex));
   }  
}

lastname_discount_demo.java File:
public class lastname_discount_demo {

   public static void main(String[] args) {
       // Weights array
       int[] weights = {175, 160, 190, 154, 100, 139, 123, 165, 138, 125};
       // Ages array
       int[] ages = {61, 45, 56, 30, 23, 45, 65, 25, 30, 34};
       //Costs array
       double[] costs = {60.97, 50.00, 56, 78.90, 56.78, 34.67, 67, 87.56, 56.89, 45.78 };
      
       lastname_discount discounts = new lastname_discount(weights, ages, costs);
      
       //Print the details of customer
       System.out.printf("%10s %10s %10s %20s %20s\n", "Weight", "Age", "Cost($)", "Discount(%)", "Discount Amount($)");
       for(int index = 0; index < weights.length; index++) {
           System.out.printf("%10d %10d %10.2f %20.2f %20.2f\n", weights[index], ages[index],
                   costs[index], discounts.getCustomerDiscountPercentage(index),
                   discounts.getCustomerDiscountAmount(index));
       }
      
       System.out.println("\n\nCustomer details who gets more discount amount:");
       discounts.printHighDiscountCustomer();

   }

}

Sample Run:

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

**************************************************************************************


Related Solutions

A certain retail store bases its staffing on the number of customers that arrive during certain...
A certain retail store bases its staffing on the number of customers that arrive during certain time slots. Based on prior experience this store expects 32% of its customers between 8:00 am and 12:00 pm; 21% of its customers between 12:00 pm and 4:00 pm; 35% of its customers between 4:00 pm and 8:00 pm; and 12% of its customers between 8:00 pm and midnight. On a certain day, the store had 214, 198, 276, and 134 customers in those...
A store has issued two different coupons for its customers to use. One coupon gives customers...
A store has issued two different coupons for its customers to use. One coupon gives customers $25 off their purchase price, and the other coupon gives customers 35% off of their purchase. The store allows customers to use both coupons and choose which coupon to apply first. For this context, ignore sales tax. Let f be the function that inputs a cost (in dollars) and outputs the cost after applying the "$25 off" coupon, and let g be the function...
The Schmedley Discount Department Store has approximately 300 customers shopping in its store between 9 A.M....
The Schmedley Discount Department Store has approximately 300 customers shopping in its store between 9 A.M. and 5 P.M. on Saturdays. In deciding how many cash registers to keep open each Saturday, Schmedley’s manager considers two factors: customer waiting time (and the associated waiting cost) and the service costs of employing additional checkout clerks. Checkout clerks are paid an average of $8 per hour. When only one is on duty, the waiting time per customer is about 10 minutes (or...
Lee Ltd delivers the goods to customers and gives the customers the right to return the...
Lee Ltd delivers the goods to customers and gives the customers the right to return the product with no reason within 14 days after delivery. 1st May 20X9, goods were sold and delivered to a customer. The price charged was equal to the cost of $200 plus a 20% profit margin. According to the historical data, a significant amount of goods were returned within 14 days after delivery. Please ignore the GST. Required: (Please label your responses as 1), 2).)...
A sporting goods store believes the average age of its customers is 35 or less. A...
A sporting goods store believes the average age of its customers is 35 or less. A random sample of 42 customers was​ surveyed, and the average customer age was found to be 39.2 years. Assume the standard deviation for customer age is 9.0 years. Using alphaαequals=0.10 complete parts a and b below. a. Does the sample provide enough evidence to refute the age claim made by the sporting goods​ store? Determine the null and alternative hypotheses. Upper H 0H0​: muμ...
A discount specialty foods store sells many varieties of baked goods and wheat-based crackers and snacks....
A discount specialty foods store sells many varieties of baked goods and wheat-based crackers and snacks. It has recently noticed the growing popularity of a snack made of potatoes and lentils. It has also received a growing number of inquiries regarding gluten-free products, of which it has very few. The company is considering whether to introduce more gluten-free baked goods and snacks into both its own product line and its stock. 1. How should the company go about sampling its...
A program was created to randomly choose customers at a clothing store to receive a discount....
A program was created to randomly choose customers at a clothing store to receive a discount. The program claims 22% of the receipts will get a discount in the long run. The owner of the clothing store is skeptical and believes the program's calculations are incorrect. He selects a random sample and finds that 17% received the discount. The confidence interval is 0.17 ± 0.05 with all conditions for inference met. Part A: Using the given confidence interval, is it...
A program was created to randomly choose customers at a shoe store to receive a discount....
A program was created to randomly choose customers at a shoe store to receive a discount. The program claims 15% of the receipts will get a discount in the long run. The manager of the shoe store is skeptical and believes the program's calculations are incorrect. She selects a random sample and finds that 12% received the discount. The confidence interval is 0.12 ± 0.05 with all conditions for inference met. Part A: Using the given confidence interval, is it...
A program was created to randomly choose customers at a clothing store to receive a discount....
A program was created to randomly choose customers at a clothing store to receive a discount. The program claims 22% of the receipts will get a discount in the long run. The owner of the clothing store is skeptical and believes the program's calculations are incorrect. He selects a random sample and finds that 17% received the discount. The confidence interval is 0.17 ± 0.05 with all conditions for inference met. Part A: Using the given confidence interval, is it...
For customers purchasing a refrigerator at a certain appliance store, let A be the event that...
For customers purchasing a refrigerator at a certain appliance store, let A be the event that the refrigerator was manufactured in the U.S., B be the event that the refrigerator has an icebreaker, and the event that the customer purchased an extended warranty. Relevant probabilities are: P(A) = 0.70 P(B|A) = 0.85 P(B|A ′ ) = 0.75 P(C|A ∩ B) = 0.75 P(C|A ∩ B′ ) = 0.5 P(C|A′ ∩ B) = 0.6 P(C|A′ ∩ B′) = 0.25 b. What...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT