Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your local supermarket is having a \"coupon bonanza\" this week, offering you in

ID: 3536989 • Letter: Y

Question

 Your local supermarket is having a "coupon bonanza" this week, offering you  incentives to come in and use all those coupons you have cut out of the paper.  Of course, they hope you will buy lots of other items while you are in the store -  but that does not concern us for this assignment!  The store offer is as follows: 1.    If the face value of the coupon is 35 cents or less:                the first 4 of these get triple value, any additional ones get double value. 2.    If the face value is over 35 cents but less than 51 cents, it gets double value -              no matter how many there are. 3.    If the face value is 51 cents or over but less than $1.00, it gets a value of $1.00. 4.    Any coupons of $1.00 or more, get their face value.  Your assignment is to read in a series of face values for coupons,  calculate and print the actual value of each one, total the actual value of all  of the valid coupons and count how many valid coupons were processed.   The maximum allowable face value of a coupon is $3.00.  Any data value above that  limit should cause an error message to be printed and the program should then  continue on to the next coupon.  Bad data must not be included in the count  of valid coupons.  More specifically, your program must read in a series of face values from a  data file that you have to create using the following data, and you should stop  the loop when you see a negative number:  0.43 0.28 0.74 0.32 3.01 0.50 1.24 0.35 0.99 3.00 0.16 0.21 0.36 0.51 1.00 0.17 -0.30 You should not be reading this line    ****************************************************** Your sample output should be something like: /* Output from program:  face value =0.43 value =0.86 face value =0.28 value =0.84 face value =0.74 value =1 face value =0.32 value =0.96 Bad input (value > $3.00) face value =0.5 value =1 .... etc. .........  ********************************************  number of coupons = 15 Total Value=14.91 Press any key to continue . . .
what is the source code?
what is the output?

Explanation / Answer

import java.io.File;
import java.util.Scanner;


public class FaceValue {

   public static void main(String[] args) throws Exception{

       Scanner scanner = new Scanner(new File("D:/data.txt"));

       int nCoupns =0;
       float total = 0;
       int n35le = 0;
       float faceValue = 0;
       float value = 0;
       while(scanner.hasNext()){
           faceValue = scanner.nextFloat();
           value = 0;
           if(faceValue < 0)
               break;
           else {
              
               if(faceValue <= 0.35) {
                   n35le++;
                   if(n35le <= 4)
                       value =   faceValue * 3;
                   else
                       value = faceValue * 2;
                      
               } else if(faceValue > 0.35 && faceValue < 0.51) {
                   value = faceValue * 2;
               } else if(faceValue >= 0.51 && faceValue < 1) {
                   value = 1;
               } else if(faceValue >= 1 && faceValue <=3) {
                   value = faceValue;
               }
               if(faceValue > 3)
                   System.out.println("Bad input (value > $3.00)");
               else {
                   System.out.println("face value = "+faceValue+" value = "+value );
                   nCoupns++;
               }
              
               total += value;
               faceValue = 0;
           }
      
       }
       System.out.println("number of coupons = "+nCoupns+" Total Value= "+total);
      
   }
}