First Java Programming Assignment - Grad student needs Help

Thank-you to whomever helps me out here (I have been waiting for the Professor to respond for 2 days now, and our asignment is due by midnight 2-nite. Here is my problem. We have a value called nPer. This value is defined as a double (it needs to since, it perfoms lots of calculations). Now the assigment calls for the print line to display the field in its integer format. So I have done the following:
nPer=Math.ceil(nPer);
This has caused the value to be represented as 181.0. Not good enough! The value needs to be truncated and represented as 181.
The professor has provided us with directions that use the following syntax
(int)181.0
Putting that exact code in my program causes JBuilder to create an error message. Ergo, its not right. I have serached all over the tutorial looking for the proper method to resolve this, however - no luck. Could some kind sole please help??? Thank-you.

You can look at either java.math.BigDecimal, if the
true representation of the value and rounding are a
concern, or java.text.NumberFormat if it's simply a
matter of display.
Your professor must be an old C programmer. Casting a
double to an int? Oh, my. - MODBut that's what his assignment says, display it as an int. And the cast would work; I'm assuming he just didn't use it right.

Similar Messages

  • Grad student needs help with Listener

    I am doing my Masters project on Distributed Database and am trying to connect 4 database to one listener on one machine. The first two appear to connect OK as listenermral and listenermrny. But the next two keep on giving me TNS-01150 errors-address of specified listener name is incorrect. I check with Metadata and the suggestion was to build the listener.ora file with netmgr, but it hangs when I launch it. This is my code:
    LISTENERMRAL=
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL= IPC)
    (KEY = MRAL)
    (ADDRESS =
    (PROTOCOL=TCP)
    (HOST=dilbert)
    (PORT=1521)
    STARTUP_WAIT_TIME_LISTENER = 0
    CONNECT_TIMEOUT_LISTENER = 0
    SID_LIST_LISTENER=
    (SID_LIST=
    (SID_DESC=
    (SID_NAME = MRAL)
    (ORACLE_HOME = /OFA/ORACLE/PRODUCT/10.1.0.3)
    LISTENERMRNY=
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL= IPC)
    (KEY = MRNY)
    (ADDRESS =
    (PROTOCOL=TCP)
    (HOST=dilbert)
    (PORT=1522)
    STARTUP_WAIT_TIME_LISTENER = 0
    CONNECT_TIMEOUT_LISTENER = 0
    SID_LIST_LISTENER=
    (SID_LIST=
    (SID_DESC=
    (SID_NAME = MRNY)
    (ORACLE_HOME = /OFA/ORACLE/PRODUCT/10.1.0.3)
    LISTENERMRTX=
    (ADDRESS_LIST =
    (ADDRESS =
    (PROTOCOL= IPC)
    (KEY = MRTX)
    (ADDRESS =
    (PROTOCOL=TCP)
    (HOST=dilbert)
    (PORT=1524)
    STARTUP_WAIT_TIME_LISTENER = 0
    CONNECT_TIMEOUT_LISTENER = 0
    SID_LIST_LISTENER=
    (SID_LIST=
    (SID_DESC=
    (SID_NAME = MRTX)
    (ORACLE_HOME = /OFA/ORACLE/PRODUCT/10.1.0.3)
    The service_name for all the databases is MR<xx>1.
    The instance_name is the same as the SID
    Thanks in advance for any help

    Fedora is free and Oracle has given it the thumbs up. Plus there are tons of docs available, from installation to trouble shooting. I would go with Fedora, especially since it won't hurt your budget.
    -Raj Suchak
    [email protected]

  • My first java program!! ALMOST done..I hope

    I've just written my first java program (part of a class I'm taking).. It's feeling kinda awkward since I'm a C++ programmer.. I've written most of the code but I'm still having problems and I thought I should show it to you to get some help..
    import java.lang.*;
    import java.util.*;
    public class Dice
    private static Random generator = new Random();
    int Die1, Die2, rolled, pairNum, pairSum;
    public Dice()
       int[] Dice_arr={Die1, Die2};
       new Random(System.currentTimeMillis());
       return;
      }//end_func_Dice
       public static roll()
         rolled = generator.nextInt(6) + 1;
         return rolled;
        }//end_func_roll
       public String toString()
         StringBuffer bfr = new StringBuffer("\n");
         System.out.println("Rolling Dice...");
          for(pairNum=0; pairNum==10; pairNum++)
            System.out.println("Pair"+pairNum+": "+Die1+","+Die2+" Sum= "+pairSum);
           }//end_for_
        }//end_func_ 
    }//end_class_Dice
    public static void main(String args[])
          for (int dieNum=0; dieNum==2; dieNum++)
            Dice.roll();
            Dice_arr[dieNum]=rolled;
           }//end_for_
         return;
        }//end_func_mainI need main to instatiate the Dice class and then use the toString to print the dice numbers and their sum 10 times..
    I hope this doesn't need much effort,
    Thanks a bunch in advance..

    Right now, my opinion in java is that it's too
    complicated for no reason compared to C++..It's not too complicated, it's just that you are new at this.
    Here's a little example of a simple class with a simple main method, the rest figure it out yourself, and with time read some java books, you won't learn java just by knowing C++.
    public class Human {
        // See this as C constants (although they're not their Equivalent)
        public static boolean MALE = true;
        public static boolean FEMALE = false;
        //member variables.
        private String name;
        private boolean sex;
        /** Creates a new instance of Human */
        public Human(String n, boolean s) {
            name = n;
            sex = s;
        }//End of CONSTRUCTOR.
        public String getName() {
            return name;
        }//End of getName
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append("[Name: " + name);
            if(sex)
                sb.append(", sex: Male]");
            else
                sb.append(",sex: Female]");
            String returnValue = new String(sb);
            return returnValue;
        }//End of toString()
        //Just the main program, it could be at another class.
        public static void main(String[] args) {
            Human h = new Human("Pablo", Human.MALE);
            String theHumanAsAString = h.toString();
            System.out.println(theHumanAsAString);
        }//End of main method
    }//End of class

  • Trying to compile my first Java program !

    Hi,
    I am a new programmer.Looking to clarify a very simple doubt while compiling my first java program.
    I have set up jdk in the following directory on my PC , E:\j2sdk1.4.1_01\bin.
    Now when I create the first AClass.java file in the AClass directory under bin and try and compile it I get the following error.
    E:\j2sdk1.4.1_01\bin>java E:\j2sdk1.4.1_01\bin\AClass\AClass
    Exception in thread main
    java.lang.NoClassDefFoundError: E:\j2sdk1/4/1_01\bin\AClass\AClass
    Kindly help me how to fix this.

    hi,
    Just do this,
    set path & classpath either in the system environment veriable or in the command prompt as shown below.
    set PATH=%PATH%;E:\j2sdk1.4.1_01\bin
    set CLASSPATH=%CLASSPATH%;.
    Be careful, there is a trailing DOT (.) at the end of the classpath, and that is what needed for
    the JVM to find the class file. with this you would be able to run your program. Infact JDK1.4.x and higher
    doesn't requires classpath to be set, your system classpath variable needs a DOT (.)
    at the end of the classpath variable defined in the environment variable section of your computer or
    in the command prompt you need it to set it once for the current command prompt window before
    executing any java program.
    Regards
    Goodieguy

  • My first generation ipod touch is disabled. need help to reactavated

    My first generation ipod touch is disabled. need help to reactivated

    Hi noraaziz,
    Thanks for visiting Apple Support Communities.
    If your iPod touch only shows the "Connect to iTunes" screen, see this article for steps that can help:
    iOS: Unable to update or restore
    http://support.apple.com/kb/ht1808
    All the best,
    Jeremy

  • My first java programming - Need some help please!!!

    I have to create a simple java program which i am not good at i am ok in C but my java is quite bad. The program need to define a class called Student and with a string called StudentNAme, a integer StudentID(key), An array of 8 integers called Marks that holds the students marks for 8 modules. It also says Include appropriate accessors, mutators and constructor(s) as well as a method to update the student�s marks. Anybody please help me in this question. I prefer an simple example of this program so I can learn faster, I dont even know how to declare a class.. So sorry but please help me out and thanks in advance

    I would also suggest you try using an IDE like
    eclipse (free)
    www.eclipse.org
    This will help you get a working program much faster.But please do also tell them that if they have troubles using it, they're supposed to read the IDE manual instead of posting here.

  • Need Help with a JAVA programming assignment

    How do I write a JAVA program that could be used as the start of an MS-DOS/Windows simulation of the IEEE 802.3 protocol? I am to only code the parts necessary to build the 802.3 frame. For the initial implementation, the Checksum function need not be a CRC function, and the Destination and Source addresses wil be in input, stored, and output, and in dotted-decimal format.
    I need:
    1. A record to describe the frame, with each field being a (byte-) string of the required size, except that the Data field is of variable size. Although the "Source address" and "Destination address" would be 6 bytes for a real implementation, for this first implementation you can either assume they'll be text strings in the usual "dotted decimal" form (e.g. "14.04.05.18.01.25" as a typical example--from Tanenbaum, p. 429), or 6 hex digits.
    2. Suitable constant declarations for values such as the standard "Preamble" and "Start of Frame" values.
    3. Suitable functions to Get the three variable values "Destination address", "Source address", and "Data" from the standard input device.
    4. A suitable function to display each of the fields of a given frame in a format such as:
    Preamble: ...
    StartofFrame: ...
    Destination: ...
    etc.
    5. A suitable function to generate a "Pad" field if necessary.
    6. A "dummy" Checksum-generating function which just takes the first 32 bits (4 bytes) of the Data (or Data+Pad, if necessary) rather than an actual CRC algorithm.
    I have no experience with Java. Can you help me or start me in the right direction?
    Thanks...........TK

    If you have no experience with Java, then it seems to me your first step should be to start learning the language. But it's difficult to advise how, since we don't know anything about your background. There are many good books available on Java, some are for beginners and some are for advanced programmers, so I'd suggest you go somewhere that has a large selection and start looking for something that doesn't seem completely over your head.

  • New Java Programming Student Needs Help

    Hey everyone,
    I've just started taking a Java programming class at Penn State University, and I have had some prior experience with programming, i.e. C, C++, HTML, SQL. However, this will be my first attempt at Java. I know there are a lot of similarities between C++ and Java, but I'm still a little lost on some methodology.
    To get myself going, I've been looking through the textbook a little and came across a problem that gave me some difficulty. I'll write out the outline:
    A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and time and a half (i.e. 1.5 times their hourly wage) for overtime hours worked, commission workers (who receive $250 plus 5.7% of their gross weekly sales), and pieceworkers (who receive a fixed amount of money per item for each of the items they produce � each pieceworker in this company works on only one type of item).
    +Define a Java class named EmployeePayment that includes functionality to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have paycode 1, hourly workers have paycode 2, commission workers have paycode 3 and pieceworkers have paycode 4.+
    +Define a main method that creates an instance of the EmployeePayment class, and calls the setManagerPay method to set the managers weekly salary to $625.00. The main method should then prompt the user for the paycode ��Enter paycode (-1 to end): �, validate the input and perform the associated processing for that paycode. Your program should allow the user to process employees until a paycode of -1 has been entered. Use a switch structure to compute each employee�s pay, based on the employee�s paycode. Within the switch, prompt the user (i.e. the payroll clerk) to enter the appropriate facts your program needs to calculate each employee�s pay based on that employee�s paycode, invoke the respective method (defined below) to perform the calculations and return the weekly pay for each type of employee, and print the returned weekly pay for each employee.+
    +Define a setManagerPay method that accepts and stores the fixed weekly salary value for managers.+
    +A private instance variable weeklyManagerPay should be defined in the EmployeePayment class to support these accessor and mutator methods.+
    +Define a calcManagerPay method that has no parameters and returns the fixed weekly salary.+
    +Define a calcHourlyWorkerPay method that accepts the hourly salary and total hours worked as input parameters and returns the weekly pay based on the hourly worker pay code description.+
    +Define a calcCommWorkerPay method that accepts the gross weekly sales as an input parameter and returns the weekly pay based on the commission worker pay code description.+
    +Define a calcPieceWorkerPay method that accepts the number of pieces and wage per piece as input parameters and returns the weekly pay based on the piece worker pay code description.+
    +Once all workers have been processed, the total number of each type of employee processed should be printed. Define and manage the following private instance variables (*numManager*, numHourlyWorker, numCommWorker, and numPieceWorker) within the EmployeePayment class. What are the ways in which these variables can be updated?+
    Sorry for the length, but I wanted this to be thorough. Basically, I'm having the most trouble writing the switch statement, and outputting the total number of each type of employee...
    Any help and pointers will be greatly appreciated...thanks all.

    You said you've written C and C++ code before. I don't have an excellent memory but from the little code that I wrote in C, I believe the switch statement is exactly the same.
    Read this: [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html]
    If you're having trouble understanding something post what your specific problem is. No one is going to write your homework for you, but many, myself included, would be more than willing to help if you're really stumped. Just post your concise problem.
    Edited by: sheky on Mar 12, 2008 9:52 PM

  • Intro To Java Programming student needing help on how to download java SDK on 10.6.8

    Hey Ladies and Gents,
    For the past hour I have been trying to download Java SDK for my 10.6.8 Mac. Can someone point me in the right direction. I am taking a course in intro to Java programming and the book I am using isnt as helpful as I hoped.

    SE 6 development kits support SE 5 constructs.  Just watch that you use only SE 5 constructs.  Texts on 5 will not list the 6 constructs, and texts on 6 are available that tell what came when.
    There is another forum (https://discussions.apple.com/community/developer_forums) where "developers" troll for questions to answer, and your developer questions will stay at the top of the list longer than in MacbookPro forum.

  • Assignment Due TODAY - NEED HELP

    My program is below and I have already setup a Client Server Connection for a hangman game, but I need help sending and displaying the options selected by the user. PLEASE HELP
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class ClientApp extends JFrame
        // Declarations used in program
        private Socket server;
        ObjectOutputStream out;
        ObjectInputStream in;
        int length = 0; // Length of word received by Server
        String guess;
        String lines;
        String secret;
        int chances = 0; // Count to Hold no of chances by user
        int categorySelected ;
        // GUI Declarations
        private JButton btnMovies;
        private JButton btnSport;
        private JButton btnExit, btnNew;
        private JButton a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
        private JLabel lblWelcome, lblCategory , lblChances;
        private JPanel pan1, pan2, pan3, pan4, pan5, pan6, pan7, pan8, pan9, pan10;
        private JTextArea answer;
        private JTextField txtCategory, txtChances;
       // CONSTRUCTOR
        public ClientApp()
            setLayout(new FlowLayout());
            pan1 = new JPanel();
            pan3 = new JPanel();
            pan2 = new JPanel();
            lblWelcome = new JLabel("Welcome to Hangman.\n\n Please select a category.");
            pan1.add(lblWelcome);
            btnMovies = new JButton("Movie Titles");
            pan3.add(btnMovies);
            btnSport = new JButton("Sport");
            pan3.add(btnSport);
            btnNew = new JButton("New Game");
            pan3.add(btnNew);
            btnExit = new JButton("Exit");
            pan2.add(btnExit);
            pan9 = new JPanel();
            txtCategory = new JTextField(10);
            pan9.add(txtCategory);
            pan8 = new JPanel();
            answer = new JTextArea(3,30);
            answer.setEditable(false);
            pan8.add(answer);
            add(pan1);
            add(pan3);
            add(pan2);
            add(pan9);
            add(pan8);
            btnExit.addActionListener(
                new ActionListener()
                    public void actionPerformed(ActionEvent event)
                        System.exit(0);
            btnMovies.addActionListener(
                new ActionListener()
                    public void actionPerformed(ActionEvent event)
                       enableButtons();
                       btnSport.setEnabled(false);
                       btnNew.setEnabled(true);
                       txtCategory.setText("Movies");
                       categorySelected = 0;
                       processClient();
            btnSport.addActionListener(
                new ActionListener()
                    public void actionPerformed(ActionEvent event)
                       enableButtons();
                       btnMovies.setEnabled(false);
                       btnSport.setEnabled(false);
                       btnNew.setEnabled(true);
                       txtCategory.setText("Actors Names");
                       categorySelected = 1;
                       processClient();
            btnNew.addActionListener(
                new ActionListener()
                    public void actionPerformed(ActionEvent event)
                        enableButtons();
                        btnSport.setEnabled(true);
                        btnMovies.setEnabled(true);
                        btnNew.setEnabled(false);
                        chances = 0;
                        communicate();
            buttons();
            disableButtons();
            btnNew.setEnabled(false);
            // Attempt to establish connection to server
            try
                // Create socket
                server = new Socket("localhost", 8008);
            catch (IOException ioe)
                System.out.println("IOException: " + ioe.getMessage());
        // Method to add Alphabetic Buttons to GUI
        public void buttons()
                pan4 = new JPanel();
                pan5 = new JPanel();
                pan6 = new JPanel();
                pan7 = new JPanel();
             a = new JButton("A");
             b = new JButton("B");
             c = new JButton("C");
             d = new JButton("D");
             e = new JButton("E");
             f = new JButton("F");
             g = new JButton("G");
             h = new JButton("H");
             i = new JButton("I");
             j = new JButton("J");
             k = new JButton("K");
             l = new JButton("L");
             m = new JButton("M");
             n = new JButton("N");
             o = new JButton("O");
             p = new JButton("P");
             q = new JButton("Q");
             r = new JButton("R");
             s = new JButton("S");
             t = new JButton("T");
             u = new JButton("U");
             v = new JButton("V");
             w = new JButton("W");
             x = new JButton("X");
             y = new JButton("Y");
             z = new JButton("Z");
            pan4.add(a);
            pan4.add(b);
            pan4.add(c);
            pan4.add(d);
            pan4.add(e);
            pan4.add(f);
            pan5.add(g);
            pan5.add(h);
            pan5.add(i);
            pan5.add(j);
            pan5.add(k);
            pan5.add(l);
            pan6.add(m);
            pan6.add(n);
            pan6.add(o);
            pan6.add(p);
            pan6.add(q);
            pan6.add(r);
            pan7.add(s);
            pan7.add(t);
            pan7.add(u);
            pan7.add(v);
            pan7.add(w);
            pan7.add(x);
            pan7.add(y);
            pan7.add(z);
            add(pan4);
            add(pan5);
            add(pan6);
            add(pan7);
            // Button Handler for Alphabet
            ButtonHandler handler = new ButtonHandler();
           a.addActionListener(handler);
           b.addActionListener(handler);
           c.addActionListener(handler);
           d.addActionListener(handler);
           e.addActionListener(handler);
           f.addActionListener(handler);
           g.addActionListener(handler);
           h.addActionListener(handler);
           i.addActionListener(handler);
           j.addActionListener(handler);
           k.addActionListener(handler);
           l.addActionListener(handler);
           m.addActionListener(handler);
           n.addActionListener(handler);
           o.addActionListener(handler);
           p.addActionListener(handler);
           q.addActionListener(handler);
           r.addActionListener(handler);
           s.addActionListener(handler);
           t.addActionListener(handler);
           u.addActionListener(handler);
           v.addActionListener(handler);
           w.addActionListener(handler);
           x.addActionListener(handler);
           y.addActionListener(handler);
           z.addActionListener(handler);
       private class ButtonHandler implements ActionListener
        public void actionPerformed(ActionEvent ae)
                 if (ae.getSource()==a)
                            guess = "a";
                            a.setEnabled(false);
                            sendGuess();
                 if (ae.getSource()==b)
                           guess = "b";
                           b.setEnabled(false);
                           sendGuess();
                 if (ae.getSource()==c)
                             guess = "c";
                             c.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==d)
                             guess = "d";
                             d.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==e)
                             guess = "e";
                             e.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==f)
                             guess = "f";
                             f.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==g)
                             guess = "g";
                             g.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==h)
                             guess = "h";
                             h.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==i)
                             guess = "i";
                             i.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==j)
                             guess = "j";
                             j.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==k)
                             guess = "k";
                             k.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==l)
                             guess = "l";
                             l.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==m)
                             guess = "m";
                             m.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==n)
                             guess = "n";
                             n.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==o)
                             guess = "o";
                             o.setEnabled(false);
                             sendGuess();
                  if (ae.getSource()==p)
                             guess = "p";
                             p.setEnabled(false);
                             sendGuess();
                  if (ae.getSource()==q)
                             guess = "q";
                             q.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==r)
                             guess = "r";
                             r.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==s)
                             guess = "s";
                             s.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==t)
                             guess = "t";
                             t.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==u)
                             guess = "u";
                             u.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==v)
                             guess = "v";
                             v.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==w)
                             guess = "w";
                             w.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==x)
                             guess = "x";
                             x.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==y)
                             guess = "y";
                             y.setEnabled(false);
                             sendGuess();
                 if (ae.getSource()==z)
                             guess = "z";
                             z.setEnabled(false);
                             sendGuess();
            // Method to Disable the buttons          
            public void disableButtons()
                a.setEnabled(false);
                b.setEnabled(false);
                c.setEnabled(false);
                d.setEnabled(false);
                e.setEnabled(false);
                f.setEnabled(false);
                g.setEnabled(false);
                h.setEnabled(false);
                i.setEnabled(false);
                j.setEnabled(false);
                k.setEnabled(false);
                l.setEnabled(false);
                m.setEnabled(false);
                n.setEnabled(false);
                o.setEnabled(false);
                p.setEnabled(false);
                q.setEnabled(false);
                r.setEnabled(false);
                s.setEnabled(false);
                t.setEnabled(false);
                u.setEnabled(false);
                v.setEnabled(false);
                w.setEnabled(false);
                x.setEnabled(false);
                y.setEnabled(false);
                z.setEnabled(false);
            // Method to enable Buttons so user can Click on them
            public void enableButtons()
                a.setEnabled(true);
                b.setEnabled(true);
                c.setEnabled(true);
                d.setEnabled(true);
                e.setEnabled(true);
                f.setEnabled(true);
                g.setEnabled(true);
                h.setEnabled(true);
                i.setEnabled(true);
                j.setEnabled(true);
                k.setEnabled(true);
                l.setEnabled(true);
                m.setEnabled(true);
                n.setEnabled(true);
                o.setEnabled(true);
                p.setEnabled(true);
                q.setEnabled(true);
                r.setEnabled(true);
                s.setEnabled(true);
                t.setEnabled(true);
                u.setEnabled(true);
                v.setEnabled(true);
                w.setEnabled(true);
                x.setEnabled(true);
                y.setEnabled(true);
                z.setEnabled(true);
        public void communicate()
            // The connection has been established - now send/receive.
            try
                //  create channels
                out = new ObjectOutputStream(server.getOutputStream());
                out.flush();
                in = new ObjectInputStream(server.getInputStream());
            catch (IOException ioe)
                JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
            catch (NullPointerException n)
                JOptionPane.showMessageDialog(null,"Error occured...");
        public void processClient()
            try
                // Tells server which category is selected by user
                out.writeObject(categorySelected);
                out.flush();
                secret = (String)in.readObject();
                length = (Integer)in.readObject();
                lines = "";
                for (int x=0;x < length;x++)
                    lines += " - ";
                answer.setText(lines);
                String ToDisplay=""; 
                  for (int q=0; q<secret.length;q++)
                   ToDisplay+=secret.length;
                   answer.setText(" " + ToDisplay); */
                  // String Correctin = (String)in.readObject();
                  // JOptionPane.showMessageDialog(null, Correctin );
            catch (IOException ioe)
                 JOptionPane.showMessageDialog(null, "IO Exception: " + ioe.getMessage());
            catch (ClassNotFoundException cnfe)
                JOptionPane.showMessageDialog(null, "Class not found..." );
        }//end method
        public void sendGuess()
            try
                // Sends the character guessed by user
                out.writeObject(guess);
                out.flush();
                // Chances incremented
                //chances = chances + 1;
                // Calcualates to see whether chances are up
                //if (chances >= 7)
                //    JOptionPane.showMessageDialog(null,"GAME OVER!! You used up all your chances...");
                 //   disableButtons();
            }//end try
            catch (IOException ioe)
                JOptionPane.showMessageDialog(null, ioe.getMessage());
            }//end catch
        }//end method
        public static void main(String[] args)
            ClientApp client = new ClientApp();
            client.communicate();
            client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            client.setSize(500,300);
            client.setVisible(true);     
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    public class ServerApp
         String movies [] = {"shrek","titanic","disturbia","blade","scream"};
         String sport [] = {"tennis","golf","rugby","hockey","soccer","judo"};
         int inCategory; // Category Selected By User
         int selectw; // Random word selected in Array
         String secretword = "";
         int wordlength = 0;
         String guess;
         char letter;
         Random rand = new Random();
         String msg;
         ObjectOutputStream out;
         ObjectInputStream in;
         int chances;
        // Server socket
        private ServerSocket listener;
        // Client connection
        private Socket client;
        public ServerApp()
           // Create server socket
            try {
                listener = new ServerSocket(8008);
            catch (IOException ioe)
              JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
        public void listen()
            // Start listening for client connections
            try
              client = listener.accept(); 
              System.out.println("Server started");       
              processClient();
            }//end try
            catch(IOException ioe)
                JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
            }//end catch   
        public void processClient()
            try
                while(msg != "TERMINATE")
                   //input and output stream
                   out = new ObjectOutputStream(client.getOutputStream());
                   out.flush();
                   in = new ObjectInputStream(client.getInputStream());        
                   //Receiving a category
                   inCategory = (Integer)in.readObject();
                   chances = 7;
                   selectw = 0;
                   if (inCategory == 0)
                        selectw = rand.nextInt(5);
                        secretword = movies[selectw];
                        out.writeObject(secretword);
                        out.flush();
                    }//end if
                    if (inCategory == 1)
                        selectw = rand.nextInt(6);
                        secretword = sport[selectw];
                    }//end if
                        wordlength = secretword.length();
                        out.writeObject(wordlength);
                        out.flush();
                           for (int y=0;y < wordlength;y++)
                                guess = (String)in.readObject();
                                letter = guess.charAt(0);
                                  if(chances == 0)
                                      JOptionPane.showMessageDialog(null,"No more chances left");
                                   else
                                  if(letter == secretword.charAt(y))
                                    JOptionPane.showMessageDialog(null,"You chose a correct letter...");
                                else
                                    JOptionPane.showMessageDialog(null,"You chose a wrong letter...");
                                    chances--;
                        JOptionPane.showMessageDialog(null,"You won the game...");
                }//end while
                // Step 3:close down
                out.close();
                in.close();
                client.close();
                System.out.println("Server stopped");
            catch (IOException ioe)
                JOptionPane.showMessageDialog(null,"IO Exception: " + ioe.getMessage());
            catch (ClassNotFoundException cnfe)
                JOptionPane.showMessageDialog(null,"Class not found: " + cnfe.getMessage());
        public static void main(String[] args)
            // Create application
            ServerApp server = new ServerApp();
            // Start waiting for connections
            server.listen();
    }

    JAVAHELPNEEDED wrote:
    How do I save that amount of code?
    Can you HELP me or NOT??Depends what you mean. Will I write you any code? No. Will I tell you what to write? No. You can do it yourself, that's why it's called your homework. I will, though, give you a couple of tips on how to get started.
    1) Throw away what you've done
    2) Do a quick requirements analysis. That means, write down descriptive, plain English (or whatever language you think in) what the thing is supposed to do. "Be a hangman game" is too brief, but twenty pages of technical jargon is too much. Write a bit of a story about what the program must do. You now have the start of a design.
    3) Break down what has to be done into manageable chunks. Your first mistake (and most newbs) was trying to write one side of the game in a single class. Don't be afraid to write 20 classes, or 50, if that's what's needed. It'll be easier both now and in the long run
    4) Tackle each chunk one by one. Don't try and do it all at once, that never works. If you write the code one bit at a time, you'll inevitably write more modular code
    5) You'll probably screw it up. Don't worry. It happens. Try again
    6) Don't give up. Writing software is hard, there's no way around that, so deal with it
    7) Don't make the mistake of thinking the software is the GUI. It isn't (don't extend JFrame, hint hint)
    8) Good luck

  • Java for Pocket PC 6700, Need Help

    Somebody Please help me! I bought a Pocket PC 6700 With Windows Mobile 5.0. I am trying to run an ".aspx" java supported extension for my Scottrade streaming quotes screen on my Pocket PC. Is there ANY java programs/downloads/patches, anything that will launch this app. with what I got? Im looking for a solution to this problem. Ive came across some research of it being a liscensing problem but I would think this kind of technology would be taken advantage of at this point with these new pocket PC's
    Thanks,
    Eric

    have a look at
    http://java.sun.com/products/personaljava/
    it's free.
    It is quite easy to write applications in Java for Pocket PC. If your are new to Java finde a nice book buy it learn an start. To run the stuff on the Pocket PC install PJava on the device, set the classpath on the Pocket PC (there is a description how to do it in the doc files), make a jar file from your app and transfer it to the Pocket PC: ready to use.
    If you have any specific questions how to use PJava go to the PersonalJava Forum.
    Have Fun!

  • Does the % drop the decimal before or after calculation? Student needs help

    I'm a student taking a course on Java at home and I need to know if in a calculation, the % switch drops the decimal before or after calculation?

    % as in mod, as in remainder? I believe this only works on int/long values, in which case, it would probably be before... but I have been known to be wrong.

  • Java Intro student needs help on arrays

    As my first assignment I have created a program called RobotRat which has a "Rat" move north, south, east, or west on an array floor. I have the program running but am having trouble creating my "floor" using a two-dimensional array. My teacher also wants us to use boolean values for our array. I am drawing a blank on how to create this. From my books I have gathered the following code but cannot get it to work. Any help would be greatly appreciated:
    1.public class RobotRatArray
    2.{
    3.
    4. dataType RobotRatArray[] [];
    5. int matrix [] [];
    6. matrix = new int [20] [20];
    7.
    8.
    9.}

    Okay, I just spoke with a classmate of mine and they said my array isn't in another window. I need to do some system.out.print commands so they print out on my dos window. I am just so confused with this program. I am going to copy and paste it in here in case anyone has any guidance for me. It would be greatly appreciated. (Sorry, I can't figure out how to get my line numbers to populate from textpad when I paste in this message)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class RobotRat extends JFrame implements ActionListener
         private JPanel panel1 = null;
         private JPanel panel2 = null;
         private JPanel panel3 = null;
         private JLabel label1 = null;
         private JLabel label2 = null;
         private JLabel label3 = null;
         private JTextField textfield1 = null;
         private JButton button1 = null;
         private JButton button2 = null;
         private JButton button3 = null;
         private JButton button4 = null;
         private boolean[][] floor = null;
         private int current_column = 21;
         private int current_row = 21;
         private static final int UP = 1;
         private static final int DOWN = 0;
         private static final int NORTH = 0;
         private static final int EAST = 1;
         private static final int SOUTH = 2;
         private static final int WEST = 3;
         private int pen_position = UP;
         private int rats_direction = EAST;
    public RobotRat()
    super("RobotRat");
    label1 = new JLabel("Spaces: ");
    textfield1 = new JTextField(40);
    button1 = new JButton("Move North");
    button2 = new JButton("Move South");
    button3 = new JButton("Move East");
    button4 = new JButton("Move West");
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);
    this.getContentPane().setLayout(new FlowLayout());
    this.getContentPane().add(label1);
    this.getContentPane().add(textfield1);
    this.getContentPane().add(button1);
    this.getContentPane().add(button2);
    this.getContentPane().add(button3);
    this.getContentPane().add(button4);
    this.setSize(600, 100);
    this.setLocation(100, 100);
    this.show();
    public void togglePen()
         switch(pen_position)
              case (UP): pen_position = DOWN;
              label1.setText("DOWN");
              break;
              case (DOWN): pen_position = UP;
              label1.setText("UP");
              break;
              default: break;
    public void turnLeft()
         switch(rats_direction)
              case NORTH: rats_direction = WEST;
              label3.setText("WEST");
              break;
              case EAST: rats_direction = NORTH;
              label3.setText("NORTH");
              break;
              case SOUTH: rats_direction = EAST;
              label3.setText("EAST");
              break;
              case WEST: rats_direction = SOUTH;
              label3.setText("SOUTH");
              break;
    public void move()
         int spaces_to_move = 0;
         try
              spaces_to_move=Integer.parseInt(textfield1.getText());
         catch(Exception e)
         switch(pen_position)
              case UP:
                   switch(rats_direction)
                        case NORTH: ;
                        case SOUTH: ;
                        case WEST: ;
                        case EAST: ;
              break;
              case DOWN:
                   switch(rats_direction)
                        case NORTH: ;
                        case SOUTH: ;
                        case WEST: ;
                        case EAST: ;
              break;
    public void actionPerformed(ActionEvent e)
         if (e.getActionCommand().equals("TogglePen")) {
         togglePen();
         else if (e.getActionCommand().equals("TurnLeft")) {
         turnLeft();
    public static void main(String[] args)
         RobotRat rr = new RobotRat();

  • Im a Uni student&need help:JAVA Final Year Project: Undo Manager Problem

    Hey all,
    Im writing a Final Year Project and have minimal experience writing in JAVA.
    It is an information visualisation assignment which involves reproducing code/text in a reduced format. Sort of to do with Line oriented statistics.
    http://www.cc.gatech.edu/aristotle/Tools/tarantula/continuous.gif
    This image will give you an idea of what im talking about.
    Anyway, i need to know if its possible to get information about individual undos/edits from an undomanager.
    Basically i need to be able to say, for example,
    there are 12 undos
    undo 12 occurs at line X
    undo 11 occurs at line Y
    etc etc
    I need to be able to get this information without actually invoking the Undo last edit call.
    Im bringing the Java undomanager tutorial home but from what ive read it seems like impossible?
    Any and all help appreciated.
    Regards,
    P

    When I was at uni I had to implement that for the text area of an IDE. All I did was rip off the code from the Notepad.java that comes with the SDK.

  • Collage Students need help with Java project(Email Server) whats analysis?

    Hi im studying in collage at the moment and i have just started learning java this semester, the thing is my teacher just told us to do an project in java , since we just started the course and i dont have any prior knowledge about java i was wondering if some one could help me with the project.
    i choose Email Sevice as my project and we have to submit an analysis and design document , but how the hell am i suppose to know what analysis is ? i just know we use ER diagrams & DFD's in the design phase but i dont know what analysis means ?
    could some one tell me what analysis on an email service might be? and what analysis on a subject means? is it the codeing involved or some thing coz the teacher told us not to do any codeing yet so im completly stumped,
    oh and btw we are a group of 3 students who are asking u the help here coz all of us in our class are stupmed ?

    IN case any one is interested this is the analysis i wrote
    ANALYSIS
    Analysis means figuring out what the problem is, maybe what kinds of solutions might be appropriate
    1.     Introduction:-
    The very definition of analysis is an investigation of the component parts of a whole and their relations in making up the whole. The Analysis done here is for an emailing service called Flashmail, the emailing service is used to send out mails to users registered with our service, these users and there log activities will be stored in some where, the most desirable option at this time is a Database, but this can change as the scope of the project changes.
    2.     Customer Analysis:-
    We are targeting only 30 registered users at the moment but this is subject to change as the scale changes of the project .Each user is going to be entitled to 1MB of storage space at this time since we lack the desired infrastructure to maintain anything higher than 1MB but the end vision of the project is to sustain 1000 MB of storage space while maintaining a optimal bandwidth allocation to each user so as to ensure a high speed of activity and enjoyment for the Customer.
    The Service will empower the user to be able to send, read, reply, and forward emails to there specified locations. Since we are working on a limited budget we can�t not at this time enable the sending of attachments to emails, but that path is also left open by modularity of java language, so we can add that feature when necessary.
    3.     Processor Load Analysis:-
    The number of messages per unit time processing power will be determined on hand with various algorithms, since it is best not to waste processor power with liberally distributing messages per unit time. Hence the number of messages will vary with in proportion to the number of registered users online at any given time.
    4.     Database Decision Analysis:-
    The High level Requirements of the service will have to be decided upon, the details of which can be done when we are implementing the project itself. An example of high level requirements are database management, we have chosen not to opt for flat files because of a number of reasons, first off a flat files are data files that contain records with no structured relationships additional knowledge is required to interpret these files such as the file format properties. The disadvantages associated with flat files are that they are not fast, they can only be read from top to bottom, and usually they have to be read all the way through. Though there is are advantages of Flat files they are that it takes up less space than a structured file. However, it requires the application to have knowledge of how the data is organized within the file.
    Good databases have key advantage over flat files concurrency. When you just read stuff from file it�s easy, but tries to synchronize multiple updates or writes into flat file from scripts that run in different process spaces.
    Whereas a flat file is a relatively simple database system in which each database is contained in a single table. In contrast, relational database systems can use multiple tables to store information, and each table can have a different record format.
    5.     Networking Analysis:-
    Virtually every email sent today is sent using two popular protocols known as SMTP (Simple Mail Transfer Protocol) and MIME (Multipurpose Internet Mail Extensions).
    1.     SMTP (Simple Mail Transfer Protocol)
    The SMTP protocol is the standard used by mail servers for sending and receiving email. In order to send email we will first establish a network connection to our SMTP server. Once you have finished sending your email message it is necessary that you disconnect from the SMTP server
    2.     MIME (Multipurpose Internet Mail Extensions)
    The MIME protocol is the standard used when composing email messages.

Maybe you are looking for

  • ITunes not opening and not on the program list to uninstall

    iTunes will not open at all.  I am not getting any error messages.  I see iTunes in the program list but clicking on it does absolutely nothing other than an hourglass for a second or 2.  Then I was thinking to uninstall and reinstall iTunes but it i

  • OSM DataInstance JDBC Adapter: Invalid SQL issue....

    Hi, We are facing one issue while using the database adapter as DataInstance Behavior. Here are the scripts we used for the highlighted parameters: oms:datasource as XPATH: 'mslv/oms/oms1/internal/jdbc/DataSource' oms:sql as XQUERY: <instance name="O

  • Logical and technical routing ?

    What is the difference between logical and technical routing ? Technical routing is a pipeline step and can be monitored only in the Integration Engine and is it that logical routing can be monitored only in RWB ?

  • How can I modify the screen of TCode IW31/IW32/IW33?

    How can I modify the screen of TCode IW31/IW32/IW33? I'm trying to add new fields, so that after inputting the order type and hit on enter, a new field will be added under the Service area. Does anyone knows how can I do it?

  • Can  i use icloud on my iphone 3g

    I've got a macbook pro and a iphone 3g but icloud doesn't seem to work can i use it on the iphone3g?