Ask Question
6 February, 11:18

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

+2
Answers (1)
  1. 6 February, 14:28
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers