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

A furniture company pays its sales people on a commission basis. The sales peopl

ID: 3664955 • Letter: A

Question

A furniture company pays its sales people on a commission basis. The sales people will receive $200.00 per week plus percentage of their gross sales for that week. For example, a salesperson who grosses $5000.00 in sales in a week receives $200.00 plus 9% of $5000.00, (200 + 0.09 * 5000 = 200 + 450 = $650.00).

Input file, sales.txt shown in left

*******Write a java application named sales.java using only concepts learned in chapters 1 to 6. You are given an input file (sales.txt) containing the sales people and their gross sale for one week. Use EOF controlled while loop in your program (See pages 268-269 for an example).

Declare the needed variables. The base salary of $200 and percentage rates must be declared as constants in the program.

The commission percentage rate of salesperson is based on gross sales in a week. (Refer the table for commission rates.) Each salesperson achieves a particular tier based on the net sales per week. This is available in the table - Tiers of sales person based on their net sales per week.

Read the data from input file and write the information to console with formatting as shown below. [Sales person is left justified and all numbers are right justified.

********* SAMPLE OUTPUT*************************IS ATTACHED ALONG WITH TEXT FILE

Tiers of sales person based on their net sales per week.

Tier

Net sales per week

1

Greater than 1000.00

2

Greater than 500 and less than or equal to 1000

3

Last tier

Table shows the commission rates based on gross sales per week

Gross sales

Percentage

Greater than 5000

9

Greater than 3000 and less than or equal to 5000

6

Greater than 2000 and less than or equal to 3000

4

Tier

Net sales per week

1

Greater than 1000.00

2

Greater than 500 and less than or equal to 1000

3

Last tier

Gales Furniture Store NetPerWeek Tier SalesPerson Sam Susan Kelly Yolanda Pete Paul Mark Luke Ron David Claire GrossPerWeek 6500.00 4250.75 15950.25 8879.35 6543.89 7931.90 17650.00 9821.00 6299.75 8573.99 2500.25 785.00 455.04 1635.52 999.14 788.95 913.87 1788.50 1083.89 766.98 971.66 350.02 2 3 1 2 2 2 1 1 2 3

Explanation / Answer

package com.he.capillary;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class Sales {

   private static String space = " ";
   private static DecimalFormat df2 = new DecimalFormat("00.00");
   private static double baseSalary = 200d;

   public static void main(String[] args) {
       try {
           Sales st = new Sales();
           st.calculateSales("/home/coder/mygit/tally/src/main/java/com/he/capillary/sale.txt");
       } catch (Exception exception) {
           System.out.println("File Not found.");
       }
   }

   /**
   * This will accept file and calculate data
   * @throws FileNotFoundException
   * @throws IOException
   */
   private void calculateSales(String fileName) throws FileNotFoundException, IOException {
       BufferedReader br = new BufferedReader(
               new FileReader(fileName));
       String line = br.readLine();
       String str[] = new String[2];
       List<Sale> saleList = new ArrayList<Sale>();
       while (line != null) {
           str = line.split(" ");
           Sale sale = new Sale();
           sale.setSalePerson(str[0].trim());
           sale.setGrossPerWeak(Double.parseDouble(str[1]));
           int percentage = getPercentage(sale.getGrossPerWeak());
           sale.setNetPerWeek(baseSalary + sale.getGrossPerWeak() * percentage / 100.0);
           sale.setTier(getTier(sale.getNetPerWeek()));
           saleList.add(sale);
           line = br.readLine();
       }
       printTabular(saleList);
   }

   public void printTabular(List<Sale> saleList) {
       StringBuilder sb = new StringBuilder();
       sb.append("SalesPerson" + space + "GrossPerWeek" + space + "NetPerWeek" + space + "Tier ");
       if (saleList != null && saleList.size() > 0) {
           for (Sale sale : saleList) {
               sb.append(sale.getSalePerson() + space + df2.format(sale.getGrossPerWeak()) + space
                       + df2.format(sale.getNetPerWeek()) + space + sale.getTier() + " ");
           }
       }
       System.out.println(sb.toString());
   }

   private int getPercentage(double amount) {
       if (amount > 5000) {
           return 9;
       } else if (amount <= 5000 && amount > 3000) {
           return 6;
       } else if (amount <= 3000 && amount > 2000) {
           return 4;
       }
       return 0;
   }

   private int getTier(double amount) {
       if (amount > 1000) {
           return 1;
       } else if (amount <= 1000 && amount > 500) {
           return 2;
       } else if (amount <= 500) {
           return 3;
       }
       return 0;
   }

   static class Sale {
       private String salePerson;
       private double grossPerWeak;
       private double netPerWeek;
       private int tier;

       public String getSalePerson() {
           return salePerson;
       }

       public void setSalePerson(String salePerson) {
           this.salePerson = salePerson;
       }

       public double getGrossPerWeak() {
           return grossPerWeak;
       }

       public void setGrossPerWeak(double grossPerWeak) {
           this.grossPerWeak = grossPerWeak;
       }

       public double getNetPerWeek() {
           return netPerWeek;
       }

       public void setNetPerWeek(double netPerWeek) {
           this.netPerWeek = netPerWeek;
       }

       public int getTier() {
           return tier;
       }

       public void setTier(int tier) {
           this.tier = tier;
       }

       @Override
       public String toString() {
           return "Sale [salePerson=" + salePerson + ", grossPerWeak=" + grossPerWeak + ", netPerWeek=" + netPerWeek
                   + ", tier=" + tier + "] ";
       }

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote