473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Okay, major problem guys

Slick47
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:
Expand|Select|Wrap|Line Numbers
  1. *******************************************************************************
  2. C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:76: incomparable types: java.lang.String and int
  3. if (Type == 1){
  4.          ^
  5. C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:80: incompatible types
  6. found   : int
  7. required: java.lang.Double
  8.         Amount2 = 0;
  9.                   ^
  10. C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:84: incompatible types
  11. found   : int
  12. required: java.lang.Double
  13.         Amount2 = 0;
  14.                   ^
  15. C:\Users\Susan\Desktop\Compsci\Compsci172\Assign 2\Phonebill.java:90: incomparable types: java.lang.String and int
  16. else if (Type == 2){
  17.               ^
  18. 4 errors
  19.  
  20. Tool completed with exit code 1
  21. **********************************************************************************
  22.  
I just need someone to tell me what it means when it says "incomparable types: java.lang.String and int" or "incompatible types found : int required: java.lang.Double" and how I can solve this to help fix my program. Thank anyone who's willing to help me, thank you so much!!!

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. import java.util.*;
  4. import java.text.*;
  5.  
  6. class Phonebill{
  7.  
  8.     public static void main( String[] args ) {
  9.  
  10.  
  11.         String number;
  12.         String Type;
  13.         Double Dayminutes;
  14.         Double Nightminutes;
  15.         Double Totalminutes;
  16.         Double Amountdue;
  17.         Double Amount2;
  18.                                 Double Totalamount;
  19.         int servicetype;
  20.         int type;
  21.  
  22.  
  23.  
  24.         Scanner scanner;
  25.         scanner = new Scanner(System.in);
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //INPUT
  35.         System.out.print("Enter your phone number: ");
  36.         number = scanner.next();
  37.  
  38.  
  39.  
  40.         System.out.print("Enter your service type <1 for Regular, 2 for Premium>: ");
  41.         servicetype = scanner.nextInt();
  42.         Type = " ";
  43.  
  44.         if ((servicetype != 1)|(servicetype !=2)){
  45.             System.out.println ("Not a valid service type");
  46.             return;
  47.         }
  48.  
  49.         if (servicetype == 1) {
  50.                 Type = "Regular";
  51.         }
  52.  
  53.         else if (servicetype == 2) {
  54.                 Type = "Premium";
  55.         }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.         System.out.print("Enter the minutes used during day time: ");
  62.         Dayminutes = scanner.nextDouble();
  63.  
  64.         System.out.print("Enter the minutes used during night time: ");
  65.         Nightminutes = scanner.nextDouble();
  66.  
  67.  
  68. //Calculations
  69.  
  70.  
  71. //another 2 if ifelse else 's
  72.  
  73.  
  74. Totalminutes = Dayminutes + Nightminutes;
  75.  
  76. if (Type == 1){
  77.     if (Totalminutes >= 50){
  78.  
  79.         Amountdue = 10 + ((Totalminutes-50) * .20);
  80.         Amount2 = 0;
  81.         }
  82.     else if(Totalminutes < 50){
  83.         Amountdue = 10 + (Totalminutes - Totalminutes);
  84.         Amount2 = 0;
  85.         }
  86.  
  87. }
  88.  
  89.  
  90. else if (Type == 2){
  91.         if (Dayminutes >=75){
  92.     Amountdue = 25 + ((Dayminutes-75) * .10);
  93.     }
  94.         else if (Dayminutes < 75){
  95.     Amountdue = 25 + ((Dayminutes - Dayminutes) * .10);
  96.     }
  97.         else if (Nightminutes >= 100){
  98.     Amount2 = 25 + ((Nightminutes - 100) * .05);
  99.     }
  100.         else if (Nightminutes < 100){
  101.     Amount2 = 25 + ((Nightminutes - Nightminutes) * .05);
  102.     }
  103. }
  104.  
  105.  
  106. Totalamount = Amountdue + Amount2;
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //RESULTS
  115.  
  116.  
  117. System.out.println("");
  118. System.out.println("");
  119. System.out.println("Current information for your account:");
  120. System.out.println("");
  121. System.out.println("Account number:" + "\t" + number);
  122. System.out.println("Service type:" + "\t" + Type);
  123. System.out.println("Minutes used:" + "\t" + Totalminutes);
  124. System.out.println("Amount Due:" + "\t" + Totalamount);
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. }
  134. }
Feb 23 '09 #1
6 3873
jkmyoung
2,057 Expert 2GB
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?
Feb 23 '09 #2
I'm using Textpad with the Java SE Runtime 6 External Application, thank you though!!! I'm going to give this try right now!
Feb 23 '09 #3
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.lang.String)
location: class java.lang.String
if(Type.Equals("1")){

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



Am I entering that in the right spot?
Feb 23 '09 #4
Okay, the only things left that I need to fix are:

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


and:

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


The rest of the code is still the same; anybody else have any help or suggestions?
Feb 23 '09 #5
JosAH
11,448 Expert 8TB
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
Feb 24 '09 #6
jkmyoung
2,057 Expert 2GB
yes, lowercase equals. Sorry, C# kicked in for some reason.
Feb 24 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Doe | last post by:
Does anyone understand what a 'raw device number' is with respect os.major() and os.minor() Found in os-file-dir.html, section 6.1.4, os.major() description is: major(device) Extracts a...
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
9
by: Tim Frawley | last post by:
I have converted a VB6 application to VB.NET. The old application made extensive use of the Clipboard for copying an Image Name so that it could be pasted into the image capture app when the user...
11
by: Madison Kelly | last post by:
Hi all, I am new to the list and I didn't want to seem rude at all so I wanted to ask if this was okay first. I have a program I have written in perl which uses a postgresSQL database as the...
2
by: Jef Driesen | last post by:
I'm working on a project where i need to exchange multidimensional data between C/C++ (row-major) and matlab (column-major). I understand the difference between those two mappings to linear memory....
31
by: zdenko | last post by:
I have a multi user database and users were created by user level security wizzard - as I mentioned in message before. Everything works fine for those users, but now I have another problem. I have...
8
by: Diwa | last post by:
Hi Guys, Is there any better way than below to find an int in a string (e.g. "30" in "KFStat30A") // -------------------------------------------------------------- #include <iostream>...
6
by: wketchin | last post by:
Hey guys, this is my first time posting to this forum. I hope you're nice :D I love advice, and a solution would be even better! So here's my situation: I am building a website for the machine...
3
by: Lax | last post by:
Isn't it "technically" meaningless to call C a "row major language," since there are no such things as multidimensional arrays in C. In C you can define arrays of arrays, and the way that the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.