Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The president of Toy R Us needs a report on the company\'s computer software inv

ID: 3633597 • Letter: T

Question

The president of Toy R Us needs a report on the company's computer software inventory. Design a program that will accept the answer to the following questions and store the answers in an array.

What is the title of the software?

How many of (put name of software here) are in stock?

The program should then sort the items so that the records are in order by title or number of stock and display all of the records in alphabetical or numerical order. Decide on the menu options this program needs.

Examples of input could be:
LOTUS 123 54
WordPerfect 26
Microsoft Word 33
Microsoft Excel 11

Have Output similar to the following:

COMPUTERS R US Software Inventory
TITLE QUANTITY
LOTUS 123 54
Microsoft Excel 11
WordPerfect 26
WordPerfect 26

*****IMPORTANT: I use java 1.4.2 and not any newer. Please ensure that the program works with java 1.4.2. classes such as scanner dont work.Lifesaver will be rated if it works well. INCLUDE A SCREENSHOT please!

Explanation / Answer

//ToyCompany .java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class ToyCompany
{
    static ArrayList<String> LstTitle = null;
    static ArrayList<Integer> LstQuantity = null;
    public static void main(String[] args)
    {
        LstTitle = new ArrayList<String>();
        LstQuantity = new ArrayList<Integer>();
        InputStreamReader inp = null;
        BufferedReader input = null;
        int option = 0;
        try
        {
            while(true)
            {
                inp = new InputStreamReader(System.in);
                input = new BufferedReader(inp);
              
                System.out.println("**** COMPUTERS R US Software Inventory ****");
                System.out.println("1. Add New Software Title");
                System.out.println("2. Sort by Title");
                System.out.println("3. Sort by Quantity");
                System.out.println("4. Print the data");
                System.out.println("Choose an action to perrform >> ");
                option = Integer.parseInt(input.readLine());
              
                switch(option)
                {
                    case 1:
                        AddNewTitles(input);
                        break;
                    case 2:
                        sortByTitle();
                        break;
                    case 3:
                        sortByQuantity();
                        break;
                    case 4:
                        Print();
                        break;
                    default:
                        return;
                }
                System.out.println("Do you perform another operation (y/n)? ");
                if(!input.readLine().toLowerCase().equals("y"))
                    break;
            }
        }
        catch(Exception exp){}
    }
  
    private static void AddNewTitles(BufferedReader input) throws IOException
    {
        String strTitle = "";
        System.out.println("What is the title of the software?");
        strTitle = input.readLine();
        LstTitle.add(strTitle);
        System.out.println("How many of "+strTitle+" are in stock?");
        LstQuantity.add(Integer.parseInt(input.readLine()));
    }
  
    private static void sortByTitle()
    {
        for(int i=0;i<LstTitle.size();i++)
        {
            for(int j=i+1;j<LstTitle.size();j++)
            {
               String str1 = LstTitle.get(i), str2 = LstTitle.get(j);
               if(str1.compareTo(str2) > 0)
               {
                   LstTitle.set(i,str2);
                   LstTitle.set(j,str1);
                   int tmpQunatity = LstQuantity.get(i);
                   LstQuantity.set(i,LstQuantity.get(j));
                   LstQuantity.set(j,tmpQunatity);
               }
            }
        }
        Print();
    }
  
    private static void sortByQuantity()
    {
        for(int i=0;i<LstTitle.size();i++)
        {
            for(int j=i;j<LstTitle.size();j++)
            {
                String str1 = LstTitle.get(i), str2 = LstTitle.get(j);
                if(LstQuantity.get(i)> LstQuantity.get(j))
                {
                    LstTitle.set(i,str2);
                    LstTitle.set(j,str1);
                    int tmpQunatity = LstQuantity.get(i);
                    LstQuantity.set(i,LstQuantity.get(j));
                    LstQuantity.set(j,tmpQunatity);
                }
            }
        }
        Print();
    }
  
    private static void Print()
    {
        System.out.println(" COMPUTERS R US Software Inventory");
        System.out.println("TITLE QUANTITY");
        for(int i=0;i<LstTitle.size();i++)
        {
            System.out.println(LstTitle.get(i)+" "+LstQuantity.get(i));
        }
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote