Question

In: Computer Science

I need this before the end of the day and in java please :) 10.12 Lab...

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

  • Constructor with no arguments – does nothing – open and close brace
  • Set methods (mutators) set the field to the new values passed in to it
    • setLastName – sets field to the value passed in
    • setQtySold – checks the formal parameter – if it’s negative, it sets the field to zero otherwise it sets the field to the formal parameter
    • setBasePay – checks the formal parameter – if it’s negative, it sets the field to zero otherwise it sets the field to the formal parameter
  • Constructor with arguments
    • Calls the set methods to set the fields
  • Get methods (accessors) return the field that the get refers to
  • computePercentBonus – determines the bonus based on the description above and returns the percent bonus (as an integer – 0, 5, 10, or 15)
  • calculatePay – calculates the pay. It will have to call the computePercentBonus method to determine how much bonus to add to the base pay.

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

  • The main method should set up a scanner object so it will read the file you just created
  • Remember to include the following imports
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
  • Make sure you test the file when you open it – if it doesn’t find the file it should print an error message to the screen and exit the program
  • Print the header to the screen using the following line of code. (you can just copy it) Take notice of the formatting. If you don’t understand what the numbers mean, ask.
System.out.printf("%-10s%8s%10s%8s%12s%n",  "Name","Qty Sold","Base Pay","%Bonus","Total Pay");
  • Write a loop that reads in the name, quantity, and base salary from the file and puts the information into an object. It then uses the object to print the line of code (using the get methods) as seen on the output. (use formatting in the header above as an example of how to line up the columns)
  • After you get the employees printing out, add the code to your loop to find the total amount paid and the top seller’s number of cars sold for the week and print them out as shown in the output below.

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 

Solutions

Expert Solution

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


Related Solutions

Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with...
Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with the code **** Objective: Write a program that calculates a final grade! The program should read in a file and then calculates the final grade based on those scores. Files read into this system are expected to follow this format: <Section0>\n <Grade0 for Section0>\n <Grade1 for Section0>\n … <GradeX for Section0>\n <Section1>\n <Grade0 for Section1>\n … <GradeY for Section1> <Section2> … <SectionZ> Sections denote...
Please I need this to be done in Java, can I have it answered by anonymous...
Please I need this to be done in Java, can I have it answered by anonymous who answered my last question regarding java? Thank you You will need to implement a specific algorithm implementation to match the class definition AND implement a unit test using JUnit that conforms the specific naming convention. Algorithm: Inputs: integers m and n , assumes m and n are >= 1 Order is not important for this algorithm Local variables integers: remainder Initialize: No initialization...
Please I need all answers about questions in TLC LAB. (Q1) In our lab, what is...
Please I need all answers about questions in TLC LAB. (Q1) In our lab, what is the mobile phase and what is stationary phase? Discuss the polarity of each. (Q2) Do your results suggest that the chemical characteristics of these pigments might differ according to their color? Explain. (Q3) Which of your pigment molecules was the most non-polar? Polar? (Q4) What is the relationship between Rf values and polarity for this experiment? Is this always true? (Q5) Why should you...
B has to be matched with A so please I need both in Java. the previous...
B has to be matched with A so please I need both in Java. the previous project mean A A. Write a class that maintains the top ten scores for a game application, implementing the add and remove methods but using a singly linked list instead of an array. B. Perform the previous project, but use a doubly linked list. Moreover, your implementation of remove(i) should make the fewest number of pointer hops to get to the game entry at...
I need this in Java please: Lab11B: Understanding the constructor. Remember that the constructor is just...
I need this in Java please: Lab11B: Understanding the constructor. Remember that the constructor is just a special method (with no return type) that has the same name as the class name. Its job is to initialize all of the attributes. You can actually have more than one constructor, so long as the parameters are different. Create a class called Turtle that has two attributes: 1) speed and 2) color. Then, create a constructor that has no parameters, setting the...
I need this in Java please: Behaviors. In the context of OOP, functions are called methods...
I need this in Java please: Behaviors. In the context of OOP, functions are called methods or behaviors because they typically do something. Most often, they read or change the values of one or more variables in the class. For example, you may have a weight variable in a class, and a method called gainWeight( ) that increases the weight variable by a certain amount. For this part of the lab, create class KoalaBear that has a weight attribute (in...
Please answer this question ASAP an explain in detail. I really need it before the night...
Please answer this question ASAP an explain in detail. I really need it before the night is over. a) Explain what a catalytic process is and how it is different from the non-catalytic version of the process. Give an example of an enzymatic process other than amylase and describe the substrate(s)/product(s): b) Describe what the enzyme amylase does and what would happen in the absence of this enzyme:
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user...
IN JAVA PLEASE ASAP !!! I just need the main and mergesort function Ask the user for the number of elements, not to exceed arraySize = 20 (put appropriate input validation) Ask the user for the type of data they will enter - EnglishGrade or MathGrade objects. Use your EnglishGrade and MathGrade classes Based on the input, create an appropriate array for the data to be entered. Write a helper function called recursionMergeSort such that: It is a standalone function...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove,...
Java Searching and Sorting, please I need the Code and the Output. Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer, say, removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (After deleting an element, the number of elements in the array is reduced by 1.) Assume that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT