}
public double getBaseSalary(){
return baseSalary;
}
public double earnings(){
return baseSalary+(commissionRate*grossSales);
}
public String toString(){
return String.format("%s: %s %s/n%s: %s\n%s: %.2f\n%s: %.2f\n%s: %.
2f","o ergazomenos:",firstName,lastName,
"ssn=",socialSecurityNumber,"grossSales",grossSales,"commissionRate",
commissionRate,"base salary",baseSalary);
}
}
that calls class COMEMP: public class COMEMP{
protected String firstName;
protected String lastName;
protected String socialSecurityNumber;
protected double grossSales;
protected double commissionRate;
public COMEMP(String first,String last,String ssn,double
sales ,double rate){
firstName=first;
lastName=last;
socialSecurityNumber=ssn;
setGrossSales(sales);
setCommissionRate(rate);
}
public void setFirstName(String first){
firstName=first;
}
public String getFirstName(){
return firstName;
}
public void setLastName(String last){
lastName=last;
}
public String getLastName(){
return lastName;
}
public void setSocialSecurityNumber(String ssn){
socialSecurityNumber=ssn;
}
public String getSocialSecurityNumber(){
return socialSecurityNumber;
}
public void setGrossSales(double sales){
grossSales=(sales<0.0)?0.0:sales;
}
public double getGrossSales(){
return grossSales;
}
public void setCommissionRate(double rate){
commissionRate=(rate>0.0&&rate<1.0)?rate:0.0;
}
public double getCommissionRate(){
return commissionRate;
}
public double earnings(){
return commissionRate*grossSales;
}
public String toString(){
return String.format("%s: %s %s\n%s: %s\nn%s: %.2f\n%s: %.2f
","commission
employee",firstName,lastName,"ssn",socialSecurityNumber,"gross
sales",grossSales,"rate",commissionRate);
}
}
Compilation is successfully but runtime error says:
> Hi ,how are you , may i hava your help to an application in java?The
> program prints the information of the employees , salary,
> rate ,name...
[snipped code]
> Compilation is successfully but runtime error says:
Well, what did it say? Forgot to paste it perhaps?
Anyway, the error when you run it gives a BIG clue:
Exception in thread "main" java.util.MissingFormatArgumentException:
Format specifier '.2f'
at java.util.Formatter.format(Formatter.java:2429)
at java.io.PrintStream.format(PrintStream.java:914)
at java.io.PrintStream.printf(PrintStream.java:815)
at
BasePlusCommissionEmployeeTest3.main(BasePlusCommissionEmployeeTest3.java:11)
Looking at the line in the stacktrace where *your* code appears, suggest
that there's something wrong at line 11 in
"BasePlusCommissionEmployeeTest3.java".
That line is:
System.out.printf("%s %.2f\n",
basePlusCommissionEmployee.getBaseSalary());
So what does the error say about that line:
MissingFormatArgumentException:
Format specifier '.2f'
.2f is the second format argument in your format string,
but how many arguments do you really have?
/// Bjorn A
No. Learn to write meaningful subject lines. Learn to include the full
error message. Learn to provide useful example code.
Someone seems to be in a crappy mood.
You are, of course, correct in the points you are making.
A clearer subject line will help draw someone with the right knowledge to the message.
The actual error message will help an experienced Java programmer pinpoint the
immediate problem, although it may not be the only problem.
The code tells all. Without the relevant code, we can only make guesses about the
problem.
Here's a real challenge, though. You know Java, and enjoy solving tough coding
problems. But can you guide someone to learn how to ask the right questions to
solve their own problems?
Or is it just more satisfying to rap a ruler across someone's knuckles?
You can always ignore a post that doesn't give enough information. Maybe someone else
will have the patience to guide the poster to a solution. Maybe not.
--
TideRider