How can I add error handling facilities to this code?

Hi everyone, i have this code that needs some error handling facilities (messages that warn user the data inputted is not valid that prvent crashing) added to it. I have no idea on how to do it and i accept any ideas. I'll post the code in two sections as it doesnt fit. The code works by recieveing inputs for student grades and calculating the total and the average. That works fine, but i need to include an error handling facility that doesnt allow the user to input letters, special characters or numbers outside the range 1-10. Can anyone help?

Code Part 1:
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.util.*;
//Defines the counter for the student count and uses a usage method to
public class EdronProject {
  private              int           studentCount;
  private static final String        USAGE = "Usage: java EdronProject <student count>";
  private              List<Student> list;
//Set up the counter fo the number of students and the list in which
//each student's information is saved once processed
  public EdronProject(int count) {
    studentCount = count;
    list = new ArrayList<Student>();
//Checks the number or arguments, and it executes the rest of the code
//if there is 1 argument or more (the number of arguments = the number
//of students being processed)
  public static void main( String args[] )  throws NumberFormatException {
   int count = 0;
   switch (args.length) {
     case 1: count = Integer.parseInt(args[0]); break;
     default: System.out.println(USAGE); System.exit(0);
  //Defines method for processing and printing students within the
  //EdronProject class 
    EdronProject edp = new EdronProject(count);
    edp.processStudents();
    edp.printStudents();
  class Student {
  //Define integer values for the 5 subject's grades, the gradeCounter (used
  //in the processing stage) and the student name string
      private int 
                gradeCounter,
                grade1,
                grade2,
                grade3,
                grade4,
                grade5;
     private double total;
     private String studentName;
//Use setter getter methods for the student name to be retrieved
    public void setStudentName(String name) {
       studentName = name;
    public String getStudentName() {
      return( studentName );
//Use setter getter methods for the grades inputted to be retrieved
//by the processing stage
    public void setGrade(int gradeNo, int grade)  throws IllegalArgumentException {
      switch( gradeNo) {
        case 1 : grade1 = grade; break;
        case 2 : grade2 = grade; break;
        case 3 : grade3 = grade; break;
        case 4 : grade4 = grade; break;
        case 5 : grade5 = grade; break;
        default: throw new IllegalArgumentException("ERROR: Bad grade number passed!");
  //Increase grade counter for it to register the number of grades inputted
  //by user
      gradeCounter++;
    public int getGrade(int gradeNo)  throws IllegalArgumentException {
      int grade = 0;
      switch( gradeNo) {
        case 1 : grade = grade1; break;
        case 2 : grade = grade2; break;
        case 3 : grade = grade3; break;
        case 4 : grade = grade4; break;
        case 5 : grade = grade5; break;
        default: throw new IllegalArgumentException("ERROR: Bad grade number passed!");
//Return grade values for them to be used by the processing stage   
      return( grade );
    }

Similar Messages

  • How can I add keywords for SEO into the code?

    How can I add keywords (for SEO) into the code of a Muse designed site?

    You might also be interested in the upcoming MuseJam on Thursday Muse Jam: Search Engine Optimization | Facebook
    Muse Jam: Search Engine Optimization
    Online May 22, 2013
    Join Principal Product Manager Dani Beaumont of the Adobe Muse team as she explores ways within the Muse application to build search engine optimized sites by way of metadata, keywords, H1 definitions, and sitemap generation. After the presentation we'll open the floor to any questions you might with the application.

  • How can i add newly create infotype in t.code po13

    Can any one pl tel me how can i view newly created infotype in t.code PO13
    Edited by: Utkarsh M parikh on Mar 10, 2010 5:29 PM

    See:
    Mac OS X Automation,
    Automated Workflow Tips,
    Introduction to Automator tutorial, and
    a four-parter on Automation in Snow Leopard by Sal Saghoian:
    Snow Leopard Services,
    Services for iPhoto,
    Safari and WebKit integration, and
    Installing and using services.
    Finally, 
    Developing AppleScript Applications and
    Apple's Automator Developer Documentation

  • How can i add a new count to this source code ?

    [4shared.com - document sharing - download db.txt|http://www.4shared.com/file/210566155/c080d93a/db_online.html] Hi everyone
    I have 5 variables
    1. XTSM is between 0~200
    2. XTS is between 0~2
    3. XRX is 0~3
    4. XHAN is 0~7
    5. ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL
    they are related to their with this shape .
    XTSM->XTS->XRX->XHAN->ZHTYPE (Just Logical)
    Please tell me how can i see this output?
    ----Type------------------Total---------------------Total of ZHTYPE-----------------
        XTSM:0/XTS:0               in this case is : 29     TCHF_HLF:28 TCHSD:1 TCHFULL:0
        XTSM:0/XTS:1               No. of found  
        XTSM:0/XTS:2               No. of found  
        XTSM:1/XTS:0               No. of found  
        XTSM:1/XTS:1               No. of found  
        XTSM:1/XTS:2               No. of foundI get XTSM/XTS/TRX/XHAN and now i want count total of this
    ZHTYPE is one of these : (1)TCHF_HLF (2)TCHSD (3)TCHFULL
    they are related to their with this shape .
    * Each XTSM has 3 XTS (0-2)
    * Each XTS has 4 XRX (0-3)
    * Each XRX has 8 XCHAN (0-7)
    * and Each line has a type of ZHTYPE
    This is sample file: 4shared.com - document sharing - download db.txt
    This output with this code is true but I want add ZHTYPE at the end of each line + XTSM/XTS please help me ???(for example this : XTSM:0/XTS:0 : 29 TCHF_HLF:28 TCHSD:1 TCHFULL:0)
    public class Test {
        public static void main(String[] args) throws IOException {
            Test test = new Test();
            test.execute();
        private static String TYPE_XTSM = "XTSM";
        private static String TYPE_XTS = "XTS";
        private static String TYPE_XRX = "XRX";
        private static String TYPE_XHAN = "XHAN";
        private void execute() throws IOException {
            InputStream in = null;
            BufferedReader br = null;
            TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap = new TreeMap<Integer, TreeMap<Integer, Integer>>();
            try {
                in = Test.class.getResourceAsStream("db.txt");
                br = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = br.readLine()) != null) {
                    Record rec = new Record(line);
                    processRecord(xtsmMap, rec);
            } finally {
                if (br != null) {
                    br.close();
            printResults(xtsmMap);
        private void processRecord(
                TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap, Record rec) {
            TreeMap<Integer, Integer> xtsMap;
            if (xtsmMap.containsKey(rec.getXtsm())) {
                xtsMap = xtsmMap.get(rec.getXtsm());
            } else {
                xtsMap = new TreeMap<Integer, Integer>();
                xtsmMap.put(Integer.valueOf(rec.getXtsm()), xtsMap);
            if (xtsMap.containsKey(rec.getXts())) {
                Integer count = xtsMap.get(rec.getXts());
                xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(count
                        .intValue() + 1));
            } else {
                xtsMap.put(Integer.valueOf(rec.getXts()), Integer.valueOf(1));
        private void printResults(
                TreeMap<Integer, TreeMap<Integer, Integer>> xtsmMap) {
            System.out.println("Type\t\tTotal");
            Set<Integer> xtsmSet = xtsmMap.navigableKeySet();
            for (Integer xtsm : xtsmSet) {
                TreeMap<Integer, Integer> xtsMap = xtsmMap.get(xtsm);
                Set<Integer> xtsSet = xtsMap.navigableKeySet();
                for (Integer xts : xtsSet) {
                    Integer count = xtsMap.get(xts);
                    String outputLine = TYPE_XTSM + ":" + xtsm + "/" + TYPE_XTS
                            + ":" + xts + "\t" + count;
                    System.out.println(outputLine);
        private static class Record {
            private Integer xtsm, xts, xrk, xhan;
            Record(String line) {
                StringTokenizer st = new StringTokenizer(line, "/");
                while (st.hasMoreTokens()) {
                    String token = st.nextToken();
                    String type = token.substring(0, token.indexOf(":"));
                    String valueStr = token.substring(token.indexOf(":") + 1, token
                            .length());
                    Integer value = Integer.valueOf(valueStr);
                    if (TYPE_XTSM.equals(type)) {
                        xtsm = value;
                    } else if (TYPE_XTS.equals(type)) {
                        xts = value;
                    } else if (TYPE_XRX.equals(type)) {
                        xrk = value;
                    } else if (TYPE_XHAN.equals(type)) {
                        xhan = value;
            public Integer getXtsm() {
                return xtsm;
            public Integer getXts() {
                return xts;
            public Integer getXrk() {
                return xrk;
            public Integer getXhan() {
                return xhan;
    }I want add ZHTYPE to this ...
    Code:
    Type        Total
    XTSM:0/XTS:0    29        such as this : TCHF_HLF:28 TCHSD:1 TCHFULL:0
    XTSM:0/XTS:1    29
    XTSM:0/XTS:2    29
    XTSM:1/XTS:0    29
    XTSM:1/XTS:1    29
    XTSM:1/XTS:2    29
    XTSM:2/XTS:0    29
    XTSM:2/XTS:1    29
    XTSM:2/XTS:2    29
    XTSM:3/XTS:0    14
    XTSM:3/XTS:1    14
    XTSM:3/XTS:2    14
    XTSM:4/XTS:0    13Thanks a lot.

    http://www.4shared.com/file/210566155/c080d93a/db_online.html

  • How can I add a search filter by EAN (code of items) in my application?

    I have to filter my list of item (product) by their code. Someone can eplain me how can i do it? I'm new with CF. Thanks.

    I think you need to be more specific about what you are trying to do.  When you say "filter my list..." do you mean in a database query, in a full-text search, or do you mean filter a displayed list based on some user interaction?

  • How can I add error/console log to a submitted form?

    I created a form that I distribute manually over a dedicated server.  The form is to be filled using Reader and it is then validated and submitted by email using a custom script.  I retreive some data collected during validation and have it pasted to the body of the email as a way to identify what went wrong during the filling of the form. Now I'm wondering, is it possible to generate a log file and/or retreive any data from either the console or anything else which could help me identify JS bugs encountered by the user or eliminate some leftovers from previous scripts and paste it as well in the body of the email? Or, is there already a console log inside the file somewhere and I just need to reach it?

    You can't extract data from the console, and the text that is output to the console is not saved into any local file, as far as I'm aware.

  • How can I handel errors in .ksh file

    Hi All
    I am writing a .ksh file which will create FTP a file to the ftp location ..
    My file looks like this :-
    cd ${RUNTIME}
    NOW=$(date +"%y%m%d%H%M%S")
    ftp -i -n -v ${TEST_TP_SERVER} <<END
    user $TEST_TP_USER_ID $TEST_TP_USER_PWD
    lcd ${OUTDIR}
    put "TEST.txt" "$NOW.ABC"
    quit
    END
    My question is how can I handel errors here in this file . If something happens after cd ${RUNTIME} line then I can write like this :
    if [ "$?" -ne "0" ]; then echo "Can not connect , wrong user name / password " exit 1 fi 
    But after ftp -i -n -v ${TEST_TP_SERVER} <<END line I cant write the same . So can anyone please tell me how can I write error handling part after FTP command ?

    Moreover, I need to send that page as a whole by email, so even if the white spaces between parts of picture
    could be removed during printing, it wouldn't be a solution =(
    You can email the new PDF document.

  • How can i add a new 53 rd week to calendar

    Hi All,
    we have requirment i need to add a new week to fiscal year 2011 for septemebr,2011
    Please let me know how can i add a new week to this month,
    Thanks & regards,
    Chand

    Hi All,
    we have requirment i need to add a new week to fiscal year 2011 for septemebr,2011
    Please let me know how can i add a new week to this month,
    Thanks & regards,
    Chand

  • How can I add a client wireless usig Airport Utility 6.0?

    In menu airport of firmware 6.0 there is not window "Add a wireless client". I'm using Mac Os lion with Airport Utility6.0, how can I add a client wireless with this firmware)?

    If you have a dual band AirPort Extreme, you can add another to "extend" both bands of your network to provide more  wireless coverage.
    The "best" way to do this is to connect the "remote" access point back to your main AirPort Extreme using an Ethernet connection. This preserves bandwidth on the network better than any other method...and...you can locate the "remote" Extreme exactly in the area where more coverage is needed. Instructions for thhis are here:
    http://support.apple.com/kb/HT4260
    You might be able to connect using wireless only, but this is always "Iffy".
    In general, the Extreme would need to be located approximately half the distance from your main router to the general area that needs more coverage. But, walls, ceilings and other obstructions usually come into play, requiring some experimentation. Instructions are here:
    http://support.apple.com/kb/HT4259
    If you elect to try wireless, you really won't know if things will work until you try. Recommend that you have a "Plan B" if wireless does not work for your purpose.

  • How can I add my PC Laptop to my iCloud updates?

    I currently update my iphone, ipad and PC through the icloud.  How can I add my PC Laptop to this routine?

    The first question is how many iCloud accounts are you using with your various devices?  They should all be using the same Apple ID/password.  Look at each device/computer and check to see which account (which ID) they each use.

  • How can I define "java.util.ResourceBundle" in my Code ?

    Dear Mr. MLRon,
    Thanks to you for your replying to me.
    How can I define "java.util.ResourceBundle" in my Code ? To more understanding about my problem I can say that the Persian Font is Like as Arabic, but the Java can not Recognize it. please tell me how can I add "java.util.ResourceBundle" to my code and what should I do then?
    Thank you in advance,
    Tantan.

    Please stop starting new threads for this. Please reply in the original thread!
    http://forum.java.sun.com/thread.jspa?threadID=627917

  • How to Setup Forward Error Handling in PI Scenarios. Can you help me with the same with screen shots if possible?

    Dear all
    How to Setup Forward Error Handling in PI Scenarios. Can you help me with the same with screen shots if possible?
    Thanks
    Regards
    karan

    Hello
    These are the following errors
    1. Trace level="1" type="T">no interface action for sender or receiver found</Trace>
    2. <Trace level="1" type="System_Error">Application-Error exception return from pipeline processing!
    3.
    <Trace level="1" type="T">Application Error at Receiver... => ROLLBACK WORK</Trace>  
    <Trace level="1" type="T">System Error at Receiver... => ROLLBACK WORK</Trace>  
    <Trace level="1" type="B" name="CL_XMS_MAIN-WRITE_MESSAGE_LOG_TO_PERSIST" />  
    <Trace level="1" type="System_Error">Application-Error exception return from pipeline processing!</
    Trace level="3" type="T">No persisting of message after plsrv call, because of config</Trace>Trace level="3" type="T">Error of the prevous version:</TraceTrace level="3" type="T">Error ID APPLICATION_ERROR</Trace>
    tThere are repeating errors also.
    TThanks
    Regards
    kkaran

  • How can I add logic control with timeout in OSB?

    In the proxy service, when I try to call business service, the business service may timeout, how can I add logic with this? Like, I can set the timeout to 20 seconds, if more than 20 seconds, then do something else. But I just want this service can set to 20 seconds, others may different. Is that possible? Thanks.

    There is a Read Timeout and Connection Timeout setting in the Business service configuration.
    You can change the default values and test.Inside the error handler you can choose to do something else after you 20 seconds.
    Test and let us know if it works.

  • How can I add a field to a Repeating Frame in the body of a 9i Report

    How can I add a field to a Repeating Frame in the body of an Oracle 9i Report whose source is in a higher group?
    I want to change an Oracle 9i report. The report has no header or trailer but only a body. The body has the parent frame fields & a repeating frame with four fields, A, B, C & D. They all seem to be in one group. I want to add another field E to the repeating frame whose source is from the 'header'.
    I added the field & created a boiler plate & then added the new field, E to the original group A, B, C & D. In the Property Inspector for the field, I pointed the source to the source column in the main query. However, when I run the report, I receive the error "Invalid body size". Some notes on Metalink indicate that this could be due to margins being out of the printable area.
    Moreover, after making the changes & after having unsuccessfully run the report, when I try to open the Page Layout for the report, I get no details.
    Thanks,

    Hi,
    i also got same query can u pls tell me elaborately, if u can can u pls send some code.
    Thanks & Regards
    Jagadeeshwar.B

  • How can I add a new column in compress partition table.

    I have a compress partition table when I add a new column in that table it give me an error "ORA-22856: CANNOT ADD COLUMNS TO OBJECT TABLES". I had cretaed a table in this clause. How can I add a new column in compress partition table.
    CREATE TABLE Employee
    Empno Number,
    Tr_Date Date
    COMPRESS PARTITION BY RANGE (Tr_Date)
    PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
    PARTITION JUNK Values LESS THAN (MAXVALUE));
    Note :
    When I create table with this clause it will allow me to add a column.
    CREATE TABLE Employee
    Empno Number,
    Tr_Date Date
    PARTITION BY RANGE (Tr_Date)
    PARTITION FIRST Values LESS THAN (To_Date('01-JUL-2006','DD-MON-YYYY')),
    PARTITION JUNK Values LESS THAN (MAXVALUE));
    But for this I have to drop and recreate the table and I dont want this becaue my table is in online state i cannot take a risk. Please give me best solution.

    Hi Fahed,
    I guess, you are using Oracle 9i Database Release 9.2.0.2 and the Table which you need to alter is in OLTP environment where data is usually inserted using regular inserts. As a result, these tables generally do not get much benefit from using table compression. Table compression works best on read-only tables that are loaded once but read many times. Tables used in data warehousing applications, for example, are great candidates for table compression.
    Reference : http://www.oracle.com/technology/oramag/oracle/04-mar/o24tech_data.html
    Topic : When to Use Table Compression
    Bug
    Reference : http://dba.ipbhost.com/lofiversion/index.php/t147.html
    BUG:<2421054>
    Affects: RDBMS (9-A0)
    NB: FIXED
    Abstract: ENH: Allow ALTER TABLE to ADD/DROP columns for tables using COMPRESS feature
    Details:
    This is an enhancement to allow "ALTER TABLE" to ADD/DROP
    columns for tables using the COMPRESS feature.
    In 9i errors are reported for ADD/DROP but the text may
    be misleading:
    eg:
    ADD column fails with "ORA-22856: cannot add columns to object tables"
    DROP column fails with "ORA-12996: cannot drop system-generated virtual column"
    Note that a table which was previously marked as compress which has
    now been altered to NOCOMPRESS also signals such errors as the
    underlying table could still contain COMPRESS format datablocks.
    As of 10i ADD/SET UNUSED is allowed provided the ADD has no default value.
    Best Regards,
    Muhammad Waseem Haroon
    [email protected]

Maybe you are looking for

  • Error While activating Sender agreement having WS Sender Adapter.

    Hi all, I am very new to this technology. I have done Demo example Agency. I configured all the objects. While activating sender agreement having WS adapter as sender adapter, I am gettign the following errors. 1.  Field Receiver Communication Party

  • I can't burn a cd from Itunes.

    I can't burn a cd from Itunes....If I try to burn a playlist it says i need multiple cd's and I only have 5 songs on that playlist. If I try to burn it anyway it doesn't do anything.

  • Java app. consuming 100% of PC resouces

    I have an application that works great with the exception that it comsumes all resouces on a PC running Windows 2000 or XP. When the application is running multitasking by the OS is nearly disabled. Looking at resouces consumed, the Java application

  • How do i limit the number of simultaneous downloads to my ipod touch?

    I just purchased a new ipod touch and want to dump my entire icloud library onto it.  I figured the easiest way to do this would be to make a smart playlist that includes all my music and then just download the whole playlist (thousands of songs).  T

  • USB Flash Drive Problems

    Hi I have found 2 problems when using USB flash drives. I have a 1GB USB drive that works fine on my iMac running OS X 10.4.7. However, when I delete files on the drive, my USB space capacity does not free up. I realised that what happens is the file