Okay, major problem guys

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Slick47
    New Member
    • Feb 2009
    • 6

    Okay, major problem guys

    Below is my program and my major problem, (I'm sorry in advance for it being so ugly I'm a pretty big noob and this is my first time using if, else if, else statements). My major problem is that when I go to compile this I get the same 4 errors, here are the errors:
    Code:
    *******************************************************************************
    C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:76: incomparable types: java.lang.String and int
    if (Type == 1){
             ^
    C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:80: incompatible types
    found   : int
    required: java.lang.Double
    		Amount2 = 0;
    		          ^
    C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:84: incompatible types
    found   : int
    required: java.lang.Double
    		Amount2 = 0;
    		          ^
    C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:90: incomparable types: java.lang.String and int
    else if (Type == 2){
                  ^
    4 errors
    
    Tool completed with exit code 1
    **********************************************************************************
    I just need someone to tell me what it means when it says "incomparab le types: java.lang.Strin g and int" or "incompatib le types found : int required: java.lang.Doubl e" and how I can solve this to help fix my program. Thank anyone who's willing to help me, thank you so much!!!

    Code:
    
    import java.util.*;
    import java.text.*;
    
    class Phonebill{
    
        public static void main( String[] args ) {
    
    
    		String number;
    		String Type;
    		Double Dayminutes;
    		Double Nightminutes;
    		Double Totalminutes;
    		Double Amountdue;
    		Double Amount2;
                                    Double Totalamount;
    		int servicetype;
    		int type;
    
    
    
    		Scanner scanner;
    		scanner = new Scanner(System.in);
    
    
    
    
    
    
    
    
    //INPUT
    		System.out.print("Enter your phone number: ");
    		number = scanner.next();
    
    
    
    		System.out.print("Enter your service type <1 for Regular, 2 for Premium>: ");
    		servicetype = scanner.nextInt();
    		Type = " ";
    
    		if ((servicetype != 1)|(servicetype !=2)){
    			System.out.println ("Not a valid service type");
    			return;
    		}
    
    		if (servicetype == 1) {
    				Type = "Regular";
    		}
    
    		else if (servicetype == 2) {
    				Type = "Premium";
            }
    
    
    
    
    
    		System.out.print("Enter the minutes used during day time: ");
    		Dayminutes = scanner.nextDouble();
    
    		System.out.print("Enter the minutes used during night time: ");
    		Nightminutes = scanner.nextDouble();
    
    
    //Calculations
    
    
    //another 2 if ifelse else 's
    
    
    Totalminutes = Dayminutes + Nightminutes;
    
    if (Type == 1){
    	if (Totalminutes >= 50){
    
    		Amountdue = 10 + ((Totalminutes-50) * .20);
    		Amount2 = 0;
    		}
    	else if(Totalminutes < 50){
    		Amountdue = 10 + (Totalminutes - Totalminutes);
    		Amount2 = 0;
    		}
    
    }
    
    
    else if (Type == 2){
    		if (Dayminutes >=75){
    	Amountdue = 25 + ((Dayminutes-75) * .10);
    	}
    		else if (Dayminutes < 75){
    	Amountdue = 25 + ((Dayminutes - Dayminutes) * .10);
    	}
    		else if (Nightminutes >= 100){
    	Amount2 = 25 + ((Nightminutes - 100) * .05);
    	}
    		else if (Nightminutes < 100){
    	Amount2 = 25 + ((Nightminutes - Nightminutes) * .05);
    	}
    }
    
    
    Totalamount = Amountdue + Amount2;
    
    
    
    
    
    
    
    //RESULTS
    
    
    System.out.println("");
    System.out.println("");
    System.out.println("Current information for your account:");
    System.out.println("");
    System.out.println("Account number:" + "\t" + number);
    System.out.println("Service type:" + "\t" + Type);
    System.out.println("Minutes used:" + "\t" + Totalminutes);
    System.out.println("Amount Due:" + "\t" + Totalamount);
    
    
    
    
    
    
    
    
    }
    }
    Last edited by pbmods; Feb 24 '09, 03:17 AM. Reason: Added CODE tags.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    For the double to int conversion, you can cast it like so:
    Amount2 = 0D;
    or
    Amount2 = (double)0;

    For the strings to int, you would probably have to use the .Equals(Object) function, and/or cast the number to a string. eg:
    if(Type.Equals( "1"))


    What program are you using to compile?

    Comment

    • Slick47
      New Member
      • Feb 2009
      • 6

      #3
      I'm using Textpad with the Java SE Runtime 6 External Application, thank you though!!! I'm going to give this try right now!

      Comment

      • Slick47
        New Member
        • Feb 2009
        • 6

        #4
        All right, the "Amount2 = (double)0" worked perfectly, thank you! I tried using the "if(Type.Equals ("1"))" line though, I replaced the lines "if (Type == 1)" and "if (Type == 2)" and now when I try to compile it says:

        cannot find symbol
        symbol : method Equals(java.lan g.String)
        location: class java.lang.Strin g
        if(Type.Equals( "1")){

        cannot find symbol
        symbol : method Equals(java.lan g.String)
        location: class java.lang.Strin g
        else if(Type.Equals( "2")){



        Am I entering that in the right spot?

        Comment

        • Slick47
          New Member
          • Feb 2009
          • 6

          #5
          Okay, the only things left that I need to fix are:

          79: cannot find symbol
          symbol : method Equals(java.lan g.String)
          location: class java.lang.Strin g
          if(Type.Equals( "1")){


          and:

          93: cannot find symbol
          symbol : method Equals(java.lan g.String)
          location: class java.lang.Strin g
          else if(Type.Equals( "2")){


          The rest of the code is still the same; anybody else have any help or suggestions?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            In Java methods start with a lowercase letter, so it's 'equals', not 'Equals'. Read this article for a rationale of the conventions.

            kind regards,

            Jos

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              yes, lowercase equals. Sorry, C# kicked in for some reason.

              Comment

              Working...