Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to write a method that calculates pay, where if someone works over 8 hours, you get paid time and a half (1.5) and

I'm trying to write a method that calculates pay, where if someone works over 8 hours, you get paid time and a half (1.5) and if someone works over 12 hours, your get paid double time (2). It says bad operand types for line 29 ( else if ( 8 < y < 12) { ), but I don't know why my code isn't working so please include comments. Code is below. The return is the total amount of pay.

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package getpay;

/** * * @author paolosantos */ public class GetPay {

public static void main(String[] args) {

System.out.println ("The amount of pay earned at an hourly rate of $" + x + " for " + y + " hours worked is " + calcPay(10.50, 8)); System.out.println ("The amount of pay earned at an hourly rate of $" + x + " for " + y + " hours worked is " + calcPay(10.50, 10)); System.out.println ("The amount of pay earned at an hourly rate of $" + x + " for " + y + " hours worked is " + calcPay(10.50, 12));

} public static double calcPay(double x, double y){ if ( x <= 0 || y <= 0) throw new IllegalArgumentException("The parameters are invalid."); else { double z = 0; x = 0; y = 0; // x = pay rate // y = number of hours worked // z = amount earned if (y < 8){ z = y * x; } else if ( 8 < y < 12) { z = y * x * 1.5 ; } else if ( y > 12 ){ z = y * x * 2; } return z; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions