(Java) Please include one data type class and one driver class in the program. P
ID: 3708038 • Letter: #
Question
(Java) Please include one data type class and one driver class in the program. Please also include a UML diagram and pseudocode.
B. REQUIREMENT STATEMENT THIS LAB REQUIRES OBJECT ORIENTED PROGRAMMING. YOU HAVE TO CREATE ONE DATA TYPE CLASS AND ONE DRIVER CLASS (include main) One company request an application that allows users to READ from the keyboard the information of a vendor: name (String), id (String), sale amount in the month (double) then calculate the salary of vendors based on the sale amount in the month to get base salary, commission or bonus: Commission Bonus AMOUNT OF SALE PER MONTH 0 to 20,000 20,000 to 30,000 Base salar 2500 3.5% on extra sales beyond 20,000 4.2% on extra sales beyond 20,000 2500 2% on any sales beyond greater than $30000 2500 30,000 The salary of a vendor in the month will be: Salary base salary + commission +bonus The output should be Vendor Name Vendor ID Total sale Base Salary: Commission Bonus: Total Amount made Smith Crystal 12345 32254 2500 504.67 45.08 3049.75Explanation / Answer
Vendor.java
import java.util.Scanner;
public class Vendor {
//Declaring instance variables
private String id;
private String name;
private double saleAmount;
private double baseSalary;
private double commission;
private double bonus;
//Zero argumented constructor
public Vendor() {
}
//Parameterized constructor
public Vendor(String id, String name, double saleAmount) {
this.id = id;
this.name = name;
this.saleAmount = saleAmount;
}
// getters and setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSaleAmount() {
return saleAmount;
}
public void setSaleAmount(double saleAmount) {
this.saleAmount = saleAmount;
}
//This function will read the data entered by the user
public void readData()
{
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.print("Enter Name :");
this.name = sc.nextLine();
System.out.print("Enter Id :");
this.id = sc.next();
System.out.print("Enter Total Sale :");
this.saleAmount = sc.nextDouble();
}
//This function will perform calculations and display the vendor data
public void displayVendorInfo() {
// calculating the basesalary,commisssion,bonus
if (saleAmount >= 0 && saleAmount < 20000) {
baseSalary = 2500;
commission = 0;
bonus = 0;
} else if (saleAmount >= 20000 && saleAmount < 30000) {
baseSalary = 2500;
commission = 0.035 * (saleAmount - 20000);
bonus = 0;
} else if (saleAmount >= 30000) {
baseSalary = 2500;
commission = 0.042 * (saleAmount - 20000);
bonus = 0.02 * (saleAmount - 30000);
}
// calculating the total Amount
double totAmt = baseSalary + commission + bonus;
System.out.println(" ------------------------");
System.out.println("Vendor Name: " + name);
System.out.println("Vendor ID: " + id);
System.out.println("Total Sale: " + saleAmount);
System.out.println("Base Salary: " + baseSalary);
System.out.printf("Commission: %.2f ",commission);
System.out.printf("Bonus: %.2f ",bonus);
System.out.printf("Total Amount: %.2f ",totAmt);
System.out.println("------------------------");
}
}
________________
Test.java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//Creating an instance of Vendor class
Vendor v = new Vendor();
//calling the methods on the Vendor class
v.readData();
v.displayVendorInfo();
}
}
_________________
Output:
Enter Name :Kane Williams
Enter Id :12345
Enter Total Sale :32254
------------------------
Vendor Name: Kane Williams
Vendor ID: 12345
Total Sale: 32254.0
Base Salary: 2500.0
Commission: 514.67
Bonus: 45.08
Total Amount: 3059.75
------------------------
________________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.