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:
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:
*******************************************************************************
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
**********************************************************************************
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);
}
}
Comment