Results 1 to 11 of 11
  1. #1
    Elcliff is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Unhappy 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))));
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    What is method String.parseString( ... ) supposed to do? As you have already noticed the String class doesn't have such method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    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.

  4. #4
    Elcliff is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Default

    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.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Elcliff View Post
    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.
    Reread my original reply #2 and answer the question please.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Elcliff is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Default

    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.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Elcliff View Post
    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.
    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    SmilingKey is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    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.

  9. #9
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by Elcliff View Post
    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.

    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.

  10. #10
    Elcliff is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Thumbs up 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....:)

  11. #11
    Elcliff is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Thumbs up 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

  1. java:92: cannot find symbol error
    By noviceNewbie in forum AWT / Swing
    Replies: 3
    Last Post: 12-18-2010, 02:46 AM
  2. Replies: 8
    Last Post: 10-17-2010, 10:24 AM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Replies: 2
    Last Post: 09-18-2008, 07:30 AM
  5. [SOLVED] Java Error: Cannot find Symbol...
    By bobleny in forum New To Java
    Replies: 8
    Last Post: 04-15-2008, 06:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •