Question

In: Computer Science

4. Create a program that takes in the following CMD arguments: Item name, quantity, cost per...

4. Create a program that takes in the following CMD arguments: Item name, quantity, cost per item, and total cost. Your task then is to take this given information to print a simple receipt as indicated below (Don’t worry about the calculations for now.)

1

Sample run 1:

Java lab01_task04 Banana 6 3.25 19.50

Output:

Welcome to FCI Fresh Goods

Sales

======================

You have purchased:

6 X Banana @ N$ 3.25

including 15% VAT

======================

Total Cost: N$ 19.50

======================

Solutions

Expert Solution

Following is the java code for the above problem.

It takes four command line arguments as stated in the question.

Note that in java, by default a String is created named args[] which contains all the command line arguments specified by the user.

So,

args[0] ---> contains ItemName

args[1] ----> Quantity

args[2] ----> Cost per item

args[3] ----> Total cost

public class Main
{
        public static void main(String[] args) {
            
            String item_name = args[0];
            String quantity = args[1];
            String cost_per_item = args[2];
            String total_cost = args[3];
            
                System.out.println("Welcome to FCI Fresh Goods");
                System.out.println("Sales");
                System.out.println("======================");
        System.out.println("You have purchased:");
        System.out.println(quantity+" X "+ item_name + " @ " + " N$ "+cost_per_item);
        System.out.println("including 15% VAT");
        System.out.println("======================");
        System.out.println("Total Cost: N$ "+ total_cost);
        System.out.println("======================");
        }
}

Note: You should name the file (in which you paste the above code) to be Main.java because the public class name is also Main. Not doing it may give you errors. Please let me know if you have any questions/doubts/need more explanation. Thanks

Output:

Code Screenshot:


Related Solutions

Using the main function’s arguments, create a program that takes in a person’s name, their home...
Using the main function’s arguments, create a program that takes in a person’s name, their home town/location, and cell number then prints out the following message: Sample run 1: Java lab01_task03 Sililo Uis 0819876543 Output:   Contact successfully saved !! Contact Name : Sililo @ Uis Home number: 0819876543
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the...
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the name of an input file and the name of an output file. The program should confirm the input and output files can be opened. If a file cannot be opened, print the error message Cannot open file '<filename>' where <filename> is the name of the file and return. fopen() will return 0 if it fails to open a file. Then, the program will read...
Lower-of-Cost-or-Market Method On the basis of the following data: Item Inventory Quantity Cost per Unit Market...
Lower-of-Cost-or-Market MethodOn the basis of the following data: $$ \begin{array}{lccc} \text { Item } & \text { Inventory Quantity } & \text { Cost per Unit } & \begin{array}{l} \text { Market Value per Unit } \\ \text { (Net Realizable Value) } \end{array} \\ \hline \text { JFW1 } & 6,330 & \$ 10 & \$ 11 \\ \text { SAW9 } & 1,140 & 36 & 34 \end{array} $$Determine the value of the inventory at the lower-of-cost-or-market by applying...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Consider a basic economic order quantity (EOQ) model with the following characteristics: Item cost: $15 Item...
Consider a basic economic order quantity (EOQ) model with the following characteristics: Item cost: $15 Item selling price: $20 Monthly demand: 500 units (constant) Annual holding cost: $1.35 per unit Cost per order: $18 Order lead time: 5 working days Firm's work year: 300 days (50 weeks @ 6 days per week) Safety stock: 15% of monthly demand For this problem, determine the values of: Q* the optimal order quantity and reorder point. Select one: a. 400 and 100 b....
Write a pseudocode for the following code: /*every item has a name and a cost */...
Write a pseudocode for the following code: /*every item has a name and a cost */ public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;...
Create a program with the Calculator.java code RUN the program with the invalid data arguments 1,...
Create a program with the Calculator.java code RUN the program with the invalid data arguments 1, 3, 5x Take a screenshot of the output and describe what you think happened. MODIFY the code as in listing 14.2, NewCalculator.java , RUN it again with the same invalid input Take a screenshot of the new output and describe in your word document why you think the exception handling is a 'better' programming technique than just letting the program crash. __________________________________________________________________________ The Calculator.java...
Item Inventory Quantity Cost per Unit Market Value per Unit (Net Realizable Value) A13Y 80 $26...
Item Inventory Quantity Cost per Unit Market Value per Unit (Net Realizable Value) A13Y 80 $26 $31 O5T4 162 14 11 Determine the value of the inventory at the lower of cost or market by applying lower of cost or market to each inventory item, as shown in Exhibit 9. $
create a PYTHON program that will determine the cost per 3" serving for a giant sub...
create a PYTHON program that will determine the cost per 3" serving for a giant sub sandwich you will be ordering for a get-together with your friends. Within main(), get the input of the length in inches for the sub and the cost. Create function named numServings() that will receive the length in inches and return the number of servings. Each 3" is considered serving. Servings should be a whole number, so you will need to find a way to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT