Question

In: Computer Science

A company accepts user orders by part numbers interactively. Users might make the following errors as...

A company accepts user orders by part numbers interactively. Users might make the following errors
as they enter data:
 The part number is not numeric. u The quantity is not numeric.
 The part number is too low (less than 0).
 The part number is too high (more than 999).
 The quantity ordered is too low (less than 1).
 The quantity ordered is too high (more than 5,000).
Create a class that stores an array of usable error messages; save the file as DataMessages.java. Create a
DataException class; each object of this class will store one of the messages. Save the file as
DataException.java. Create an application that prompts the user for a part number and quantity. Allow
for the possibility of nonnumeric entries as well as out-of-range entries, and display the appropriate
message when an error occurs. If no error occurs, display the message “Valid entry”. Save the program
as PartAndQuantityEntry.java.

Solutions

Expert Solution

PartAndQuantityEntry.java

import java.util.*;
import java.util.Scanner;
import java.lang.*;
public class Main{
    public static void PartAndQuantityEntry(String[] args)
    {
        
        DataMessages datamsg=new DataMessages();
        DataException obj1=new DataException(datamsg.msg[0]);
        DataException obj2=new DataException(datamsg.msg[1]);
        DataException obj3=new DataException(datamsg.msg[2]);
        DataException obj4=new DataException(datamsg.msg[3]);
        DataException obj5=new DataException(datamsg.msg[4]);
        DataException obj6=new DataException(datamsg.msg[5]);
        
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter part number and quantity : ");
        String pn=sc.next();
        String qn=sc.next();
        int flag1=1,flag2=1,flag3=1,flag4=1,flag5=1,flag6=1;
        
        for(int i=0;i<pn.length();i++)
        {
            if(i==0&&pn.charAt(0)=='-')
            continue;
            if(pn.charAt(i)!='0'&&pn.charAt(i)!='1'&&pn.charAt(i)!='2'&&pn.charAt(i)!='3'&&pn.charAt(i)!='4'&&pn.charAt(i)!='5'&&pn.charAt(i)!='6'&&pn.charAt(i)!='7'&&pn.charAt(i)!='8'&&pn.charAt(i)!='9')
            flag1=-1;
        }
        for(int i=0;i<qn.length();i++)
        {
            if(i==0&&qn.charAt(0)=='-')
            continue;
            if(qn.charAt(i)!='0'&&qn.charAt(i)!='1'&&qn.charAt(i)!='2'&&qn.charAt(i)!='3'&&qn.charAt(i)!='4'&&qn.charAt(i)!='5'&&qn.charAt(i)!='6'&&qn.charAt(i)!='7'&&qn.charAt(i)!='8'&&qn.charAt(i)!='9')
            flag2=-1;
        }
        
        if(flag1!=-1&&Integer.parseInt(pn)<0)
        flag3=-1;
        if(flag1!=-1&&Integer.parseInt(pn)>999)
        flag4=-1;
        if(flag2!=-1&&Integer.parseInt(qn)<0)
        flag5=-1;
        if(flag2!=-1&&Integer.parseInt(qn)>5000)
        flag6=-1;
        
        String result="";
        if(flag1!=-1&&flag2!=-1&&flag3!=-1&&flag4!=-1&&flag5!=-1&&flag6!=-1)
        result="Valid Entry";
        else
        {
            result+=(flag1==-1)?obj1.err+"\n":"";
            result+=(flag2==-1)?obj2.err+"\n":"";
            result+=(flag3==-1)?obj3.err+"\n":"";
            result+=(flag4==-1)?obj4.err+"\n":"";
            result+=(flag5==-1)?obj5.err+"\n":"";
            result+=(flag6==-1)?obj6.err+"\n":"";
        }
        System.out.println(result);
    }
}

Explanation:

DataMessages.java

import java.util.*;

public class DataMessages
{
  
String[]msg =
  {
  "The part number is not numeric.","The Qunatity  is not numeric.", "The part number is too low.",
      "The part number is too high.", "The quantity ordered is too low.",
      "The quantity ordered is too high."};


}

DataException.java

import java.util.*;
public class DataException{
    String err="";
    DataException(String str)
    {
        this.err=str;
    }
}

Related Solutions

Draw a flowchart and pseudocode that accepts three numbers from a user and displays a message...
Draw a flowchart and pseudocode that accepts three numbers from a user and displays a message if the sum of any two numbers equals the third. Make a working version of this program in Python.
What types of defects or errors might the following organizations measure and improve as part of...
What types of defects or errors might the following organizations measure and improve as part of a Six Sigma initiative – Metropolitan Bus company and Walt Disney World?
In C++, Write a program that accepts exactly ten (10) integer numbers from the user. When...
In C++, Write a program that accepts exactly ten (10) integer numbers from the user. When the user is done inputting these numbers, the program prints back: (i) the sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value from the 10 numbers.
Phorwex Canada Inc. is a cleaning and hygiene catalogue company that accepts customer orders by phone,...
Phorwex Canada Inc. is a cleaning and hygiene catalogue company that accepts customer orders by phone, online, and mail. About 75% of customer orders are received by phone; salespeople complete the paper order and send it (by fax) to the main office for shipping. The remaining orders are mainly online with very few sent through postal mail. The company has experienced many issues with customer orders in terms of delays in data entry, errors in customer information, incorrect order details,...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors...
Part 1: Find and fix errors and add following functionalities 1. There are several syntax errors in the code that are preventing this calculator from working, find and fix those errors. When they are fixed, the number buttons will all work, as well as the + (add) and -- (decrement) buttons. a. To find the errors, open up the Developers Tool of the browser and look at the console (F12). Verify the add functionality works. For a binary operator, you...
How might the following errors affect the concentration of the standard 0.0600 M solution?    Weighing...
How might the following errors affect the concentration of the standard 0.0600 M solution?    Weighing - out 1.2 g of CuCl2 anhydrous instead of 1.2 g of CuCl2 •2H2O. Over - diluting the stock solution. Not all of the CuCl2 dissolved in the stock solution. 1. Increases the concentration. 2. Decreases the concentration. 3. Concentration is not affected.
Python: I want to make the following code to prompt the user if want to run...
Python: I want to make the following code to prompt the user if want to run the software again. I am new to python, so i do not know if it works like c++. If can explain that would be much appreciated base = float(input("Enter base of the triagle: ")) Triangle_Right = float(input("Enter right side of the triagle: ")) Triangle_Left = float(input("Enter left side of the triagle: ")) height = float(input("Enter the height of the triangle: ")) perimiter = base...
Takke Company orders 10 inventory part items on a purchase order. All 10 items are received...
Takke Company orders 10 inventory part items on a purchase order. All 10 items are received along with the bill. Takke Company opens a bill form and selects the vendor. What is the next step? Select one: A. Takke should add the items (including quantities) from the purchase order to the bill. B. Takke should close the bill form, open the purchase order, and select Create Bill. C. Takke should manually enter the items and quantities received in the item...
Question 24 Part A Each of the following sets of quantum numbers is supposed to specify...
Question 24 Part A Each of the following sets of quantum numbers is supposed to specify an orbital. Choose the one set of quantum numbers that does not contain an error. n = 3, l = 2, ml =+3 n = 4, l = 4, ml =0 n = 4, l = 0, ml =-1 n = 5, l = 3, ml =-3 n = 3, l = 1, ml = -2
Describe different roles that an insurance company might create to manage user groups. This is for ORACLE 12c: SQL
Describe different roles that an insurance company might create to manage user groups. This is for ORACLE 12c: SQL
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT