1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

Any Java experts

Discussion in 'BBS Hangout' started by clutchdream, Feb 19, 2002.

  1. clutchdream

    clutchdream Member

    Joined:
    Jan 20, 2001
    Messages:
    137
    Likes Received:
    0
    I need help understanding arrays and wrapper classes in java. Also What is the exact function of accessors and mutators?? Anyone know a good site where i could get some help. I kno
     
  2. clutchdream

    clutchdream Member

    Joined:
    Jan 20, 2001
    Messages:
    137
    Likes Received:
    0
  3. Mango

    Mango Member

    Joined:
    Sep 23, 1999
    Messages:
    10,174
    Likes Received:
    5,626
    <A HREF="http://developer.java.sun.com/developer/onlineTraining/">Sun tutorials</A>


    Mango
     
  4. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    What exactly does this mean because I have to turn it in tomorrow. Here is the assignment:

    Write a program that will determine the area of a triangle by using the lengths of the sides. Assume the lengths entered by the user are all positive and that the sides are of an actual triangle. (In other words, you do not need to check these things.) Use the JOptionPane class for both input and output.

    Variable declarations and how to determine the square root are due Wed.

    What are variable declarations??? :confused: And how do you determine the square root??? :confused:
     
  5. movement

    movement Member

    Joined:
    Aug 9, 2001
    Messages:
    212
    Likes Received:
    0
    If I've got the right term logy, variable delclarations are simply stating what variables will hold the user's input.
    double x, y, z;

    I don't know how in depth your assignment is, but with Java there are pre-written classes that have common math functions used a lot.
    import java.lang.*;
    Math.sqrt(num);

    I too am taking a programming class this semster, and it's stressing me out!

    For arrays: http://www.echoecho.com/javascript10.htm
     
    #5 movement, Feb 20, 2002
    Last edited: Feb 20, 2002
  6. paikj83

    paikj83 Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    Don't forget to import the package for the JOptionPane class. I believe it's javax.swing.*. An example of something you might use in your program would be:

    import javax.swing.*;

    public class Example {
    public static void main(String[] args) {
    String input = JOptionPane.showInputDialog("Enter a side");
    double x = Double.parseDouble(input);
    JOptionPane.showMessageDialog(null, "You entered " + input);
    }
    }

    Something like that.

    http://java.sun.com/j2se/1.3/docs/api/

    That's a good link to have. Hope I helped out somewhat.
     
  7. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Hey movement and paikj83 that helps out a lot. Thanks.
     
  8. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Another question, can your variables be anything??? Like, instead of naming them x y z or a b c could I name them anything I want such as side 1 side 2 side 3 or length a length b length c or just any crazy thing because my teacher said to choose some good variable names so did she mean for me to pick or make up a name? Sorry if this stupid question but it's only my second Java program.
     
  9. paikj83

    paikj83 Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    You could name then anything, with the restriction being it has to start with a letter. It can contain any alphanumeric symbol along with the underscore. So things like side1, side_2, and sideThree are all valid variable names.
     
  10. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    I keep getting errors on this program (in above post) I keep trying. How do I enter variables for the sides and make them where they will multiply, that's thee rror I keep getting, something like cannot perform operator on String...
     
  11. paikj83

    paikj83 Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
    String input = JOptionPane.showInputDialog("Enter a side");
    double x = Double.parseDouble(input);
    JOptionPane.showMessageDialog(null, "You entered " + input);


    The first statement gets the input from the user through a dialog box and sets the string equal to it. The second statement takes the string and parses it into a double. The third statement just tells the user what was inputted. To do mathematical operations, you would use the double, not the string. That was the whole point of the second statement. Hope this helps.
     
  12. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Can anybody write a Java program which determines an employees pay using dialog boxes? The person receives a $500 per month base salary plus commission on all sales made. Output should include the name of the person, total sales, commission, and salary.

    I made a horrible grade on a quiz where we were supposed to do this. I tried to re-write it three times and still haven't been able to get one to compile and execute. I know one mistake was using int for my number because $ amounts usually contain decimal points.
     
  13. movement

    movement Member

    Joined:
    Aug 9, 2001
    Messages:
    212
    Likes Received:
    0
    it's written in VB, but the logic is there. If your program has syntax errors, then double check the example code in your book for proper format.

    http://movement3.dynu.com/salary.html
     
  14. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    I am supposed to write a program in which all the verses of "99 Bottles of Beer on the Wall" are to be displayed in the Command/MS-DOS Prompt Window and not a dialog box. I have written a program and I don't get any errors when I compile but none of the verses gets printed out. The program which I typed (in Notepad) is below, could somebody help me out and tell me why my verses are not printing out???

    import javax.swing.JOptionPane;

    public class Program5 {

    public static void main( String args [] )
    {

    String input;
    int number;
    int count;

    input = JOptionPane.showInputDialog( "Enter the number 99" );

    number = Integer.parseInt( input );

    while ( number == 99 );
    {
    input = JOptionPane.showInputDialog( "Enter the number 99" );

    number = Integer.parseInt( input );
    }

    count = 99;

    {
    System.out.println( count + "bottles of beer on the wall" );

    count --;
    }

    System.exit( 0 );
    }
    }
     
  15. movement

    movement Member

    Joined:
    Aug 9, 2001
    Messages:
    212
    Likes Received:
    0
    I dont have a java compiler on this computer, but I wrote the javascript here:
    http://movement3.dynu.com/bottles.html

    The main loop should look like this:
    while (userinput != -1)
    {
    d.write(userinput+ " bottles of beer on the wall<br>");
    userinput--;
    }

    When you're using the while loop, its like saying the opposite, the loop will keep on going as long as userinput is not -1. Once userinput becomes -1, then userinput == -1, thus making the statement (userinput != -1) false. all other values makes the condition true.

    If you set the condition, number == 99 then the loop is going to exit the second try since the statement becomes false. Also you want all the system.out.println to be within the loop.
     
    #15 movement, Mar 20, 2002
    Last edited: Mar 20, 2002
  16. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Hey is there a class that will determine the results of a quadratic equation like the one for square roots?
     
  17. RocketsPimp

    RocketsPimp Member

    Joined:
    Feb 15, 1999
    Messages:
    13,812
    Likes Received:
    194
    Yuck!! Java looks too much like C++(which I am taking right now and HATE it with a passion). I'm actually at school right now writing a program that deals with arrays.

    I really don't think programming is for me.
     
  18. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    I believe that Java was derived from C++.

    About my previous question on quadratic equation, is there a website which list all the Math classes? I still need the quadratic one if there is one.
     
  19. paikj83

    paikj83 Member

    Joined:
    Aug 17, 2001
    Messages:
    144
    Likes Received:
    1
  20. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Is there a website that can help me out on modular programming? I am having to re-write a program we did earlier this year in modular mode but I just don't understand it. The assignment is below. Like I said we have done this before and I have the former program on my computer but what I don't understand how to do are the parts in bold lettering.

    Write a modular application that shows a user a menu with 5 items: 1. Add two numbers, 2. Subtract two numbers, 3. Multiply two numbers, 4. Divide two numbers, and 5. Exit. If the user chooses 1-4, s/he is then prompted for the two numbers, the appropriate operation is performed, the result is displayed and the menu is shown again. If the user chooses 5, the application exits. If the user chooses anything else, an error is reported and s/he is prompted again.

    You should include a method, OpeningInfo, to inform the user of your name, the purpose of the program, and the assignment number. As well as a method, NormalExit, to inform the user of a normal exit. The display of the menu, acquisition of an appropriate choice, and display of error message on inappropriate choice should be in a method. The input of a number (for the mathematics) should be handled with a method.
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now