185k views
0 votes
1. Write the following static methods. Assume the reference variable input has already been declared for the Scanner class. Use printf(). a. A method called shippingInvoice() that prompts for an invoice number and stores it in a class variable called invoiceNo. Assume an invoice number that contains numbers and letters (think about the data type).

User Nielarshi
by
5.3k points

1 Answer

4 votes

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3. static String invoiceNo;
  4. public static void main(String[] args) {
  5. shippingInvoice();
  6. System.out.printf("Invoice no: %s", invoiceNo);
  7. }
  8. public static void shippingInvoice(){
  9. Scanner input = new Scanner(System.in);
  10. System.out.print("Input invoice no: ");
  11. invoiceNo = input.nextLine();
  12. }
  13. }

Step-by-step explanation:

The solution is written in Java.

In the Java Main class, create a class variable, invoiceNo using keyword static (Line 5). The invoiceNo should be a string as it is supposedly composed of mixed numbers and letters.

Next, create the static method shippingInvoice (line 12 -16) that use Scanner object to get user input for the invoice number and assign it to the class variable invoiceNo.

In the main program, we call the shippingInvoice function and use printf method to print the invoice number (Line 8-9).

User Coudy
by
5.6k points