Question

In: Computer Science

The goal of Java program implemented as part of this assignment is to build an Inventory...

The goal of Java program implemented as part of this assignment is to build an
Inventory Management System, from here on referred to as IMS, for a bookstore.
You will need to do the following tasks:
Requirement-1 – Create 3 different Arrays (15 pts)
(a) Create an array named items that will hold the following item names (strings)
- Pen
- Pencil
- Eraser
- Marker
- Notepad
(b) Create a second array named quantity, that will hold corresponding quantities
for items in the items array above. This will be populated through user inputs.
For each input you get from the user, be sure to check it is a number > 0. If
not, continue to ask the user for the right number.
Hint: User the handy-dandy Scanner to read user input, the if-else construct to
validate user input and the loop to repetitively ask for user input should you
get an unacceptable value
(c) Create a third array named price, that will hold price-per-item for the items
stored in the first array. The price point for each item should also come from
the user. For example, a notepad could be priced at $1.47, eraser at $0.76 etc.
As in the above case, for each price point input you get from the user, be sure
to check it is a number > 0. If not, continue to ask the user for the right
number for the item price.
The message, for example, could look like “Please enter price for a Notebook”
(d) Based on the type of data that needs to be stored in the above-mentioned
arrays, be sure to use the correct data type


Requirement-2 –Create Operations for an Inventory Manager role
(a) Show Functions List
Once the above data points have been correctly created, you will now need to
build the functional points (operations) for this IMS. But before we do that, we
need tell the user about operations that are available to be invoked by the
user, as part of this IMS. The 5 operations of the IMS are as follows. So, display
these operations to the user and ask the user to enter the letter for the
operation that the user wants to run.
- Print Inventory (p)
- Check for Low Inventory (c)
- Highest/Lowest value inventory Items (h)
- Total Inventory Value (t)
- Exit System (e)
Sample output should look something like the following:
Welcome to IMS. Please select a function from the following:
Print Inventory (p)
Check for Low Inventory (c)
Highest/Lowest value inventory Items (h)
Total Inventory Value (t)
Exit System (e)
(b) PrintInventory (15 pts)
This operation should print inventory, starting with the header, in the
following format
Item_Name Quantity Price Total_Inventory_Value
Eraser 14 $.95 $13.30
Notebook 10 $1.47 $14.70
….
Note:
The last column will show a computed value (price * quantity) for the item
At the end of this operation, go back to displaying the 5 operations that user
can choose from, as in (a) above
(c) checkForInventory
This operation checks for items that have quantity less than 5, and then prints
them in the same format as in (b) above. For example:
Items with quantity less that 5:
Item_Name Quantity Price Total_Inventory_Value
Notebook 7 $1.47 $10.29
Marker 4 $1.02 $4.08
….
….
At the end of this operation, go back to displaying the 5 operations that user
can choose from, as in (a) above
(d) highestAndLowestValueItems
This operation finds the highest, and lowest, value item(s) in inventory,
computed by multiplying the quantity with the price for that item, and then
prints them in the same format as in (b) above.
Highest Inventory Value Items:
Item_Name Quantity Price Total_Inventory_Value
Notebook 7 $1.47 $10.29
Marker 4 $1.02 $4.08
….
Lowest Inventory Value Items:
Item_Name Quantity Price Total_Inventory_Value
Pencil 4 $.74 $2.96
Marker 2 $1.02 $2.04
….
At the end of this operation, go back to displaying the 5 operations that user
can choose from, as in (a) above
(e) totalInventoryValue
This operation simply prints the Grand Total value of the entire inventory. This
will essentially be the summation of all individual total values of each item in
the inventory
At the end of this operation, go back to displaying the 5 operations that user
can choose from, as in (a) above
(f) exit
This operation simply exits the program

Solutions

Expert Solution

package com.example;

import java.util.Scanner;

import static java.lang.System.exit;

public class IMS {
    String items[] = {"Pen", "Pencil", "Eraser", "Marker", "Notepad"};
    int quantity[] = new int[5];
    double price[] = new double[5];

    void initialize() {
        for (int i = 0; i < 5; i++) {
            System.out.println("Please enter quantity for " + items[i]);
            quantity[i] = getValidQuantity(items[i]);
        }

        for (int i = 0; i < 5; i++) {
            System.out.println("Please enter price for " + items[i]);
            price[i] = getValidPrice(items[i]);
        }
    }

    int getValidQuantity(String str) {
        Scanner scanner = new Scanner(System.in);
        int count;
        while (true) {
            count = scanner.nextInt();
            if (count > 0)
                break;
            System.out.println("Please enter valid quantity for " + str);
        }
        return count;
    }

    double getValidPrice(String str) {
        Scanner scanner = new Scanner(System.in);
        double amount;
        while (true) {
            amount = scanner.nextDouble();
            if (amount > 0)
                break;
            System.out.println("Please enter valid price for " + str);
        }
        return amount;
    }

    void printInventoryIndex(boolean[] arr) {
        System.out.println("Item_name\tQuantity\tPrice\tTotal_Inventory_Value");
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]) {
                String str = String.format("%s\t%s\t$%s\t$%s", items[i], quantity[i], price[i], quantity[i] *price[i]);
                System.out.println(str);
            }

        }
    }

    void printInventory() {
        boolean[] arr = {true, true, true, true, true};
        printInventoryIndex(arr);
    }

    void printInventoryLowQuantity() {
        boolean[] arr = {false, false, false, false, false};
        for (int i = 0; i < 5; i++) {
            if (quantity[i] < 5)
                arr[i] = true;
        }
        printInventoryIndex(arr);
    }

    double getMedian () {
        // sort array and return median
        double[] value = new double[5];
        for (int i = 0; i < 5; i++) {
            value[i] = quantity[i] * price[i];
        }

        for (int i = 0; i < value.length; i++) {
            int maxI = i;
            for (int j = i; j < value.length; j++) {
                if (value[j] > value[maxI]) {
                    maxI = j;
                }
            }
            // swap location
            double temp = value[maxI];
            value[maxI] = value[i];
            value[i] = temp;
        }

        return value[2];
    }

    void highestAndLowestValueItems() {
        double[] value = new double[5];
        for (int i = 0; i < 5; i++) {
            value[i] = quantity[i] * price[i];
        }

        double mValue =getMedian();
        // get highest value items

        boolean[] maxarr = {false, false, false, false, false};
        for (int i = 0; i < 5; i++) {
            if (mValue <= value[i]) {
                maxarr[i] = true;
            }
        }

        System.out.println("Highest Inventory Value Items:");
        printInventoryIndex(maxarr);

        // get lowest value items
        boolean[] minarr = {false, false, false, false, false};
        for (int i = 0; i < 5; i++) {
            if (mValue >= value[i]) {
                minarr[i] = true;
            }
        }

        System.out.println("Lowest Inventory Value Items:");
        printInventoryIndex(minarr);
    }

    void totalInventoryValue() {
        double value = 0;
        for (int i = 0; i < 5; i++) {
            value += quantity[i] * price[i];
        }
        System.out.println("Total Inventory Value: $" + value);
    }


    public static  void main(String[] args) {
        IMS ims = new IMS();
        ims.initialize();
        char input;
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("\nPrint Inventory (p)\n" +
                    "Check for Low Inventory (c)\n" +
                    "Highest/Lowest value inventory Items (h)\n" +
                    "Total Inventory Value (t)\n" +
                    "Exit System (e)");
            input = scanner.nextLine().charAt(0);
            switch(input) {
                case 'p':
                    ims.printInventory();
                    break;
                case 'c':
                    ims.printInventoryLowQuantity();
                    break;
                case 'h':
                    ims.highestAndLowestValueItems();
                    break;
                case 't':
                    ims.totalInventoryValue();
                    break;
                case 'e':
                    exit(0);
                    break;
                default:
                    continue;
            }
        }
    }

}



Related Solutions

Python The goal of this assignment is to build a simulation of a popular children’s dice...
Python The goal of this assignment is to build a simulation of a popular children’s dice game named Beat That. Beat That is an educational game in which children learn strategic thinking and the concept of place value. While the rules of the game can be flexible, we will be playing a basic version in which 2 players (Player A and Player B) are rolling 2 dice in a 5-round game. Game play is based on rounds. In each round,...
The assignment is to build a program in Python that can take a string as input...
The assignment is to build a program in Python that can take a string as input and produce a “frequency list” of all of the wordsin the string (see the definition of a word below.)  For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words.  In the output, each line contains of a...
Suppose the interface and the class of stack already implemented, Write application program to ( java)...
Suppose the interface and the class of stack already implemented, Write application program to ( java) 1- insert 100 numbers to the stack                         2- Print the even numbers 3- Print the summation of the odd numbers
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
Your assignment is to build a program that can take a string as input and produce...
Your assignment is to build a program that can take a string as input and produce a “frequency list” of all of the words in the string (see the definition of a word below.) For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words. In the output, each line contains of...
Java program In this assignment you are required to create a text parser in Java/C++. Given...
Java program In this assignment you are required to create a text parser in Java/C++. Given a input text file you need to parse it and answer a set of frequency related questions. Technical Requirement of Solution: You are required to do this ab initio (bare-bones from scratch). This means, your solution cannot use any library methods in Java except the ones listed below (or equivalent library functions in C++). String.split() and other String operations can be used wherever required....
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create a java class InventoryItem which has a String description a double price an int howMany Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one. Write a clone method that uses the copy constructor to create...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods.(Need Comment, Write by Java Code) Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by...
Please do this in java program. In this assignment you are required to implement the Producer...
Please do this in java program. In this assignment you are required to implement the Producer Consumer Problem . Assume that there is only one Producer and there is only one Consumer. 1. The problem you will be solving is the bounded-buffer producer-consumer problem. You are required to implement this assignment in Java This buffer can hold a fixed number of items. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT