Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: exception handling problem

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default exception handling problem

    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~");
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: exception handling problem

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: exception handling problem

    What part are you having trouble with?

    The Exception class part, the array part, the sorting part (which is extra credit anyway), how to appropriately handle the exception, the entire thing, something else?

Similar Threads

  1. [SOLVED] exception handling
    By Topflyt in forum Exceptions
    Replies: 5
    Last Post: December 22nd, 2011, 12:00 PM
  2. [SOLVED] Exception Handling
    By Melawe in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 21st, 2011, 07:39 PM
  3. Exception handling
    By JavaGirl9001 in forum Object Oriented Programming
    Replies: 1
    Last Post: November 26th, 2011, 08:45 PM
  4. Exception Handling
    By hello_world in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 5th, 2011, 05:47 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM