I have a main class called CustomerTypeApp. It has a class variable private static float itemPrice = 0.0f. Within the main method is the following code:
String promptType = (" To determine a discount for " + nf.format((float) itemPrice) + ", type in the... ...Select => ");
char customer = Validation.getChar(promptType);
I also have a class called Validation with a method getChar. The code is as follows:
public static char getChar(String prompt){
String input;
char choice;
System.out.printf(" " + prompt);
input = sc.nextLine();
choice = input.charAt(0);
return choice;
}
In the CustomerTypeApp class, the nf.format is obviously referring to NumberFormat. However, the professor has said we cannot use NumberFormat and instead have to use printf. The getChar method does use a printf statement. However, I am having trouble passing the value for the printf (variable?). Here's what I mean: I edited my code for CustomerTypeApp as follows:
String promptType = (" To determine a discount for $%.2s, type in the... ...Select => ");
The problem is I have to pass in itemPrice where the $%.2s is. I tried tacking it onto the end of promptType as follows:
(" To determine...$%.2s...Select => ", itemPrice);
However, I get an error stating ")" expected and ";" expected. I also tried adding it in the getChar method as follows:
System.out.printf(" " + prompt, itemPrice);
However, for that I get an error stating Cannot find symbol.
Can anyone tell me what I'm doing wrong? Thanks!
String promptType = ("<- whats the point of the parenthesis? Is it supposed to be part of the String?promptdeclared (is it a variable?)