10.3:
Design and implement a program that creates an exception class called
InvalidDocumentCodeExeception, designed to be thrown when an improper designation
for a document is encountered. during processing. Suppose in a particular business
all documents are given a two-character designation starting with either U, C, or P,
standing for unclassified, confidential, or proprietary. If a document designation is
encountered that description, the exception is thrown. Create a driver program to test
the exception, allowing it to terminate the program.
DONE
10.4:
Modify the solution to PP 10.3 (above) such that it catches and handles the exception
if it is thrown. Handle the exception by printing the appropriate message and then
continue processing.
DONE
anyways i've completed Programming Projects 10.3 and 10.4, the code is below
however I have no idea what this other stuff is about :
For this lab you will combine Programming Projects 10.3 and 10.4 in your
textbook on pages 580 and 581.
You solution should include a “Driver” program that tests the exception. To do
this, you will need to create a class that holds information about Documents you
are processing. You may choose what that document contains (ie: Vendor Name,
Total Sale, Client Name, Type of Lawsuit, ……. You choose, but it must include
Document Code).
Your “Driver” program should include a loop so the user can enter information for
a number of documents. Use an Array to hold the Document Objects.
Entering an improper Document Code should trigger the exception. Your code
should handle the exception, and allow the user to enter more documents.
When the user is done entering Document information, print the contents of your
array.
Extra Credit: sort your array before printing.
can someone please tell me what its asking and how to implement it
cuz I have no idea :S
any help will be much appreciated
thanks
--------------
code:
public class InvalidDocumentCodeException extends Exception{
public InvalidDocumentCodeException(){
}
public String getMessage(){
return "Document code must be U (Unclassified), C (Confidential), or P (Proptietary)." +
"\nDocument will default to Unclassified.";
}
}
public class Document {
private String dType = "U";
public Document(String docType){
try{
if( docType.compareToIgnoreCase("U") != 0
&& docType.compareToIgnoreCase("C") != 0
&& docType.compareToIgnoreCase("P") != 0 )
throw new InvalidDocumentCodeException();
dType = docType;
}
catch(InvalidDocumentCodeException e){
System.out.println("Exception caught and handled! Continuing...");
System.out.println(e.getMessage());
}
}
public void setDocType(String docType){
dType = docType;
}
public String toString(){
return "Document type: "+ dType.toUpperCase();
}
}
import java.util.Scanner;
public class Starter {
public static void main(String[] args) {
String done = "DONE";
System.out.println("DocType? U = Unclassified, C = Confidential, P = Proprietary.");
System.out.println("Type DONE, in all caps to end.");
Scanner scan = new Scanner(System.in);
String docType = scan.next();
while(docType.compareTo(done) != 0){
Document doc = new Document(docType);
System.out.println(doc);
docType = scan.next();
}
System.out.println("Program Fin~");
}
}