Skip to content

Commit

Permalink
Code Clean-up
Browse files Browse the repository at this point in the history
A little bit of clean up to make the code look better
  • Loading branch information
MintyTheCoder committed Sep 10, 2023
1 parent 3967e85 commit 5a17a9f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
Binary file modified Java Calculators/bin/JavaCalculators/ConsoleCalculator.class
Binary file not shown.
Binary file modified Java Calculators/bin/JavaCalculators/SwingCalculator.class
Binary file not shown.
4 changes: 0 additions & 4 deletions Java Calculators/src/JavaCalculators/ConsoleCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void getNumbers()
//creates a method to add the numbers from getNumbers and print the sum in the console
public float doSum()
{
//getNumbers();
float sum;
sum = number1 + number2;
System.out.println("The sum of your two numbers is:");
Expand All @@ -59,7 +58,6 @@ public float doSum()
//creates a method to multiply the numbers from getNumbers and print the product in the console
public float doProduct()
{
//getNumbers();
float product;
product = number1 * number2;
System.out.println("The product of your two numbers is:");
Expand All @@ -71,7 +69,6 @@ public float doProduct()
//creates a method to subtract the numbers from getNumbers and print the difference in the console
public float doDifference()
{
//getNumbers();
float difference;
difference = number1 - number2;
System.out.println("The difference between your two numbers is:");
Expand All @@ -83,7 +80,6 @@ public float doDifference()
//create a method to divide the numbers from getNumbers and print the quotient in the console
public float doQuotient()
{
//getNumbers();
float quotient;
quotient = number1 / number2;
System.out.println("The quotient of your two numbers is:");
Expand Down
20 changes: 10 additions & 10 deletions Java Calculators/src/JavaCalculators/SwingCalculator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package JavaCalculators;

import javax.swing.*;

import java.awt.FlowLayout;
//import java.util.Scanner;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

Expand All @@ -12,7 +11,7 @@
public class SwingCalculator
{
//create a JFrame Object
static JFrame calcBox;
public static JFrame calcBox;

//create 2 text boxes for text input
static final JTextField intInput1 = new JTextField("Enter Your First Integer");
Expand All @@ -28,10 +27,11 @@ public static void main(String[] args)

public static void setup()
{
// creating a frame object
// creating a frame object
calcBox = new JFrame();
calcBox.setSize(500,500);
// creating the buttons

// creating the buttons
JButton addition = new JButton("+");
JButton subtraction = new JButton("-");
JButton multiplication = new JButton("×");
Expand All @@ -51,6 +51,7 @@ public static void setup()
subtraction.addActionListener(subtractButton);
multiplication.addActionListener(multiplyButton);
division.addActionListener(divideButton);


//connects Action Listeners to corresponding text fields
intInput1.addActionListener(text1);
Expand All @@ -63,17 +64,16 @@ public static void setup()
calcBox.add(subtraction);
calcBox.add(multiplication);
calcBox.add(division);
calcBox.add(intInput2);


calcBox.add(intInput2);

//sets the size of the window/GUI
calcBox.setSize(300, 300);

//allows the window to be visible
calcBox.setVisible(true);
}



//private inner class to listen for button presses
/** Action that will happen when enter is pressed on the TextField*/
private static class TextListener1 implements ActionListener
Expand Down Expand Up @@ -110,7 +110,7 @@ public void actionPerformed(ActionEvent buttonPress)
{
//what happens when button is pressed
System.out.println("Addition Selected");
//calculator.doSum();

JLabel label = new JLabel(" = " + calculator.doSum());
calcBox.add(label);

Expand Down

0 comments on commit 5a17a9f

Please sign in to comment.