## 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();
}
}

## Self-reflection, February 16th

The few weeks have been successful for me. I gave it my all to succeed. I have been making a program that you can play rock paper scissors with a computer. There is a fair chance of wins, loses and ties. I have made a winning rate and it shows around 33% as you play more. I have already posted a GOYO post about it but I have learned that I can add pictures on java. Below is the rock paper scissors program I made and the link to the code is on the GOYO project. http://codex.gnimmargorp.com/19yyun/2017/02/08/goyo-large/ I have currently been doing codecademy and also tried to learn pygame. It is really interesting and I enjoy learning it. My goal for next time is finish making my calculator. I have started making it for the past two days and my goal is to finish it. Below is the picture what I have been doing it for two days. I have not put commands on it yet, but I have made the buttons and designed it so it looks cleaner. ## GOYO Large

I have been studying random numbers on python. So I wanted to make a small game related to random numbers. I am not too good at making games on python, so I choose to make the game on java. I was not really good at using random numbers, so I chose to study a little bit about it for 2 classes. At first I made a heads or tails program for 1 more class, but it was not as fun to do. So I made a rock paper scissors program for the 2 classes. After I made this, I felt like I could improve this program, so I put a win, lose, tie count so it shows how good you are. The opponent is a computer and it generates random numbers, meaning you can not guess what they are going to put. I started planning it by writing what I had to do for all things I needed, such as Buttons, Panels, Integers, and so on. By making this program, I learned that you could put pictures in a java program. I did know that it was possible but I have never tried it before. I feel like I have accomplished something big by doing this. This project might change my work, by using more pictures in my program, and make it look more visual. This project can be used when someone is bored and nothing to do. It will help them escape boredom. This project was a very successful piece of code. It would be nice if I was able to receive more than 30 Golds.      These are the codes and a picture when the code was running.