title: How to pass a NumberFormat object to a method?
body: <p>I'm trying to use a NumberFormat object to display a price. I'm very new to programming, my book isn't very helpful, nor is my teacher. I have a class called Product and a class called MyProduct, which is a subclass of Product. In the Product class there is a method called getPrice() that has no parameters. All it does is return the value for price. My task is to create a method in MyProduct called getPrice(NumberFormat nf) that returns the price, but formatted as currency. In the main method, if I use myproduct.getPrice(); I get the price, but unformatted (I know this is because it's calling getPrice() from Product, not getPrice(NumberFormat nf) from MyProduct. My question is what do I put in as an argument to stop getting a compile time error? I've tried getPrice(nf), getPrice(this), getPrice(price), just about anything I can think of and nothing works. Any help would be greatly appreciated and all relevant lines of code are posted below. Thanks in advance.</p>
  
  <p>Below is the MyProduct class</p>
  
  <pre><code>public class MyProduct extends Product{
  public MyProduct()
  {
   super();
  }
  
  NumberFormat nf;
  
  public String getPrice(NumberFormat nf) {
  
      this.nf = NumberFormat.getCurrencyInstance();
      String priceFormatted = nf.format(price);
      return priceFormatted;
  }
  </code></pre>
  
  <p>And here is ProductApp class</p>
  
  <pre><code>public class ProductApp {
  
  public static void main(String args[]) {
      // display a welcome message
      System.out.println("Welcome to the Product Viewer");
      System.out.println();
  
      // create 1 or more line items
      Scanner sc = new Scanner(System.in);
      String choice = "y";
      while (choice.equalsIgnoreCase("y")) {
          // get input from user
          System.out.print("Enter product code: ");
          String productCode = sc.nextLine();
  
          // Use a ProductReader object to get the Product object
          ProductDB db = new ProductDB();            
  
               MyProduct myproduct = db.getProduct(productCode);
  
          // display the output
          String message = "\nPRODUCT\n" +
              "Code:        " + myproduct.getCode() + "\n" +
              "Description: " + myproduct.getDescription() + "\n" +
              "Price:       " + myproduct.getPrice()+ "\n";
          System.out.println(message);
  
          // see if the user wants to continue
          System.out.print("Continue? (y/n): ");
          choice = sc.nextLine();
          System.out.println();
      }
      System.out.println("Bye!");
  </code></pre>
  
  <p>The line I need help with is </p>
  
  <pre><code>"Price:       " + myproduct.getPrice()+ "\n";
  </code></pre>