Results 1 to 11 of 11
- 12-21-2010, 06:55 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
this is the error i get: cannot find symbol method parseString(java.lang.String)
this is the question and my code
Hilan International Bank decided to have a salary plan for its employees. In the new Policy, bonus is based on the fact that one is a senior staff or junior staff. You have been called in as a programmer to develop a software to meet this policy’s requirement:
(a.) Create a class called Salary.
(b.) Create methods/functions that will calculate
i. the tax which is 5% of the gross salary
ii. Bonus depending on the status of employee-senior/junior
Senior staff-1hr-15 US dollars
Junior staff-1hr-12 US dollars
iii. Net Salary=Bonus+gross salary-tax
(c.)Create another class called SalDemo with the main function
(d.)Declare an instance of the salary class called cal.
(e.)Use the cal object to check the net salary
(f.)Use JOptionPane to allow a user to enter the status, time and the gross salary.
import javax.swing.JOptionPane;
class salary{
String status;
double T; //T represents time.
double gross_salary;
double bonus;
double GetTax(double gross_salary){
double tax=gross_salary*0.05;
return tax;
}
double GetBonus(double T,String status){
if(status=="senior staff"){
double bonus=T*15;
}
else if(status=="junior staff"){
bonus=T*12;
}
return bonus;
}
double GetNetSalary(double bonus,double gross_salary,double tax){
double netSalary=(bonus+gross_salary)-tax;
return netSalary;
}
}
class SalDemo{
public static void main(String args[]){
salary cal = new salary();
String T=JOptionPane.showInputDialog("Enter time");
double time=Double.parseDouble(T);
String status=JOptionPane.showInputDialog("Enter status");//where st represent status.
String st=String.parseString(status);
String g_salary=JOptionPane.showInputDialog("Enter gross salary");
double gross_salary=Double.parseDouble(g_salary);
System.out.println(cal.GetTax(gross_salary));
System.out.println(cal.GetBonus(time,status));
System.out.println(cal.GetNetSalary(cal.GetBonus(t ime,status),gross_salary,(cal.GetTax(gross_salary) )));
JOptionPane.showMessageDialog(null,"Your Net salary is ="+cal.GetNetSalary
(cal.GetBonus(time,status),gross_salary,(cal.GetTa x(gross_salary))));
}
}
- 12-21-2010, 07:43 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
What is method String.parseString( ... ) supposed to do? As you have already noticed the String class doesn't have such method.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-21-2010, 07:57 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
cross-posted and all because someone can't use five minutes to read the API docs, but will spend days waiting on someone else to read it for him.
- 12-21-2010, 09:49 AM #4
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Please am new and now studying java at school. The lecture would not help us solve this simply because he wants us to find the solution ourselves so can you please show me solve this problem. I've tried all best i can. Thanks.
- 12-21-2010, 10:03 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
- 12-21-2010, 10:40 AM #6
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
I actually don't understand what it means. am totally green when it comes to java and can barely see the technical aspects of codes. thanks.
- 12-21-2010, 11:11 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Your compiler was trying to tell you that it couldn't find a method named parseString( ... ) in the String class; it was right because there is no such method in that class. What do you think such a method should do? Or were you just happily typing away while hoping for the best?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-21-2010, 07:42 PM #8
Member
- Join Date
- Dec 2010
- Posts
- 19
- Rep Power
- 0
Hi,
look at your own code:
String T=JOptionPane.showInputDialog("Enter time");
double time=Double.parseDouble(T);
Parse method is used to convert from a type to a type. In these lines you converted from a String (T) to a double (time).
String status=JOptionPane.showInputDialog("Enter status");//where st represent status.
String st=String.parseString(status);
Here you are trying (I think) to convert from a String (status) to String (st) and it's obvious String.parseString(String) doesn't exist. Review this point.Last edited by SmilingKey; 12-21-2010 at 08:35 PM.
- 12-21-2010, 08:13 PM #9
i could compile and run the SalDemo by changing one line to
String st=status;
other weaks:
- your class is not called Salary but salary, which is not the same.
- the first letter of a method identifier is not capitalized, ex. getTax() is ok
- change your code in the method GetBonus() to
Java Code:double GetBonus(double T, String status) { System.out.println("status " + status); System.out.println("t " + T); if (status.equals("senior staff")) { bonus = T * 15; } else if (status.equals("junior staff")) { bonus = T * 12; } return bonus; }
- first of all strings are compared with the method equals() and not with == and don't define a new double bonus variable, because this variable is a local variable and not the same like the instance variable bonus.
the result seem to be ok.
- 12-22-2010, 12:58 AM #10
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Thanks to everybody
Hi guys i really appreciate your efforts. God bless you million times. Am so glad wish you all a MERRY CHRISTMAS AND A PROSPEROUS HAPPY NEW YEAR....:)
- 12-22-2010, 01:12 AM #11
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
This is the working code
Java Code:import javax.swing.JOptionPane; class salary{ String status; double bonus; double T; double gross_salary; double GetTax(double gross_salary){ double tax=gross_salary*0.05; return tax; } Double GetBonus(double T, String status) { //System.out.println("status " + status); // System.out.println("t " + T); if (status.equals("senior staff")) { bonus = T * 15; } else if (status.equals("junior staff")) { bonus = T * 12; } return bonus; } double GetNetSalary(double bonus,double gross_salary,double tax){ double netSalary=(bonus+gross_salary)-tax; return netSalary; } } class SalDemo{ public static void main(String args[]){ salary cal = new salary(); String T=JOptionPane.showInputDialog("Enter time"); double time=Double.parseDouble(T); String status=JOptionPane.showInputDialog("Enter status"); String st=status; String g_salary=JOptionPane.showInputDialog("Enter gross salary"); double gross_salary=Double.parseDouble(g_salary); System.out.println(cal.GetTax(gross_salary)); System.out.println(cal.GetBonus(time,status)); System.out.println(cal.GetNetSalary(cal.GetBonus(time,status),gross_salary,(cal.GetTax(gross_salary)))); JOptionPane.showMessageDialog(null,"Net salary is ="+cal.GetNetSalary (cal.GetBonus(time,status),gross_salary,(cal.GetTax(gross_salary)))); } }
Similar Threads
-
java:92: cannot find symbol error
By noviceNewbie in forum AWT / SwingReplies: 3Last Post: 12-18-2010, 02:46 AM -
cannot find symbol method initCause(java.lang.ClassNotFoundException)
By Taxi in forum CLDC and MIDPReplies: 8Last Post: 10-17-2010, 10:24 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
[SOLVED] Java Error: Cannot find Symbol...
By bobleny in forum New To JavaReplies: 8Last Post: 04-15-2008, 06:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks