Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Vusi Mbonani
Added: May 16, 2021 3:08 PM
Views: 476
Tags: no tags
  1. package salesfigures;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SalesFigures {
  6.     //Decalring a  Scanner Object.
  7.     static Scanner scan = new Scanner(System.in);
  8.  
  9.     public static void main(String[] args) {
  10.         //Declaring Local variables.
  11.           String name; //To hold the name of the sales person.
  12.           double salesAmount;  //To hold the sales amount.
  13.           double totalSalesAmount = 0;  //Running total.
  14.           double salesAverage = 0; //To hold the sales average amount.      
  15.           final int FINISH = -1; //Sentinel Value.
  16.           int counter = 0; //Counter loop variable.
  17.          
  18.           //Create a priming value to sructure the program.
  19.           System.out.print("Please enter salea person Name: ");
  20.           name = scan.nextLine();
  21.          
  22.           System.out.print("Press -1 EXIT OR Enter sales amount #"+ (counter)+": R" );
  23.           salesAmount = scan.nextDouble();
  24.          
  25.           //Defining an indefinite loop stopes by a sentinel.
  26.           while(salesAmount != FINISH){
  27.          
  28.               //Calculating the running  total.
  29.               totalSalesAmount+= salesAmount;
  30.              
  31.               //Calculate the average of a sales person.
  32.               salesAverage = totalSalesAmount/counter;
  33.              
  34.               //Counter loop increment.
  35.               counter++;
  36.          
  37.           }
  38.           //Diaplay the Total Amount and the Average Sales.
  39.           System.out.println("\n***************************");
  40.           System.out.println("SALES PERSON REPORT");
  41.           System.out.println("***************************");
  42.           System.out.println("SALES PERSON NAME:    "+name);
  43.           System.out.println("TOTAL SALES AMOUNT:   R"+totalSalesAmount);
  44.           System.out.println("AVERAGE SALES AMOUNT: R"+salesAverage);
  45.     }
  46.    
  47. }
  48.