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

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?
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,...
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.
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
collect or make financial statements of volkswagen company by estimating or assuming the numbers, project pro...
collect or make financial statements of volkswagen company by estimating or assuming the numbers, project pro forma statements and derive Free cash flow
Part C Which of the following set of quantum numbers (ordered n , ℓ , mℓ...
Part C Which of the following set of quantum numbers (ordered n , ℓ , mℓ , ms ) are possible for an electron in an atom? Check all that apply. a) 5, 2, 1, -1/2 B) 3, 3, 1, -1/2 C) 4, 2, 1, -1/2 D) 3, 2, 2, -1/2 E) 3, 2, -3, 1/2 F) 2, 1, 0, 1 G) 4, 3, 4, -1/2 H) -1, 0, 0, -1/2
What additional strategies might a firm employ to send money to another part of the company...
What additional strategies might a firm employ to send money to another part of the company if the firm is operating in a country that blocks funds? In otherwords, Subsidiary A wants to send money to its parent and Subsidiary A is located in a country that regularly blocks funds? In addition, what techniques might the parent use to send money to the subsidiary if its subsidiary is located in a country that blocks funds? Please help me answer this...
3. How might a company make strategic use of countertrade schemes as a marketing weapon to...
3. How might a company make strategic use of countertrade schemes as a marketing weapon to generate export revenues? What are the risks associated with pursuing such a strategy? Your answer should be no less than 300 words and use a case analysis to explain your answer
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT