Pls. help me to revised my code , i base my java calculator code on youtube tutorial but it was denied because almost half of our class base their code on the youtube tutorial and i need to pass the code by monday.or if possible , can you give me a simple code that is not complicated to memorize because we still have to arrange the errors that was given by our instructor before he give the score and the worst thing he havnt discuss anything with regards to this topic . PLS HELP ME!

Pls. help me to revised my code , i base my java calculator code on youtube tutorial but it was denied because almost half of our class base their code on the youtube tutorial and i need to pass the code by monday.or if possible , can you give me a simple code that is not complicated to memorize because we still have to arrange the errors that was given by our instructor before he give the score and the worst thing he havnt discuss anything with regards to this topic . PLS HELP ME!

THIS IS THE CODE I BASE IN THE YOUTUBE TUTORIAL

public class Calculator extends javax.swing.JFrame {

    //Variables

    double calculation;
    double firstkey;
    double secondkey;
    int    totalkey;

    // To check for button clicks

    int plusButton;
    int minusButton;
    int multiplyButton;
    int divideButton;
    int decimalButton;




    public Calculator() {
        initComponents();
    }





    private void initComponents() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {
                oneActionPerformed(evt);
            }

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText("");
       decimalButton = 0;


    private void oneActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+one.getText());
  }

    private void twoActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+two.getText());
    }

    private void threeActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+three.getText());
    }

    private void fourActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+four.getText());
    }

    private void fiveActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+five.getText());
    }

    private void sixActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+six.getText());
    }

    private void sevenActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+seven.getText());
    }

    private void eightActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+eight.getText());
    }

    private void nineActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+nine.getText());
    }

    private void zeroActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+zero.getText());
    }

    private void decimalActionPerformed(java.awt.event.ActionEvent evt) {
        if(decimalButton==0){
        display.setText(display.getText()+decimal.getText());
        decimalButton = 1;

    }



    private void positivenegativeActionPerformed(java.awt.event.ActionEvent evt) {
       calculation=(Double.parseDouble(String.valueOf(display.getText())));
       calculation = calculation*(-1);
       display.setText(String.valueOf(calculation));
    }

    private void plusActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      plusButton = 1;
      decimalButton = 0;


    }

    private void minusActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      minusButton = 1;
      decimalButton = 0;
    }

    private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      multiplyButton = 1;
      decimalButton = 0;
    }

    private void divideActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      divideButton = 1;
      decimalButton = 0;
    }

    private void equalsActionPerformed(java.awt.event.ActionEvent evt) {
       secondkey = (Double.parseDouble(String.valueOf(display.getText())));

       if (plusButton>0){
        totalkey = (int) (firstkey + secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        plusButton = 0;
       }

       if (minusButton>0){
        totalkey = (int) (firstkey - secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        minusButton = 0;
        }

       if (multiplyButton>0){
        totalkey = (int) (firstkey * secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        multiplyButton = 0;

    }
        if (divideButton>0){
        totalkey = (int) (firstkey / secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        divideButton = 0;
        }
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Calculator().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton clear;
    private javax.swing.JButton decimal;
    private javax.swing.JTextField display;
    private javax.swing.JButton divide;
    private javax.swing.JButton eight;
    private javax.swing.JButton equals;
    private javax.swing.JButton five;
    private javax.swing.JButton four;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton minus;
    private javax.swing.JButton multiply;
    private javax.swing.JButton nine;
    private javax.swing.JButton one;
    private javax.swing.JButton plus;
    private javax.swing.JButton positivenegative;
    private javax.swing.JButton seven;
    private javax.swing.JButton six;
    private javax.swing.JButton three;
    private javax.swing.JButton two;
    private javax.swing.JButton zero;
    // End of variables declaration//GEN-END:variables

}

Edited 3 Years Ago by Dani: Formatting fixed

i try to change the variables but it still not accepted cuz our codes are still the same.

Edited 3 Years Ago by Nick Evan: Fixed formatting

Please edit your post and wrap the code in code tags:
[code] ... code here [/code]

What are your java programming problems? Do you have any specific questions?

We're here to help students learn how to write java programs. we don't do students homework.
If you have questions, ask them and we'll try to help you understand the problem and fix your problems.

Edited 4 Years Ago by NormR1: n/a

IVE ALREADY EDITED IT .

that's the code id written in netbeans. There was no error . But i need help for revising or changing the code . Because we are all reminded that we should not have the same codes but half of our class used these code which was copied in youtube. I am asking for help by revising it or if possible can you just give me a simple java calculator code that is not too long and can be easily remembered. I am just new in java programming , i am only a first year student and i have no idea with this stuff cuz we havent discuss this yet.pls help me . I need it by monday evening.

Edited 3 Years Ago by Nick Evan: Fixed formatting

Please edit your post and wrap the code in code tags:
[code] ... code here [/code]

All of your code should look like this:

  public static void main(String args[]) {
       new Calculator().setVisible(true);
  }

Edited 3 Years Ago by diafol: fixed formatting

IVE ALREADY EDITED IT .

that's the code id written in netbeans. There was no error . But i need help for revising or changing the code . Because we are all reminded that we should not have the same codes but half of our class used these code which was copied in youtube. I am asking for help by revising it or if possible can you just give me a simple java calculator code that is not too long and can be easily remembered. I am just new in java programming , i am only a first year student and i have no idea with this stuff cuz we havent discuss this yet.pls help me . I need it by monday evening.

public class Calculator extends javax.swing.JFrame {

    //Variables

    double calculation;
    double firstkey;
    double secondkey;
    int    totalkey;

    // To check for button clicks

    int plusButton;
    int minusButton;
    int multiplyButton;
    int divideButton;
    int decimalButton;


    /** Creates new form Calculator */

    public Calculator() {
        initComponents();
    }

       private void initComponents() {

                    
        });

        
// Code for key buttons

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText("");
       decimalButton = 0;
    }

    private void oneActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+one.getText());
    }

    private void twoActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+two.getText());
    }

    private void threeActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+three.getText());
    }

    private void fourActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+four.getText());
    }

    private void fiveActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+five.getText());
    }

    private void sixActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+six.getText());
    }

    private void sevenActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+seven.getText());
    }

    private void eightActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+eight.getText());
    }

    private void nineActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+nine.getText());
    }

    private void zeroActionPerformed(java.awt.event.ActionEvent evt) {
       display.setText(display.getText()+zero.getText());
    }

    private void decimalActionPerformed(java.awt.event.ActionEvent evt) {
        if(decimalButton==0){
        display.setText(display.getText()+decimal.getText());
        decimalButton = 1;

    }
 }
        // Code for identifier calculation key buttons

    private void positivenegativeActionPerformed(java.awt.event.ActionEvent evt) {
       calculation=(Double.parseDouble(String.valueOf(display.getText())));
       calculation = calculation*(-1);
       display.setText(String.valueOf(calculation));
    }

    private void plusActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      plusButton = 1;
      decimalButton = 0;

    }

    private void minusActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      minusButton = 1;
      decimalButton = 0;
    }

    private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      multiplyButton = 1;
      decimalButton = 0;
    }

    private void divideActionPerformed(java.awt.event.ActionEvent evt) {
      firstkey=(Double.parseDouble(String.valueOf(display.getText())));
      display.setText("");
      divideButton = 1;
      decimalButton = 0;
    }

    private void equalsActionPerformed(java.awt.event.ActionEvent evt) {
       secondkey = (Double.parseDouble(String.valueOf(display.getText())));

       if (plusButton>0){
        totalkey = (int) (firstkey + secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        plusButton = 0;
       }

       if (minusButton>0){
        totalkey = (int) (firstkey - secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        minusButton = 0;
        }

       if (multiplyButton>0){
        totalkey = (int) (firstkey * secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        multiplyButton = 0;
    }


        if (divideButton>0){
        totalkey = (int) (firstkey / secondkey);
        display.setText(String.valueOf(totalkey));
        firstkey = 0;
        secondkey = 0;
        divideButton = 0;
        }
    }
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Calculator().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify

    private javax.swing.JButton clear;
    private javax.swing.JButton decimal;
    private javax.swing.JTextField display;
    private javax.swing.JButton divide;
    private javax.swing.JButton eight;
    private javax.swing.JButton equals;
    private javax.swing.JButton five;
    private javax.swing.JButton four;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton minus;
    private javax.swing.JButton multiply;
    private javax.swing.JButton nine;
    private javax.swing.JButton one;
    private javax.swing.JButton plus;
    private javax.swing.JButton positivenegative;
    private javax.swing.JButton seven;
    private javax.swing.JButton six;
    private javax.swing.JButton three;
    private javax.swing.JButton two;
    private javax.swing.JButton zero;
    // End of variables declaration//GEN-END:variables

}
public class calculator extends javax.swing.jframe {

    //variables

    double calculation;
    double firstkey;
    double secondkey;
    int    totalkey;

    // to check for button clicks

    int plusbutton;
    int minusbutton;
    int multiplybutton;
    int dividebutton;
    int decimalbutton;


    /** creates new form calculator */

    public calculator() {
        initcomponents();
    }

       private void initcomponents() {

                    
        });

        
// code for key buttons

    private void clearactionperformed(java.awt.event.actionevent evt) {
       display.settext("");
       decimalbutton = 0;
    }

    private void oneactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+one.gettext());
    }

    private void twoactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+two.gettext());
    }

    private void threeactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+three.gettext());
    }

    private void fouractionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+four.gettext());
    }

    private void fiveactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+five.gettext());
    }

    private void sixactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+six.gettext());
    }

    private void sevenactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+seven.gettext());
    }

    private void eightactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+eight.gettext());
    }

    private void nineactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+nine.gettext());
    }

    private void zeroactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+zero.gettext());
    }

    private void decimalactionperformed(java.awt.event.actionevent evt) {
        if(decimalbutton==0){
        display.settext(display.gettext()+decimal.gettext());
        decimalbutton = 1;

    }
 }
        // code for identifier calculation key buttons

    private void positivenegativeactionperformed(java.awt.event.actionevent evt) {
       calculation=(double.parsedouble(string.valueof(display.gettext())));
       calculation = calculation*(-1);
       display.settext(string.valueof(calculation));
    }

    private void plusactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      plusbutton = 1;
      decimalbutton = 0;

    }

    private void minusactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      minusbutton = 1;
      decimalbutton = 0;
    }

    private void multiplyactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      multiplybutton = 1;
      decimalbutton = 0;
    }

    private void divideactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      dividebutton = 1;
      decimalbutton = 0;
    }

    private void equalsactionperformed(java.awt.event.actionevent evt) {
       secondkey = (double.parsedouble(string.valueof(display.gettext())));

       if (plusbutton>0){
        totalkey = (int) (firstkey + secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        plusbutton = 0;
       }

       if (minusbutton>0){
        totalkey = (int) (firstkey - secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        minusbutton = 0;
        }

       if (multiplybutton>0){
        totalkey = (int) (firstkey * secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        multiplybutton = 0;
    }


        if (dividebutton>0){
        totalkey = (int) (firstkey / secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        dividebutton = 0;
        }
    }
   
    public static void main(string args[]) {
        java.awt.eventqueue.invokelater(new runnable() {
            public void run() {
                new calculator().setvisible(true);
            }
        });
    }

    // variables declaration - do not modify

    private javax.swing.jbutton clear;
    private javax.swing.jbutton decimal;
    private javax.swing.jtextfield display;
    private javax.swing.jbutton divide;
    private javax.swing.jbutton eight;
    private javax.swing.jbutton equals;
    private javax.swing.jbutton five;
    private javax.swing.jbutton four;
    private javax.swing.jpanel jpanel1;
    private javax.swing.jbutton minus;
    private javax.swing.jbutton multiply;
    private javax.swing.jbutton nine;
    private javax.swing.jbutton one;
    private javax.swing.jbutton plus;
    private javax.swing.jbutton positivenegative;
    private javax.swing.jbutton seven;
    private javax.swing.jbutton six;
    private javax.swing.jbutton three;
    private javax.swing.jbutton two;
    private javax.swing.jbutton zero;
    // end of variables declaration//gen-end:variables

}

i think there's some symbols missing but i tried to run the program and it works the problem is i have no idea what code will i applied on my program to revise or change these code that i base on youtube tutorial

public class calculator extends javax.swing.jframe {

    //variables

    double calculation;
    double firstkey;
    double secondkey;
    int    totalkey;

    // to check for button clicks

    int plusbutton;
    int minusbutton;
    int multiplybutton;
    int dividebutton;
    int decimalbutton;


    /** creates new form calculator */

    public calculator() {
        initcomponents();
                    
        });

        
// code for key buttons

    private void clearactionperformed(java.awt.event.actionevent evt) {
       display.settext("");
       decimalbutton = 0;
    }

    private void oneactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+one.gettext());
    }

    private void twoactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+two.gettext());
    }

    private void threeactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+three.gettext());
    }

    private void fouractionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+four.gettext());
    }

    private void fiveactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+five.gettext());
    }

    private void sixactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+six.gettext());
    }

    private void sevenactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+seven.gettext());
    }

    private void eightactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+eight.gettext());
    }

    private void nineactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+nine.gettext());
    }

    private void zeroactionperformed(java.awt.event.actionevent evt) {
       display.settext(display.gettext()+zero.gettext());
    }

    private void decimalactionperformed(java.awt.event.actionevent evt) {
        if(decimalbutton==0){
        display.settext(display.gettext()+decimal.gettext());
        decimalbutton = 1;

    }
 }
        // code for identifier calculation key buttons

    private void positivenegativeactionperformed(java.awt.event.actionevent evt) {
       calculation=(double.parsedouble(string.valueof(display.gettext())));
       calculation = calculation*(-1);
       display.settext(string.valueof(calculation));
    }

    private void plusactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      plusbutton = 1;
      decimalbutton = 0;

    }

    private void minusactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      minusbutton = 1;
      decimalbutton = 0;
    }

    private void multiplyactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      multiplybutton = 1;
      decimalbutton = 0;
    }

    private void divideactionperformed(java.awt.event.actionevent evt) {
      firstkey=(double.parsedouble(string.valueof(display.gettext())));
      display.settext("");
      dividebutton = 1;
      decimalbutton = 0;
    }

    private void equalsactionperformed(java.awt.event.actionevent evt) {
       secondkey = (double.parsedouble(string.valueof(display.gettext())));

       if (plusbutton>0){
        totalkey = (int) (firstkey + secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        plusbutton = 0;
       }

       if (minusbutton>0){
        totalkey = (int) (firstkey - secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        minusbutton = 0;
        }

       if (multiplybutton>0){
        totalkey = (int) (firstkey * secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        multiplybutton = 0;
    }


        if (dividebutton>0){
        totalkey = (int) (firstkey / secondkey);
        display.settext(string.valueof(totalkey));
        firstkey = 0;
        secondkey = 0;
        dividebutton = 0;
        }
    }
   
    public static void main(string args[]) {
        java.awt.eventqueue.invokelater(new runnable() {
            public void run() {
                new calculator().setvisible(true);
            }
        });
    }

    // variables declaration - do not modify

    private javax.swing.jbutton clear;
    private javax.swing.jbutton decimal;
    private javax.swing.jtextfield display;
    private javax.swing.jbutton divide;
    private javax.swing.jbutton eight;
    private javax.swing.jbutton equals;
    private javax.swing.jbutton five;
    private javax.swing.jbutton four;
    private javax.swing.jpanel jpanel1;
    private javax.swing.jbutton minus;
    private javax.swing.jbutton multiply;
    private javax.swing.jbutton nine;
    private javax.swing.jbutton one;
    private javax.swing.jbutton plus;
    private javax.swing.jbutton positivenegative;
    private javax.swing.jbutton seven;
    private javax.swing.jbutton six;
    private javax.swing.jbutton three;
    private javax.swing.jbutton two;
    private javax.swing.jbutton zero;
    // end of variables declaration//gen-end:variables

}

i think private init components is not included or there's some symbols missing but i tried to run the program and it works the problem is i have no idea what code will i applied on my program to revise or change these code that i base on youtube tutorial

Edited 4 Years Ago by jadeplaza: n/a

The code you posted does not compile for me. Unless it compiles, it can not be executed for testing.
For one thing the initComponent() method is empty.
For another there is not code to add any of the buttons to the GUI container where they can be seen.

i think private init components is not included or there's some symbols missing but i tried to run the program and it works the problem is i have no idea what code will i applied on my program to revise or change these code that i base on youtube tutorial

i didnt just apply the code directly in netbeans first i use java application then used the jframe i edited the jframe which is my design and then after i finished my calculator design the source code was directly given on my source in netbeans then afterwards i applied some codes needed for the keys to work. Try to watch the youtube tutorial of java calculator for you to understand what i mean.

Your instructor 'denied' your work because it was plagiarized. It's not hard to tell when a student submits something above their ability. Study the programming language and write your own code. Then, if you have problems, ask them here and we'd be happy to help.

and never just copy what you see in a 'youtube-tutorial'.
every dimwhit whit a webcam or screen capturing software is able to make so called 'professional tutorials', that doesn't mean they're actually any good.

all you need to know is how to create a basic Swing GUI, for which you can find all the information right here.

everything else you need to know is basic mathematics, for which I would refer any basic Math-course given in elementary school.

you've shown us the code you basically copied of some youtube video, now show us the code the way you think it should be written. that at least I'll be willing to go through.

This article has been dead for over six months. Start a new discussion instead.