-
Compiling help!
Hello! so I have a question to do a commission type calculator thing and this is what I have done so far
import java.util.Scanner;
public class Question1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int saleprice =0;
String residential="";
String multidwelling="";
String commercial="";
System.out.print("Enter the property's salesprice: ");
saleprice = input.nextInt();
System.out.print("Entery the Property code according to the following: \nResidential enter r \nMulti-Dwelling enter m \nCommercial enter c \nChoose your code: ");
int code = input.nextLine;
while (code = 'r' || code = 'm' || code = 'c')
{
if (code != 'r' || code != 'm' || code != 'c')
{
System.out.print("Code must be either R, M, or C: ");
}
}
return code;
}
}
I still need to include a new method but first I have to ask for a selling price, and then to enter the proper property code (R,m,c) and looping it to ask again if the code is not entered as r, m, or c. This is as far as I've gotten...
Now, when I try to compile it, it says the following :
int code = input.nextLine;
cannot find symbol - variable nextLine
What am I doing wrong here?
I think it should be int code = input.nextInt();
but I dunno
also when I do this, the compiler says that I cannot use || in my if and while statements... what could I do otherwise?
-
Re: Compiling help!
Guys, correct me if I'm wrong Scanner can't scan a char...
Code:
int code = input.nextLine;
while (code = 'r' || code = 'm' || code = 'c')
{
if (code != 'r' || code != 'm' || code != 'c')
{
System.out.print("Code must be either R, M, or C: ");
}
}
return code;
}
Code:
int code = input.nextLine;
while (code = 'r' || code = 'm' || code = 'c')
Your trying to filter an int or character or string?
*By using .nextLine you're trying to scan for a String
*in your your while condition, your tring to compare an int to char?
*Why there is return code there? fyi your in main method, you should create another method that returns the code
-
Re: Compiling help!
Okay so I have tried it a different way but it still doen't completely work it compiles though... it runs and just shows some lines written in red ugghhhhh.....
public class Question1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double saleprice =0;
double commission = 0;
String propertytype= "";
System.out.print("Enter the property's salesprice: ");
saleprice = input.nextDouble();
System.out.print("Enter Property code according to the following: \nResidential enter r\nMulti-Dwelling enter m\nCommercial enter c\n choose your code: ");
if (propertytype.equals("r"))
commission = 0.07;
else if (propertytype.equals("m"))
commission = 0.06;
else if (propertytype.equals("c"))
commission = 0.035;
else
{System.out.print("Code must be either r, m or c! ");
System.exit(0);
}
}
should I still create a new method??
-
Re: Compiling help!
Code:
int code = input.nextLine;
It needs to be used as a method
Code:
int code = input.nextInt();
but if you want to use a method of the String class you are going to declare code as a String.
Code:
String code = input.nextLine();
your filter needs to be something like:
Code:
while(code.charAt(0) != 'r' || code.charAt(0) != 'm' //..............etc
-
Re: Compiling help!
Well for starters you need to put parenthesis at the end of nextLine. That will throw an error without it
Code:
int code = input.nextLine();
while (code = 'r' || code = 'm' || code = 'c')
{
if (code != 'r' || code != 'm' || code != 'c')
{
System.out.print("Code must be either R, M, or C: ");
}
}
return code;
}
}
Just as mwr1976 said...sorry was writing and did not refresh
-
Re: Compiling help!
You are not displaying your output. Also since your commission rates are hard rates I would use Named Constants for those values. If you have to create another method you
could create a method that figures the commission with the named constants you wont have to pass them as parameters to your new function. You could return a double that would be a commission amount, but you still have to define your output.
-
Re: Compiling help!
alrighty thank you! my problem is... I don't understand why my output is not being dsplayed, how do I go about doing this?
-
Re: Compiling help!
How did you display the message that prompt the user for the input?
-
Re: Compiling help!
-
Re: Compiling help!
that's the right method, all you need is your parameter(s)