Ask Question
19 June, 18:32

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).

+3
Answers (1)
  1. 19 June, 20:19
    0
    import java. util. Scanner; public class Main { static String invoiceNo; public static void main (String[] args) { shippingInvoice (); System. out. printf ("Invoice no: %s", invoiceNo); } public static void shippingInvoice () { Scanner input = new Scanner (System. in); System. out. print ("Input invoice no: "); invoiceNo = input. nextLine (); } }

    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).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “1. Write the following static methods. Assume the reference variable input has already been declared for the Scanner class. Use printf (). ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers