-3

I am trying to write a simple Java program which calculates the invoice amount for parts ordered from a hardware store. Once I compile it through the command prompt, I receive "Invoice.java:17: error: '.class' expected return int invoiceAmount;"

Did I miss an identifier somewhere? I've tried adding datatypes and new methods to instantiate and display the invoiceAmount again, but that did not seem to work. Any advice would be much appreciated. Thanks in advance!

//Invoice for hardware store

import java.util.Scanner;

public class Invoice { 
  public static void setInvoice(String[] args) {

    String partNumber;
    String partDescription;
    double price;
    Scanner amountPurchased = new Scanner(System.in);

  }

  public double getInvoiceAmount(){ 
    return int invoiceAmount;       
  }

  private void setInvoice(int amountPurchased){
    int amountPurchased;

    // get quantity of item from user input 
    System.out.println("Please enter quantity of item purchased: ");
    amountPurchased = amountPurchased.nextInt( );

    // get item price from user input   
    System.out.println("Please enter single unit item price: ");
    Scanner price = new Scanner(System.in);

    //multiplies quantity by price per item
    invoiceAmount = amountPurchased * price;
  }
}
NamshubWriter
  • 23,549
  • 2
  • 41
  • 59

1 Answers1

0

There is multiple errors in your code:

  • there is no public static void main(String[] args) method so program cannot run
  • after return statement you shoud use variable's name and not type+variable's name
  • in setInvoice method you redefine variable amountPurchased
  • there is no object and no object's fields so you cannot save your results into them

Here is few materials to help you with java language and object concepts

Hope I helped a bit.

Trynkiewicz Mariusz
  • 2,722
  • 3
  • 21
  • 27