java.text.NumberFormat を正しくインポートしたことがわかっているのに、シンボル「getCurrencyInstance()」が見つからないことがコンソールに表示される
いくつかのコードを削除したので、それほど雑然としませんでした。これは私のクラス全体ではありません。
import java.util.Scanner;
import java.text.NumberFormat;
public class Kohls
{
// initialization
static Prompter prompter;
static Calculator calc;
static Operator operator;
private enum cardColor
{
RED, BLUE, GREEN;
} // end of enum Color
private static class Calculator
{
public int getDiscount(int age, cardColor color)
{
if (age > 62)
// senior discount
return 20;
if (color == cardColor.RED)
{
return 30;
}
else if (color == cardColor.BLUE)
{
return 25;
}
else if (color == cardColor.GREEN)
{
return 15;
}
return 0;
}
public double getSalePrice(int discountPercentage, double price)
{
double salePrice = price - (price * (discountPercentage / 100));
return salePrice;
}
} // end of class Calculator
private class Operator
{
public void getPriceWithDiscount()
{
// prompts
double price = prompter.getPrice();
int age = prompter.getAge();
cardColor color = prompter.getColor();
// discount(s)
int discountPercentage = calc.getDiscount(age, color);
double salePrice = calc.getSalePrice(discountPercentage, price);
NumberFormat fmt = new NumberFormat.getCurrencyInstance();
String salePriceFormat = fmt.format(salePrice);
operator.display(discountPercentage, salePriceFormat);
}
public void display(int discountPercentage, String salePrice)
{
System.out.print("You saved " + discountPercentage + "% on your purchase.");
System.out.print("\nThe price of your purchase with discount is " + salePrice + ".");
}
} // end of class Operator
public Kohls()
{
prompter = new Prompter();
calc = new Calculator();
operator = new Operator();
} // end of constructor
public static void main(String[] args)
{
Kohls kohls = new Kohls();
kohls.operator.getPriceWithDiscount();
} // end of method main()
} // end of class Kohls