Can i add an if statement anywhere in this code?

I need to add an if statement anywhere in this code, it doesnt matter where, but if it is nested it would be better. any ideas?
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.util.*;
import static java.lang.System.out;
import java.util.Scanner;
//Defines the counter for the student count and the lists for students
//to be saved in
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);
  //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 );
  //Calculate the total by adding al 5 grade values 
    public double getTotal() { 
      total = (getGrade(1) + getGrade(2) + getGrade(3) + getGrade(4) + getGrade(5));
  //Total value returned for it to be used to calculate the average   
      return total;
  //Average is calculated by dividing the total over the grade
  //counter (number of grades inputted)
    public double getAverage() { 
      return ( (gradeCounter == 0) ? 0 : total / gradeCounter);

//Get input from user for student's 5 grades which are set as Grade 1, 2, 3, 4, 5
  //and each five inputs for the student are saved to their own list along with the
  //student name
  public void processStudents() {
    for (int counter = 0; counter < studentCount; counter++) {
      Student student = new Student();
      student.setStudentName(JOptionPane.showInputDialog("Enter student's name:"));
      student.setGrade(1, Integer.parseInt(JOptionPane.showInputDialog( "Enter the student's grade for Psychology \n(You may ONLY use whole positive numbers ranging from 0 to 10)")));
      student.setGrade(2, Integer.parseInt(JOptionPane.showInputDialog( "Enter the student's grade for Math \n(You may ONLY use whole positive numbers ranging from 0 to 10)")));
      student.setGrade(3, Integer.parseInt(JOptionPane.showInputDialog( "Enter the student's grade for Art \n(You may ONLY use whole positive numbers ranging from 0 to 10)")));
      student.setGrade(4, Integer.parseInt(JOptionPane.showInputDialog( "Enter the student's grade for Science \n(You may ONLY use whole positive numbers ranging from 0 to 10) ")));
      student.setGrade(5, Integer.parseInt(JOptionPane.showInputDialog( "Enter the student's grade for English \n(You may ONLY use whole positive numbers ranging from 0 to 10)")));
      list.add(student);
//Begin printting stage for each student entered
  public void printStudents() {
    for ( int i = 0; i < list.size(); i++ ) {
      Student s = list.get(i);
      printStudent(s);
//Print the student name along with each grade entered separated by commas
//and the total and average values in separate lines
  private void printStudent(Student student) {
    System.out.println("Student Name: "+student.getStudentName()
                      +", Pych: "+student.getGrade(1)
                      +", Math: "+student.getGrade(2)
                      +", Art : "+student.getGrade(3)
                      +", Sci : "+student.getGrade(4)
                      +", Eng : "+student.getGrade(5)
                      +",\n Total  : "+student.getTotal()         
                      +",\n Average: "+student.getAverage()+"\n");
 

Similar Messages

  • Have MacBook Pro (ancient) has 2.16 Ghz Intel Core Duo with 1 GB 667 MHz RAM using OS 10.4.11. Can I upgrade OS? If so, how far? And can I add more memory? I realize this is an old laptop but I need to wait to upgrade to new.

    Have MacBook Pro (ancient) has
    2.16 Ghz Intel Core Duo with
    1 GB 667 MHz RAM
    using OS 10.4.11.
    Can I upgrade OS? If so, how far?
    And can I add more memory?
    I realize this is an old laptop but I need to wait to upgrade to new.

    if it is the core duo, mac OS X 10.6.8., max ram 2gb.

  • In the middle of creating a book in aperture I need more photos. How can I add them to the browser at this stage?

    In the middle of creating a book in Aperture I need more photos. How can I add them to the browser at this stage?

    In the middle of creating a book in Aperture I need more photos. How can I add them to the browser at this stage?
    You can add more images to your book, by dragging them from the browser to your book album. Switch to the Library Inspector, select the album or project with the images in the source list, and then drag these images onto the book icon. That will add them to the book album, and then double click the book album again to continue working with the book.
    Regards
    Léonie

  • How can I add jar files into the namespace in code?

    My friends:
    I need to add jar files into my namespace dynamicly in my code.But the jar files might be repeated, I am not sure.so, i wonder how can I add them into my namespace, ignoring the repeated files?
    This is my code:
    URL[] urlArrayA = new URL[5];
    urlArray[0] = sample1;
    urlArray[1] = sample2;
    URL[] urlArrayB = new URL[5];
    urlArrayB[0] = sample3;
    urlArrayB[1] = sample4;
    URLClassLoader urlClassLoaderA = URLClassLoader.newInstance(urlArrayA);
    URLClassLoader urlClassLoaderB = URLClassLoader.newInstance(urlArrayB);
    how can i visit classes in urlClassLoaderA from classes in urlClassLoaderB?

    could anyone please answer the question for me ? thank you...

  • How can we add field PRCT Grp to FBL3N T.code or is it possible through cus

    Hi,
        Can we add field profit center group in FBL3N T.CODE. I know profit center is already exist, but is there any way to add this field i.e profit center group in the above t.code(fFBL3N).
    or
    Is there any other Transaction code which is similar to FBL3N and also gives us the details of profit center group.
    Thanks & regards,

    Hi,
    if you click in the dynamic selection button, you will be able to specify the profit center you wish.
    The profit center is found directly in the 'Document' part.
    Please check and if happy give POINTS.

  • HT4623 why doesn't my ipod touch have 'software update' on it? I can't add apps on it because of this.

    I have an ipod touch and I can not add apps to it as it is saying I need to update my ipod.
    The trouble is when I go to General - there is no SOFTWARE UPDATE on the ipod.
    What do I do to update it and be able to download apps?
    Please Help!

    The option to update without the computer (Over the air) was made available with iOS 5. If your iDevice is using a version of iOS lower than 5, you will need to use iTunes on your syncing computer to perform the upgrade. Use the Apple link below as a guide for the upgrade.
    http://support.apple.com/kb/HT4972
    Also read the instructions from the section entitled "Update your device using iTunes" at the link below.
    http://support.apple.com/kb/HT4623
    Information regarding transferring purchases from your iDevice to iTunes on your syncing computer can be found at the link below.
    http://support.apple.com/kb/ht1848
    NOTE: The 2nd generation iPod Touch can not be upgraded beyond 4.2.1.

  • I can't figure out what's wrong with this code

    First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
    One two buckle your shoe
    Three four shut the door
    Five six pick up sticks
    Seven eight lay them straight
    Nine ten this is the end.
    The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
    public class PoemSeventeen
    public static void main(String[] args)
    EasyReader console = new EasyReader();
    System.out.println("Enter a number for the poem (0 to quit): ");
    int n = console.readInt();
    if (n = 1) || (n = 2)
    System.out.println("One, two, buckle your shoe");
    else if (n = 3) || (n = 4)
    System.out.println("Three, four, shut the door");
    else if (n = 5) || (n = 6)
    System.out.println("Five, six, pick up sticks");
    else if (n = 7) || (n = 8)
    System.out.println("Seven, eight, lay them straight");
    else if (n = 9) || (n = 10)
    System.out.println("Nine, ten, this is the end");
    else if (n = 0)
    System.out.println("You may exit now");
    else
    System.out.println("Put in a number between 0 and 10");
    I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
    The EasyReader class code:
    // package com.skylit.io;
    import java.io.*;
    * @author Gary Litvin
    * @version 1.2, 5/30/02
    * Written as part of
    * <i>Java Methods: An Introduction to Object-Oriented Programming</i>
    * (Skylight Publishing 2001, ISBN 0-9654853-7-4)
    * and
    * <i>Java Methods AB: Data Structures</i>
    * (Skylight Publishing 2003, ISBN 0-9654853-1-5)
    * EasyReader provides simple methods for reading the console and
    * for opening and reading text files. All exceptions are handled
    * inside the class and are hidden from the user.
    * <xmp>
    * Example:
    * =======
    * EasyReader console = new EasyReader();
    * System.out.print("Enter input file name: ");
    * String fileName = console.readLine();
    * EasyReader inFile = new EasyReader(fileName);
    * if (inFile.bad())
    * System.err.println("Can't open " + fileName);
    * System.exit(1);
    * String firstLine = inFile.readLine();
    * if (!inFile.eof()) // or: if (firstLine != null)
    * System.out.println("The first line is : " + firstLine);
    * System.out.print("Enter the maximum number of integers to read: ");
    * int maxCount = console.readInt();
    * int k, count = 0;
    * while (count < maxCount && !inFile.eof())
    * k = inFile.readInt();
    * if (!inFile.eof())
    * // process or store this number
    * count++;
    * inFile.close(); // optional
    * System.out.println(count + " numbers read");
    * </xmp>
    public class EasyReader
    protected String myFileName;
    protected BufferedReader myInFile;
    protected int myErrorFlags = 0;
    protected static final int OPENERROR = 0x0001;
    protected static final int CLOSEERROR = 0x0002;
    protected static final int READERROR = 0x0004;
    protected static final int EOF = 0x0100;
    * Constructor. Prepares console (System.in) for reading
    public EasyReader()
    myFileName = null;
    myErrorFlags = 0;
    myInFile = new BufferedReader(
    new InputStreamReader(System.in), 128);
    * Constructor. opens a file for reading
    * @param fileName the name or pathname of the file
    public EasyReader(String fileName)
    myFileName = fileName;
    myErrorFlags = 0;
    try
    myInFile = new BufferedReader(new FileReader(fileName), 1024);
    catch (FileNotFoundException e)
    myErrorFlags |= OPENERROR;
    myFileName = null;
    * Closes the file
    public void close()
    if (myFileName == null)
    return;
    try
    myInFile.close();
    catch (IOException e)
    System.err.println("Error closing " + myFileName + "\n");
    myErrorFlags |= CLOSEERROR;
    * Checks the status of the file
    * @return true if en error occurred opening or reading the file,
    * false otherwise
    public boolean bad()
    return myErrorFlags != 0;
    * Checks the EOF status of the file
    * @return true if EOF was encountered in the previous read
    * operation, false otherwise
    public boolean eof()
    return (myErrorFlags & EOF) != 0;
    private boolean ready() throws IOException
    return myFileName == null || myInFile.ready();
    * Reads the next character from a file (any character including
    * a space or a newline character).
    * @return character read or <code>null</code> character
    * (Unicode 0) if trying to read beyond the EOF
    public char readChar()
    char ch = '\u0000';
    try
    if (ready())
    ch = (char)myInFile.read();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (ch == '\u0000')
    myErrorFlags |= EOF;
    return ch;
    * Reads from the current position in the file up to and including
    * the next newline character. The newline character is thrown away
    * @return the read string (excluding the newline character) or
    * null if trying to read beyond the EOF
    public String readLine()
    String s = null;
    try
    s = myInFile.readLine();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (s == null)
    myErrorFlags |= EOF;
    return s;
    * Skips whitespace and reads the next word (a string of consecutive
    * non-whitespace characters (up to but excluding the next space,
    * newline, etc.)
    * @return the read string or null if trying to read beyond the EOF
    public String readWord()
    StringBuffer buffer = new StringBuffer(128);
    char ch = ' ';
    int count = 0;
    String s = null;
    try
    while (ready() && Character.isWhitespace(ch))
    ch = (char)myInFile.read();
    while (ready() && !Character.isWhitespace(ch))
    count++;
    buffer.append(ch);
    myInFile.mark(1);
    ch = (char)myInFile.read();
    if (count > 0)
    myInFile.reset();
    s = buffer.toString();
    else
    myErrorFlags |= EOF;
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    return s;
    * Reads the next integer (without validating its format)
    * @return the integer read or 0 if trying to read beyond the EOF
    public int readInt()
    String s = readWord();
    if (s != null)
    return Integer.parseInt(s);
    else
    return 0;
    * Reads the next double (without validating its format)
    * @return the number read or 0 if trying to read beyond the EOF
    public double readDouble()
    String s = readWord();
    if (s != null)
    return Double.parseDouble(s);
    // in Java 1, use: return Double.valueOf(s).doubleValue();
    else
    return 0.0;
    Can anybody please tell me what's wrong with this code? Thanks

    String[] message = {
        "One, two, buckle your shoe",
        "One, two, buckle your shoe",
        "Three, four, shut the door",
        "Three, four, shut the door",
        "Five, six, pick up sticks",
        "Five, six, pick up sticks",
        "Seven, eight, lay them straight",
        "Seven, eight, lay them straight",
        "Nine, ten, this is the end",
        "Nine, ten, this is the end"
    if(n>0)
        System.out.println(message[n]);
    else
        System.exit(0);

  • How can I add a privacy statement to my outgoing emails, below my signature?

    I'm a therapist and need to have a privacy statement/disclaimer below my signature on my outgoing emails...something like the following:
    STATEMENT OF CONFIDENTIALITY AND PRIVILEGE
    The contents of this e-mail (including its attachments) are intended for the exclusive use of the addressee(s) and may contain confidential or privileged information. Any other distribution, copying or disclosure is strictly prohibited. Email is not a secure medium of communication and should not be used for transmitting private and confidential information.
    How do I add this?? thanks, Karen

    You can set up multiple signatures and select the appropriate one. Or use stationery where the signature and disclaimer are part of the template document. Or use a text clippings tool to insert ready-to-go frequently used snippets such as your disclaimer text. Many users make use of such a tool in lieu of a prepared signature.

  • Can I add a Solid State Hard Drive to a iMac 27' 2.7 if it did not already come with one?

    I am thing about purchasing a brand new Imac 27" 2.7. I do not want to spend the money now to have Apple add one at time of build but may want to add one down the road...is this possible? Can I bring it back to Apple after the fact and have a SSD added???? Please help as this will affect my purchase decsion.

    Apple will not do it for you however you may find AASP's that will. However remember these are not intended to  be upgraded as you are suggesting. First aftermarket SSD's will not work correctly and may overheat the machine, next this may would void the warranty. I would recommend reading the warranty. There are those that will argue with me on this point however I like to error on the side or caution. If the warranty is of no value to you and you just want to save a few bucks you can ask a AASP to do it.
    Another avenue to take and the one I'd recommend is buying a refurbished machine from Apple, they come with the same warranty as a new machine and some do have SSDs.  You don't state where you are from but look at the online store for your country and you should find a section for iMac refurbs. There are many advantages to buying refurbs including saving money, getting a machine more thoroughly tested than new, warranty coverage and eligibility for AppleCare. In addition most people cannot tell a refurb from a new machine, the only difference to most is the box it ships in. One has colorful graphics the other is the same box and packaging sans graphics.  The only downside I can really think of is you may not get the exact configuration you want. Most machines I've seen only have the SSD in them, I haven't seen any with SSD and HD in the refurb section. Not a big deal, just buy FW800 or Thunderbolt EHD and you have a nice solution. Others assume the machine was refurbished because it was flawed in some fashion, that isn't necessarily the case and if it was it was fixed and retested. Machines enter the refurb program for a variety of reasons, last years model, wife makes a husband return an expensive toy, changed his mind and bought a MacBook Pro instead etc.....
    If you really want a new one with an SSD I'd just save a few more bucks and get what you want.

  • Can i add a solid state drive to my late 2006 macbook

    Got a dumb amateur question. I have a 120g hard drive in my late 2006 macbook and two 2 one gig memory cards upgraded from apple when purchased. Can i upgrade to a SSD and more memory on this mac? Can it be done on a amateur level. Is it worth it?

    You should be able to upgrade the memory to as much as 3GB by installing
    one 2-GB RAM, and one 1-GB RAM for that grand total combined amount.
    If your computer is really a MacBook Pro model, the numbers will vary.
    This is a little bit more than the 2GB total officially recognized; some users
    had installed two 2-GB RAM chips, but seldom evidence the extra 1GB.
    •MacBook: How to remove or install memory - Apple Support
    A place to check on slower style SSD upgrade parts for older Macs may be
    OWC macsales.com, as they have some that are about the data rate of
    the older early MacBook computers. Faster ones would be a waste, though
    some are backward compatible to slow computer data transfer rates.
    Also check the OWC for memory. They have RAM based on the correct identify
    of the computer in question and have a good reputation among Apple users.
    There are instructions in their site (free/video) on how to install an SSD. To use
    an external HD enclosure is a suggested method to get the SSD ready, prior to
    attempt to install; then it can be less troublesome. Back up your original HDD
    and system content. If desired, you may be able to use a clone or disk image.
    The iFixit.com repair guides (specific to various models) can be a helpful way
    to look into steps on how to replace and upgrade Mac computers. They're free.
    {There were no replies here when I started... or I wouldn't have bothered}
    Good luck & happy computing!

  • Inspiron 20 3000 can I add a solid state drive to boot for speed ?

    I'm looking to purchase an inspiron 20 3000. I asked sales if I could get it configured with an SSD drive, and they said no. I'd have to purchase it and then the drive myself. But on Dell's web site I don't see any SSD drives, or hybrids listed as compatible. 
    Anybody know if this is possible ?
    Thanks,
    Ed 

    Hi ekratz,
    The system uses normal 2.5 inch mechanical hard drive with hard drive bracket (hard drive case) as the system can be used for SATA III technology hard drives the system should accept SSD drive but Dell has not tested this system with SSD.

  • Please Help - I can't seem to get help anywhere about this issue...

    Hi everybody,
    I have and iBook G4 (Late 2004)
    I also have a Soundblaster 24-Bit Live USB Soundcard.
    I am trying to set it up.
    here's what I do...
    1. Plug in the sound card into my USB port
    2. Open "Audio/MIDI Stup Utility"
    3. Select "Soundblaster 24-Bit Live USB SOundcard" from the menu (the other option is built-in audio)
    4. Click configure speakers (when I open the window it is set to Stere) with the Soundcard plugged in, I can set speaker config to 5.1 and some of the other configurations
    4a. If i create an aggregate device I can use 7.1 (using the headphone jack as another output
    5. Close speaker config window (if I click configure speakers again it still show the 5.1 configuration)
    6. Close "Audio/MIDI Setup Utility"
    6a. If I use iTunes to play music i only get sound from TWO speakers, I quit iTunes, reopen "Audio/MIDI Setup Utility", click configure speakers and the setting is set back to Stereo.
    What on earth is going on???
    regards,
    Pete.
    If a Moderator reads this please don't delete the post because it's in the wrong area, just move it to the relevant area.
    Thanks.

    That device requires a software driver that is not available for Mac OS X. I'm afraid you won't be able to use it with a Mac without the software driver from the manufacturer. While Mac OS X may accurately recognize the device as an audio adapter, to use its full functions you'll need a driver.
    -Doug

  • How can I add a latest tweet box over this image?

    Hi, I have tried to overlay a latest tweet box onto this picture however I am having no luck could you please help me?
    *** willlh.com ***
    This is the website and the tweet box is on the left below the blue twitter logo.
    Any help appreciated,
    thanks,
    WillH

    This is a design composition.  It is NOT a web page layout.  
    http://willlh.com/Website%20Design/Home%20Page%20Website%20Design.jpg
    You have much more work to do before you can use this for a web site.   Work through the following 3-part tutorial.   Although written for Fireworks, the procedure is basically the same no matter which graphics app you use.
    Taking a Fireworks comp to a CSS Layout in DW
    Part 1 - Initial Design
    http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt1.html
    Part 2 - Markup preparation
    http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt2.html
    Part 3 - Layout and CSS
    http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt3.html
    Incidentally, don't use spaces or special characters in folder or file names for the web.  This will create problems for you later.  If you wish, you can use underscores _ or hyphens - between words.  But no spaces.
    Nancy O.

  • I need to reinstall Abobe Acrobat PRO X but can't seem to find it anywhere on this site.

    I have a legitimate license.  Please advise.

    You can download the trial version of the software using the link below and then use your current serial number to activate it.
    Be sure to follow the steps outlined in the Note: Very Important Instructions section on the download pages at this site.
    Acrobat X Pro, Reader, and Suite:
    http://prodesigntools.com/adobe-acrobat-x-10-pro-reader-suite-direct-download-links-ddl.ht ml

  • How can you add an exception if the notification "This Connection is Untrusted" is not seen complete and hence you can't click in the button "I Understand the Risks"?

    When I open the window, I can see the place to sign in; but, where the logo and images (at the top and at the left) must be appear, two separated "Untrusted Connection" certificates appear. But, as the bottom of them isn't visible, I can't make click in "I Understand the Risks". Is there a keyboard shortcut or a way to avoid that certificates?

    Check the date and time in the clock on your computer: (double) click the clock icon on the Windows Taskbar.
    *https://support.mozilla.org/kb/Secure+Connection+Failed
    Rename the file cert8.db to cert8.db.old in the Firefox Profile Folder to remove all intermediate certificates that Firefox has stored by visiting secure websites.<br />
    If that helped to solve the problem then you can remove the renamed file cert8.db.old unless you have user certificates that you may want to export first and import them in the new file.<br />
    Otherwise you can restore the certificates by renaming (copying) the file back to cert8.db<br />
    Firefox will automatically store new intermediate certificates when you visit websites that send them.<br />

Maybe you are looking for