In: Computer Science
I need this before the end of the day and in java please :)
10.12 Lab 9
In BlueJ, create a project called Lab9
A car dealership pays their salesmen a base salary every month. However, based on how many cars they sold (qtySold) they get a percentage of their salary as a bonus. To determine the percent bonus, the company uses the following chart.
qtySold | %Bonus |
---|---|
5 or less | 0% |
More than 5 but 10 or less | 5% |
More than 10 but 15 or less | 10% |
More than 15 | 15% |
Create a class called Employee as described in the following UML
Employee |
---|
- lastName: String - qtySold: int - basePay: double |
+Employee() +Employee(name: String, qtySold: int basePay: double) +setLastName(name: String):void +setQtySold(qtySold: int):void +setBasePay(basePay: double): void +getLastName(): String +getQtySold: int +getBasePay(): double +computePercentBonus(): int +calculatePay():double |
NOTE: test methods as you implement them
Create a text file using notepad. Save the text file in your Lab9 project folder and call it empData.txt. Copy the data below into the file. Save the file.
Tetzner 7 425.85 Martin 3 530.90 Smith 20 470.45 Jones 12 389.74 Glembocki 10 412.74
Create a class called Main
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException;
System.out.printf("%-10s%8s%10s%8s%12s%n", "Name","Qty Sold","Base Pay","%Bonus","Total Pay");
When you are done, upload the Employee class and the Main class to zybooks and submit it.
Sample Output
Name Qty Sold Base Pay %Bonus Total Pay Tetzner 7 425.85 5 447.14 Martin 3 530.90 0 530.90 Smith 20 470.45 15 541.02 Jones 12 389.74 10 428.71 Glembocki 10 412.74 5 433.38 The company paid out a total of $2381.15 this week Top seller this week sold 20 cars
Note :
We have to paste the input file in the project folder so that our program can able to detect.
If we didnt placed the input file in the project folder we will get FileNotFoundException.
Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================
=================================
// empData.txt (Input file)
Tetzner 7 425.85
Martin 3 530.90
Smith 20 470.45
Jones 12 389.74
Glembocki 10 412.74
================================
// Employee.java
package org.students;
public class Employee {
private String lastName;
private int qtySold;
private double basePay;
public Employee() {
}
/**
* @param lastName
* @param qtySold
* @param basePay
*/
public Employee(String lastName, int qtySold, double
basePay) {
this.lastName = lastName;
setQtySold(qtySold);
setBasePay(basePay);
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the qtySold
*/
public int getQtySold() {
return qtySold;
}
/**
* @param qtySold
* the qtySold to set
*/
public void setQtySold(int qtySold) {
if (qtySold < 0)
this.qtySold =
0;
else
this.qtySold =
qtySold;
}
/**
* @return the basePay
*/
public double getBasePay() {
return basePay;
}
/**
* @param basePay
* the basePay to set
*/
public void setBasePay(double basePay) {
if(basePay<0)
{
this.basePay =
0;
}
else
this.basePay = basePay;
}
public int computePercentBonus()
{
int bonus = 0;
if (qtySold <= 5) {
bonus = 0;
} else if (qtySold > 5
&& qtySold <= 10) {
bonus = 5;
} else if (qtySold > 10
&& qtySold <= 15) {
bonus =
10;
} else if (qtySold > 15) {
bonus =
15;
}
return bonus;
}
public double calculatePay() {
double totAmount = 0.0;
totAmount = basePay
+ (basePay * ((double) computePercentBonus() /
100));
return totAmount;
}
}
=========================================
=========================================
// Test.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// Declaring variables
String filename="empData.txt";
String name,line;
int qtySold,bonus,max=0;
double basePay,total,overallTotal=0.0;
Scanner sc=null;
try {
// Opening the input file
sc=new
Scanner(new File(filename));
System.out.printf("%-10s%8s%10s%8s%12s%n", "Name","Qty Sold","Base
Pay","%Bonus","Total Pay");
// This loop
will read the data until the end of the file
while(sc.hasNext())
{
line=sc.nextLine();
String arr[]=line.split(" ");
name=arr[0];
qtySold=Integer.parseInt(arr[1]);
if(max<qtySold)
{
max=qtySold;
}
basePay=Double.parseDouble(arr[2]);
// Create an instance of Employee class
Employee e=new Employee(name, qtySold,
basePay);
bonus=e.computePercentBonus();
total=e.calculatePay();
overallTotal+=total;
// Displaying the output
System.out.printf("%-10s%8d%10.2f%8d%12.2f\n",
name,qtySold,basePay,bonus,total);
}
sc.close();
System.out.printf("The company paid out a total of $%.2f this
week\n",overallTotal);
System.out.printf("Top seller this week sold %d cars ",max);
} catch (FileNotFoundException e)
{
System.out.println(e);
}
}
}
=========================================
=========================================
Output:
=====================Could you plz rate me well.Thank You