# GOYO Large

Calculating things such as addition, subtraction, division, and multiplication is easy to do but you must print the result like System.out.println(3+5);. However this calculator I made using java is made for people who do not know any clue how to code. Just by a normal calculator, you have all the numbers and the signs, and all you have to do is press the buttons. I feel really accomplished by doing this project. The previous projects I made was games, but this one is a program that can actually help people. There are many more better calculators on the internet that are better than me, however I think the calculator I made was a step to make mine better like the ones you can see on a mac or windows. My calculator is only for two numbers, so if you type 1+1+2, you will get 3. I still have not been able to figure out how to do 3 or more numbers, and that will be posted on my next GOYO, with an improved and better one. I did not learn anything new doing this project, but if I progress and figure out how to multiply, divide, add or subtract 3 or more numbers, it will be something new I will learn. The program I made is very good for people who need a calculator. When I use it, I would feel accomplished, since I made a useful program! Below is the calculator and its code. Since this is a really useful code, I feel like extra credit will help me out.

Image     In this input I am multiplying 7 with 9 giving me 63, which is 7 * 9.

Code

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main extends JFrame{
private static final long serialVersionUID = 1L;
static double x=0,y=0,result=0;
static int operator=0;
JLabel l;
JButton b[]=new JButton;
Container c;
Main(){
setTitle(“Calculator”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(600,200);
c=getContentPane();
c.setLayout(null);
c.setBackground(Color.WHITE);
l=new JLabel();
b=new JButton(“1”);
b=new JButton(“2”);
b=new JButton(“3”);
b=new JButton(“4”);
b=new JButton(“5”);
b=new JButton(“6”);
b=new JButton(“7”);
b=new JButton(“8”);
b=new JButton(“9”);
b=new JButton(“0”);
b=new JButton(“x”);
b=new JButton(“÷”);
b=new JButton(“+”);
b=new JButton(“-“);
b=new JButton(“.”);
b=new JButton(“=”);
b=new JButton(“Delete”);
b=new JButton(“Clear”);

l.setBounds(0,0,360,150);
l.setFont(new Font(“Arial”,Font.BOLD,40));

b.setBounds(0,410,90,60);
b.setBounds(90,410,90,60);
b.setBounds(180,410,90,60);
b.setBounds(270,410,90,60);

b.setBounds(0,350,90,60);
b.setBounds(90,350,90,60);
b.setBounds(180,350,90,60);
b.setBounds(270,350,90,60);

b.setBounds(0,290,90,60);
b.setBounds(90,290,90,60);
b.setBounds(180,290,90,60);
b.setBounds(270,290,90,60);

b.setBounds(0,230,90,60);
b.setBounds(90,230,90,60);
b.setBounds(180,230,90,60);
b.setBounds(270,230,90,60);

b.setBounds(0,170,180,60);
b.setBounds(180,170,180,60);

for(int i=0;i<18;i++){
b[i].setFocusable(false);
b[i].setBackground(Color.WHITE);
b[i].setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
b[i].setFont(new Font(“Arial”,Font.BOLD,20));
}
setVisible(true);
setSize(360,500);
setResizable(false);
}
class MyButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Object source=e.getSource();
if(source==b){
l.setText(l.getText().concat(“1”));
}
if(source==b){
l.setText(l.getText().concat(“2”));
}
if(source==b){
l.setText(l.getText().concat(“3”));
}
if(source==b){
l.setText(l.getText().concat(“4”));
}
if(source==b){
l.setText(l.getText().concat(“5”));
}
if(source==b){
l.setText(l.getText().concat(“6”));
}
if(source==b){
l.setText(l.getText().concat(“7”));
}
if(source==b){
l.setText(l.getText().concat(“8”));
}
if(source==b){
l.setText(l.getText().concat(“9”));
}
if(source==b){
l.setText(l.getText().concat(“0”));
}
if(source==b){
l.setText(l.getText().concat(“.”));
}
if(source==b){// /
x=Double.parseDouble(l.getText());
operator=4;
l.setText(“”);
}
if(source==b){// x
x=Double.parseDouble(l.getText());
operator=3;
l.setText(“”);
}
if(source==b){// –
x=Double.parseDouble(l.getText());
operator=2;
l.setText(“”);
}
if(source==b){// +
x=Double.parseDouble(l.getText());
operator=1;
l.setText(“”);
}
if(source==b){
y=Double.parseDouble(l.getText());

switch(operator)
{
case 1: result=x+y;
break;

case 2: result=x-y;
break;

case 3: result=x*y;
break;

case 4: result=x/y;
break;

default: result=0;
}

l.setText(“”+result);
}
if(source==b){
l.setText(“”);
}
if(source==b){
String s=l.getText();
l.setText(“”);
for(int i=0;i<s.length()-1;i++){
l.setText(l.getText()+s.charAt(i));
}
}
}
}
public static void main(String[] args) {
new Main();
}
}

## 2 thoughts on “GOYO Large”

1. loremasterrellim says:

Not only is that a pretty nifty start on a calculator utility, it’s a pretty meaty Codex post, too. Normally, I prefer that you DO learn something with each GOYO, but since this is one in which you’ve built a foundation and are planning to go further, I’ll award some extra XP and Gold for it. Keep moving forward!

(For the adding multiple numbers problem, you might be interested in looking up the computing terms “stack” (LIFO) and “queue” (FIFO); one of these might be useful for that issue.)