I am taking my first java class as i am a Database person this is quite interesting and here is my problem.
We are supposed to be learning to overload a class and i believe i have my code correct the problem is I cannot get the keyboard.nextdo uble to accept me hitting enter and it having a null to make my overloaded method work.
Here is the code i have.
I am supposed to be able to just add in one, two, or three variables and the methods fire off accordingly.
We are supposed to be learning to overload a class and i believe i have my code correct the problem is I cannot get the keyboard.nextdo uble to accept me hitting enter and it having a null to make my overloaded method work.
Here is the code i have.
I am supposed to be able to just add in one, two, or three variables and the methods fire off accordingly.
Code:
import java.util.Scanner; public class Pay { public static void main(String[] args) { /*Declaration of variables*/ double hoursworked; double payrate; double withholdingrate; double grosspay; double netpay; /*This lets the user enter a numer*/ Scanner keyBoard = new Scanner(System.in); System.out.print("Please enter the hours you have worked."); hoursworked = keyBoard.nextDouble(); System.out.print("Please enter your rate of pay."); payrate = keyBoard.nextDouble(); System.out.print("Please enter your withholding rate as a decimal."); withholdingrate = keyBoard.nextDouble(); /*This calls the computenetpay and displays the value*/ computenetpay(hoursworked, payrate, withholdingrate); } /*This is a new class to calculate gross and net pay*/ public static void computenetpay(double hoursworked, double payrate, double withholdingrate) { double grosspay; double netpay; grosspay = (hoursworked * payrate); netpay = grosspay - (grosspay * withholdingrate); System.out.println ("Your gross pay is " + (grosspay) + "."); System.out.println ("Your net pay is " + (netpay) + "."); } public static void computenetpay(double hoursworked, double payrate) { double grosspay; double netpay; grosspay = (hoursworked * payrate); netpay = grosspay - (grosspay * 0.15); System.out.println ("Your gross pay is " + (grosspay) + "."); System.out.println ("Your net pay is " + (netpay) + "."); } public static void computenetpay(double hoursworked) { double grosspay; double netpay; grosspay = (hoursworked * 5.85); netpay = grosspay - (grosspay * 0.15); System.out.println ("Your gross pay is " + (grosspay) + "."); System.out.println ("Your net pay is " + (netpay) + "."); } }
Comment