//~--- JDK imports ------------------------------------------------------------
import java.text.*;
import java.io.Console;
import java.util.regex.*;
import java.util.Arrays;
public class A3P2 {
public static void main(String[] args) {
final int MAX = 25;
String userInput,
str2 = "",
str3 = "",
moreItems = "";
String[] itemNum = new String[MAX];
String[] itemDescription = new String[MAX];
int[] qtyOnHand = new int[MAX];
double[] itemPrice = new double[MAX];
int totalValue = 0,
count = 0, rowNum,
rows = 0,
index = 0,
qoh = 0;
double totalCost, priceIn;
NumberFormat nfc = NumberFormat.getCurrencyInstance(); // To format outputs to currency
boolean blnEntryIsValid = true, blnCodeFound = true;
String error1 = "**ERROR01** - Item number must be five characters\n\n";
String error2 = "\n\n**ERROR02** - Department code does not exist\n\n";
String error3 = "**ERROR03** - Item number must be numeric in last 3 positions";
String error4 = "**ERROR04** - Item description is required and must be max 20 chars";
String error5 = "**ERROR05** - Unit price must be between 0 and 5,000.00";
String error6 = "**ERROR06** - Quantity on hand must be between 0 and 500";
// two-dimm array...row ... col
String[][] strDeptInfo = {
{ "AU", "Automotive" },
{ "CO", "Cosmetics" },
{ "CW", "Childrens Wear" },
{ "EL", "Electronics" },
{ "FD", "Food" },
{ "FR", "Furniture" },
{ "HW", "Hardware" },
{ "JE", "Jewelry" },
{ "KB", "Kitchen & Bath" },
{ "MW", "Mens Wear" },
{ "PH", "Pharmacy" },
{ "TO", "Toys" },
{ "WW", "Womens Wear" }
};
TextIO.putln("JavaMart Inventory System");
TextIO.putln("Programmed by Cal Schroeder");
TextIO.putln("for: Stephen Lawrence");
TextIO.putln();
TextIO.putln();
{
do {
count++;
index++;
TextIO.put("\nEnter Item Number: ");
userInput = TextIO.getlnString().toUpperCase();
TextIO.putln(userInput);
str2 = userInput.substring(0, 2);
str3 = userInput.substring(2, 5);
TextIO.putln("str3 = " + str3);
TextIO.putln("str2 = " + str2);
if ((userInput.length() != 5)) {
blnEntryIsValid = false; // If entry is not 5 characters
TextIO.put(error1 + "\n");
}
{
// Check if first two characters match list
rows = strDeptInfo.length; // Number of rows
blnEntryIsValid = false;
for (rowNum = 0; rowNum < rows; rowNum++)
{
if (strDeptInfo[rowNum][0].compareToIgnoreCase(str2) == 0)
{
blnCodeFound = false;
rowNum = rows - 1; // Allows a quick exit when found
TextIO.putln("Code Found " + str2);
TextIO.putln();
}
}
if (blnCodeFound)
do {
TextIO.putln("**ERROR02** - " + "Department code does not exist");
TextIO.putln("Choose one of the following...");
System.out.println();
for (rowNum = 0; rowNum < rows; rowNum++)
{
TextIO.putln(strDeptInfo[rowNum][0] + " - " + strDeptInfo[rowNum][1]);
}
System.out.println();
}while (blnEntryIsValid);
else
{
//last 3 characters, should be numbers
if (!Character.isDigit(str3.charAt(0)) || !Character.isDigit(str3.charAt(1)) || !Character.isDigit(str3.charAt(2)))
{
TextIO.putln("**ERROR03** - " + "Item number must be numeric in last 3 positions");
blnEntryIsValid = true;
System.out.println();
}
{
//If all is valid then it gets to this point
itemNum[index] = userInput;
}
}
do {
//Enter Description
System.out.println("Enter item Description (1 ~ 20 char): ");
userInput = TextIO.getlnString();
//Inventory item description – must contain a value and be
//less than or equal to 20 characters in length.
if (userInput == null || userInput.length() > 20)
{
blnEntryIsValid = false;
TextIO.putln(error4);
}else
{
// Read values into the array
itemDescription[index] = userInput;
TextIO.putln("Item Desription is " + itemDescription[index] + "\n");
blnEntryIsValid = true;
}
}while (blnEntryIsValid==false);
}do
{
//Unit price
TextIO.putln("Enter unit price: ");
priceIn = TextIO.getDouble();
//Unit price – between 0 and 5,000.00 inclusive.
if (priceIn > 0 || priceIn > 5000)
{
itemPrice[index] = priceIn;
if (priceIn < 0 || priceIn > 5000)
{
blnEntryIsValid = false;
TextIO.putln(error5);
}
else
{
TextIO.putln("\n\nItem Price is " + itemPrice[index] + "\n");
blnEntryIsValid = true;
}do
{
//Quantity on hand
TextIO.putln( "Enter Quantity On Hand" );
qoh = TextIO.getlnInt();
//Quantity-on-hand – between 0 and 500 inclusive.
if (qoh < 0 || qoh > 500)
{
blnEntryIsValid = false;
System.out.println(error6);
}
else
{
qtyOnHand[0] = qoh;
blnEntryIsValid=true;
{
for (rowNum = 0; rowNum < qtyOnHand.length; rowNum++)
showArray(qtyOnHand[rowNum]);
}
TextIO.putln("Any More Items y/n");
moreItems = TextIO.getlnString();
}
}while (!blnEntryIsValid);
}
}while (!blnEntryIsValid);
}while (moreItems.equalsIgnoreCase("y"));
}TextIO.putln("you have entered " + count);
}
}