輸出運行:Java的工資會繼續展示,0.00淨工資
Payroll Computation
Enter number of hours worked (00.0) <0 for Quick exit>: 39
Enter first number of hours straight (integer or 0 to disable):40
Enter hourly rate of worker (00.00): 10
Gross pay is : $390.00
Tax is : 7%
Net pay is : $0.00
淨工資應該是362.70
所以實際輸出應該像下面:
Gross pay is : $390.00
Tax is : 7%
Net pay is : $362.70
我在這裏想念什麼細節? 這是我在代碼中做錯了什麼,還是別的什麼? 需要你的幫助/援助,以獲得淨產的價值
import java.io.*;
import java.util.*;
import java.text.NumberFormat;
import java.math.*;
import java.util.Locale;
class Assign2
{
public static void main(String args[])
{
CalPayroll cpr=new CalPayroll();
cpr.acceptPay();
}
}
CallPayroll類
class CalPayroll extends Pay
{
Screen sc=new Screen();
Scanner stdin=new Scanner(System.in);
NumberFormat dollars=NumberFormat.getCurrencyInstance(Locale.US);
Pay p=new Payroll();
public void displayinfo()
{
double _gross=super.calc_payroll();
super.tax(_gross);
double _net= p.calc_payroll();
System.out.println("Gross pay is : "+dollars.format(_gross));
System.out.println("Tax is : "+taxrate+"%");
System.out.println("Net pay is : "+dollars.format(_net));
}
public void acceptPay()
{
Accept ac = new Accept();
CalPayroll cp=new CalPayroll();
float h,r;
int hs;
char s;
do
{
System.out.println("Payroll Computation");
System.out.println(" ");
System.out.println("Enter number of hours worked (00.0) <0 for Quick exit>: ");
h=stdin.nextFloat();
cp.setHours(h);
if(h>0)
{
System.out.println("Enter first number of hours straight (integer or 0 to disable):");
hs=stdin.nextInt();
System.out.println("Enter hourly rate of worker (00.00): ");
r=stdin.nextFloat();
sc.scrollscreen('=',65,2);
cp.setHrsStr(hs);
cp.setRate(r);
sc.scrollscreen(1);
cp.displayinfo();
sc.scrollscreen(1);
System.out.println("e to exit, any other letter + <Enter> to continue");
s=stdin.next().charAt(0);
}
else
{
System.out.println("e to exit, any other letter + <Enter> to continue");
s=stdin.next().charAt(0);
}
}while(s!='e'&&s!='E');
}
}
收費類
class Pay
{
private float Hours, Rate;
private int HrsStr;
public int taxrate=0;
public void setHours(float a)
{
Hours=a;
}
public void setRate(float a)
{
Rate=a;
}
public void setHrsStr(int a)
{
if(a<0)
{
HrsStr=0;
}
else
{
HrsStr=a;
}
}
public float getHours()
{
return Hours;
}
public float getRate()
{
return Rate;
}
public int getHrsStr()
{
return HrsStr;
}
public double calc_payroll()
{
double gross;
gross=getHours()*getRate();
return gross;
}
public void tax(double a)
{
if(a>=0&&a<=399.99)
taxrate=7;
else if(a>=400.00&&a<=899.99)
taxrate=11;
else
taxrate=17;
}
}
class Payroll extends Pay
{
double net;
double _gross;
public double calc_payroll()
{
_gross=super.calc_payroll();
super.tax(_gross);
net=_gross-(_gross*taxrate/100);
return net;
}
}
class Screen
{
public static void scrollscreen(int a)
{
for(int i=0;i<a;i++)
{
System.out.println(" ");
}
}
public static void scrollscreen(char c, int a, int b)
{
for(int i=0;i<b;i++)
{
for(int j=0;j<a;j++)
{
System.out.print(c);
}
System.out.println(" ");
}
}
}
class Accept
{
Scanner in=new Scanner(System.in);
public int acceptInputInt()
{
return in.nextInt();
}
public char acceptInputChar()
{
return in.next().charAt(0);
}
public float AcceptInputFloat()
{
return in.nextFloat();
}
public double AcceptInputDouble()
{
return in.nextDouble();
}
}
不能告訴。沒有提供'Pay'和'Payroll'中的相關代碼。 – pczeus
什麼是'CalParoll'和'Accept'? LOL – pczeus
我不好,我忘了複製和粘貼現在提供的薪水和工資 –