Question
package com.chegg.expert; import java.util.Scanner; public class PaymentCalcation { public static void main(String[] args) { PaidAdvisor pa = new PaidAdvisor(); pa.setNameRateHours(); pa.calculatePay(); System.out.println(pa.toString()); } } class
package com.chegg.expert;
import java.util.Scanner;
public class PaymentCalcation {
public static void main(String[] args) {
PaidAdvisor pa = new PaidAdvisor();
pa.setNameRateHours();
pa.calculatePay();
System.out.println(pa.toString());
}
}
class PaidAdvisor extends Person{
private static float regularPayRate, specialPayRate, payment = 0;
private static int totalHours, specialHours;
//Not setting over time rate because it's half of the regular rate
//Not setting overtime hours because it can be calculate from tota hours
PaidAdvisor(float regularPayRate, float specialPayRate, int totalHours, int specialHours){
this.regularPayRate = regularPayRate;
this.specialPayRate = specialPayRate;
this.totalHours = totalHours;
this.specialHours = specialHours;
}
PaidAdvisor() {
}
public void calculatePay() {
int regularHours = totalHours-specialHours, overtimeHours = 0;
if(regularHours>30) {
overtimeHours = regularHours - 30;
}
payment = regularHours*regularPayRate + specialHours*specialPayRate + overtimeHours*(regularPayRate/2.0f);
}
public float getPayRate() {
Scanner sc = new Scanner(System.in);
String ch = "";
while(true) {
System.out.println("Which par rate do you want to know? (r-regualr/o-overtime): ");
System.out.print("r/o: ");
ch = sc.nextLine();
if(ch.equalsIgnoreCase("r")) {
return regularPayRate;
}
else if(ch.equalsIgnoreCase("o")){
return specialPayRate;
}
else {
System.out.println("Invalid choice!");
}
}
}
public void setNameRateHours() {
Scanner sc = new Scanner(System.in);
String name = "";
int totalHours,regularHours, specialHours;
float regularPayRate, specialPayRate;
System.out.print("Enter name: ");
name = sc.nextLine();
System.out.print("Enter total hours: ");
totalHours = Integer.parseInt(sc.nextLine());
System.out.print("Enter special hours: ");
specialHours = Integer.parseInt(sc.nextLine());
System.out.print("Enter regualar pay rate: ");
regularPayRate = Float.parseFloat(sc.nextLine());
System.out.print("Enter special pay rate: ");
specialPayRate = Float.parseFloat(sc.nextLine());
this.regularPayRate = regularPayRate;
this.specialPayRate = specialPayRate;
this.totalHours = totalHours;
this.specialHours = specialHours;
}
public int getHoursWorked() {
return totalHours;
}
public String toString() {
return "Total payment for the emplyee "+super.getFirstName()+" "+super.getLasttName() + " is: "+payment;
}
}
class Person {
private String firstName;
private String lastName;
public Person()
{
firstName = "";
lastName = "";
}
public Person(String first, String last)
{
setName(first, last);
}
public String toString()
{
return (firstName + " " + lastName);
}
public void setName(String first, String last)
{
firstName = first;
lastName = last;
}
public String getFirstName() {
return firstName;
}
public String getLasttName() {
return lastName;
}
}
How do i get it to show the name on the output?
Total payment for the employee FIRSTNAME LASTNAME is: 1625.0
ir Console 3 terminated> PaymentCalcation [Java Application] C:Program Files Javaljre-9.0 Enter name: ABCDEF Enter total hours: 50 Enter special hours: 10 Enter regualar pay rate: 25 Enter special pay rate: 50 Total payment for the emplyee is: 1625.0 Ho
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started