If you know computers check this out..

Collapse

Recommended Videos

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dtownballa
    MVP
    • Feb 2003
    • 1450

    #1

    If you know computers check this out..

    I need help in my JAVA C++ class..

    2nd Program Assignment

    Write a JAVA program that accepts 2 numbers from the user. The user is then given a choice of what to do with the two numbers. The user can Add, Subtract, Multiply or Divide the numbers. However, there is a code for each of these operations. 1 means Add, 2 means Subtract, 3 means Multiply and 4 means Divide. The program will display the 2 numbers, whether the program will "Add, Subtract, Multiply or Divide" and the result. Additionally, the programmer must use GUI components to ask and display the values and use a loop to ask the questions again until the user supplies a number to "stop" the program. The selection part will be accomplished by using a switch() statement. (If a switch() statement was used in the first program, use IF/ELSE for this program.) Also, the user can only enter numbers between 1 and 35, no negative numbers.


    Please help me!
    PSN: The_TechNinja
    Check me out on YouTube as well: http://tinyurl.com/lqd6s9j
  • Hooe
    Hall Of Fame
    • Aug 2002
    • 21554

    #2
    Re: If you know computers check this out..

    Which language are you writing in, JAVA or C++?

    I doubt anyone on here will supply a program for you, but if you divide it into parts and do things piece-by-piece, it makes writing programs much easier. What exactly is tripping you up?

    If you have code that you've already written, you might post that and it can be critiqued by others from there.

    Comment

    • mgoblue
      Go Wings!
      • Jul 2002
      • 25477

      #3
      Re: If you know computers check this out..

      Originally posted by Krioniq
      Which language are you writing in, JAVA or C++?

      I doubt anyone on here will supply a program for you, but if you divide it into parts and do things piece-by-piece, it makes writing programs much easier. What exactly is tripping you up?

      If you have code that you've already written, you might post that and it can be critiqued by others from there.
      Exactly...we're not doing your homework for you...
      Nintendo Switch Friend Code: SW-7009-7102-8818

      Comment

      • Dtownballa
        MVP
        • Feb 2003
        • 1450

        #4
        Re: If you know computers check this out..

        I'm not asking you to do my homework.

        Lol.

        i'm stuck on the acual part to output to GUI.

        I dont know the commands for that at all, im use to "system.out.println" but what is the command for that to show in a GUI. Also, declaring varibles in the beginning I'm not what are going to be the main variables.

        The first assignment was easy, but this one just got crazy!
        PSN: The_TechNinja
        Check me out on YouTube as well: http://tinyurl.com/lqd6s9j

        Comment

        • p_rushing
          Hall Of Fame
          • Feb 2004
          • 14514

          #5
          Re: If you know computers check this out..

          very easy to do, don't remember syntax though

          system.out.printlh( a + '+' + b), should print the line to the command prompt

          you should need 4 variable max

          use a while/loop/ whatever
          print options to screen
          check for errors in input
          then switch to enter what to do
          then in each case print number and operation, then answer
          loop to beginning until exit case is met
          Last edited by p_rushing; 10-10-2007, 01:23 AM.

          Comment

          • The GIGGAS
            Timbers - Jags - Hokies
            • Mar 2003
            • 28474

            #6
            Re: If you know computers check this out..

            Have you learned about GUIs yet, such as Panels, Frames, JPanels, JFrames, JLabels, anything like that?
            Rose City 'Til I Die
            Duuuuuuuvvvvaaaaaaaal
            Hokie Hokie Hokie Hy

            Member: OS Uni Snob Assoc.
            OS OT Post Champ '11

            Twitter: @TheGIGGAS_OS
            Xbox Live: TheGIGGAS
            3DS: 1349-7755-3870

            Comment

            • Tha_Kid
              All Star
              • Oct 2002
              • 6550

              #7
              Re: If you know computers check this out..

              Are you sure you don't need a scanner object for user input?

              Comment

              • The GIGGAS
                Timbers - Jags - Hokies
                • Mar 2003
                • 28474

                #8
                Re: If you know computers check this out..

                Originally posted by Tha_Kid
                Are you sure you don't need a scanner object for user input?
                Depends on how the GUI is to take in the input. You'd be able to just get text from TextBoxes and parse it into integers.
                Rose City 'Til I Die
                Duuuuuuuvvvvaaaaaaaal
                Hokie Hokie Hokie Hy

                Member: OS Uni Snob Assoc.
                OS OT Post Champ '11

                Twitter: @TheGIGGAS_OS
                Xbox Live: TheGIGGAS
                3DS: 1349-7755-3870

                Comment

                • CM1847
                  Bacon
                  • Jul 2002
                  • 5372

                  #9
                  Re: If you know computers check this out..

                  Use Java swing GUI classes, panels, frames, buttons, textfields, etc. Make a panel and throw a couple of textfields on there for the two user input numbers and then put four buttons below that, one for add, one for subtract.... The hardest part will be getting things setup initially, like getting things to actually display. Grabbing inputs from a textfield is very simple as is listening for one of the operator buttons to be clicked.

                  Find a quick online tutorial on Java GUI programming and you could probably be done within an hour, the only task here is to learn how to program a GUI.

                  A simpel tutorial like this should work:
                  Introduction Java, while only a few years old, is already being deployed in a wide variety of devices. Java exists for mainframes, midrange servers, PCs, ... Read more


                  Go through their intros and then use their larger example source code as a guide.

                  Good luck!

                  Comment

                  • dagger55
                    No end in sight...
                    • Jul 2004
                    • 7907

                    #10
                    Re: If you know computers check this out..

                    sounds like you need to visit the Java API.


                    Also, ever been to krugle.com?

                    Comment

                    • dagger55
                      No end in sight...
                      • Jul 2004
                      • 7907

                      #11
                      Re: If you know computers check this out..

                      Not sure what development enviornment you are using, but there are some that have plugins that create the GUI for you...

                      Comment

                      • Dtownballa
                        MVP
                        • Feb 2003
                        • 1450

                        #12
                        Re: If you know computers check this out..

                        Heres how far i've gotten so far. I've never used GUI componets in my whole life. And this is my first programming class. I'm going to college for IT work and mainly hardware and networking, but this bull.
                        Attached Files
                        PSN: The_TechNinja
                        Check me out on YouTube as well: http://tinyurl.com/lqd6s9j

                        Comment

                        • Dtownballa
                          MVP
                          • Feb 2003
                          • 1450

                          #13
                          Re: If you know computers check this out..

                          Originally posted by CM1847
                          Use Java swing GUI classes, panels, frames, buttons, textfields, etc. Make a panel and throw a couple of textfields on there for the two user input numbers and then put four buttons below that, one for add, one for subtract.... The hardest part will be getting things setup initially, like getting things to actually display. Grabbing inputs from a textfield is very simple as is listening for one of the operator buttons to be clicked.

                          Find a quick online tutorial on Java GUI programming and you could probably be done within an hour, the only task here is to learn how to program a GUI.

                          A simpel tutorial like this should work:
                          Introduction Java, while only a few years old, is already being deployed in a wide variety of devices. Java exists for mainframes, midrange servers, PCs, ... Read more


                          Go through their intros and then use their larger example source code as a guide.

                          Good luck!
                          That site helped a bunch, i had that one open as I did this worked on this code.
                          PSN: The_TechNinja
                          Check me out on YouTube as well: http://tinyurl.com/lqd6s9j

                          Comment

                          • aukevin
                            War Eagle, Go Braves!
                            • Dec 2002
                            • 14700

                            #14
                            Re: If you know computers check this out..

                            Originally posted by Dtownballa
                            Heres how far i've gotten so far. I've never used GUI componets in my whole life. And this is my first programming class. I'm going to college for IT work and mainly hardware and networking, but this bull.
                            You are on the right track. I took a look at the code, you've got a few syntax problems with your switch statements and you didn't declare your results variable (and you had a typo in one place too on a variable), but after I fixed that I was able to run your program. It asked me for the two numbers, so that was good.

                            Looks like all you have left is to put a label on the third JOptionPane to explain which number relates to which math operator (add, subtract, etc) and then another JOptionPane to that displays the results variable on it.

                            One thing though, I don't think you are following the assignment's direction on the loop. You have a loop around each JOptionPane which really isn't correct because you have a break that just takes you out of each loop. The program only needs one loop, a while loop would do. After you declare your variables and before your first JOptionPane, you should have a while loop that checks some variable that you will use to break out of the loop. Inside the loop you will pop up the first JOptionPane and ask for a number, then pop up the next JOptionPane and get the second number, then pop up a third JOptionPane to get the operator to use, then do your switch statements to compute your results, then pop yet another JOptionPane (we are still inside that one while loop) to display your result. Finally, I think you need one more JOptionPane that asks the user something that you can use to break out of the loop. Like ask a question "Do you want to quit, enter -1 if so," and get that number from the JOptionPane. That way, the one loop you have just checks that value each time. For example, you might have a int called stop that is initialized to 0, then your loop would be something like:

                            while(stop >= 0){

                            JOptionPane for the first number

                            JOptionPane for the second number

                            JOptionPane for the math expression to use

                            Your switch statements to compute your results

                            JOptionPane for the results

                            JOptionPane to ask the user to continue

                            }


                            After that JOptionPane, you should end your while loop. That way, if you do enter a -1 in that final JOptionPane, when the program goes back to the top and checks the loop condition, it will exit out if you entered a negative number and then you can do your System.exit(0). Make sense?
                            Last edited by aukevin; 10-12-2007, 09:26 AM.

                            Atlanta Braves
                            - Auburn Tigers - Nashville Predators

                            Comment

                            • Dtownballa
                              MVP
                              • Feb 2003
                              • 1450

                              #15
                              Re: If you know computers check this out..

                              What your saying is making sense, but acually implementing this for me however, might be a bit difficult.

                              Can you send me the file with the changes you've made for the syntax errors.

                              Tonight when i start working on the code somemore, I'm going to try to do what you said, as far as the loop.

                              Thanks for all the help guys BTW!
                              PSN: The_TechNinja
                              Check me out on YouTube as well: http://tinyurl.com/lqd6s9j

                              Comment

                              Working...