0% found this document useful (0 votes)
0 views14 pages

Calculator

Uploaded by

ahmadashrruf3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views14 pages

Calculator

Uploaded by

ahmadashrruf3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Application

 Scientific Calculator

Application Introduction

Submit
 Introduction

Main class
Application Calculator

Project

CalculatorGUI
GUI

C
 Submit
package Gui;

 C public class C {
private char process;
private String firstValue;

public void setProcess(char process) {


this.process = process;
}

public char getProcess() {


return process;
}

public void setFirstValue(String firstValue) {


this.firstValue = firstValue;
}

public String getFirstValue() {


return firstValue;
}
}
 Submit
package Gui;
 CalculatorGUI
public class CalculatorGUI extends javax.swing.JFrame {

public CalculatorGUI() {
initComponents();
}

private final C in=new C();

@SuppressWarnings("unchecked")
Generated Code
 Submit

 CalculatorGUI
private void btn0ActionPerformed(java.awt.event.ActionEvent evt)
{
text.setText(text.getText()+"0");
}

00
 Submit

 CalculatorGUI

private void equalActionPerformed(java.awt.event.ActionEvent evt)


{
float value1 = Float.parseFloat(in.getFirstValue());
float value2 = Float.parseFloat(text.getText());

switch (in.getProcess()) {

case '/':
if(value2==0)
{
text.setText(String.valueOf("Cannot divide by zero"));
} else
{
text.setText(String.valueOf(value1/value2));
}
break;
}
 Submit

 CalculatorGUI
private void divActionPerformed(java.awt.event.ActionEvent evt)
{
in.setFirstValue(text.getText());
in.setProcess('/');
text.setText(null);
15 }

float value1 = Float.parseFloat(in.getFirstValue());


float value2 = Float.parseFloat(text.getText());

switch (in.getProcess()) {

case '/':
 Submit

 CalculatorGUI
private void sqrtActionPerformed(java.awt.event.ActionEvent evt)
{
float value = Float.parseFloat(text.getText());
text.setText(String.valueOf(Math.sqrt(value)));
}
5
25

private void factActionPerformed(java.awt.event.ActionEvent evt)


{
float value = Float.parseFloat(text.getText());
int fac=1;
for (int i =1; i <=value; i++)
{
120
5 fac *= i;
}
text.setText(String.valueOf( (fac)));
}
 Submit

 CalculatorGUI
private void dotActionPerformed(java.awt.event.ActionEvent evt)
{
if(text.getText().length()>0)
{
text.setText(text.getText()+".");
}
}

private void clearActionPerformed(java.awt.event.ActionEvent evt)


{
text.setText(null);
in.setFirstValue(null);
}
 Submit

 CalculatorGUI
private void BackSpaceActionPerformed(java.awt.event.ActionEvent evt)
{
if(text.getText().length()>0)
{
StringBuilder str =new StringBuilder(text.getText());
555 str.deleteCharAt(text.getText().length()-1);
text.setText(str.toString());
}
}
private void BlOrMiActionPerformed(java.awt.event.ActionEvent evt)
{
if(text.getText().length()>0)
{
float value = Float.parseFloat(text.getText());
text.setText(String.valueOf( value*(-1)));
}
}
 Submit

 CalculatorGUI

private void OFFActionPerformed(java.awt.event.ActionEvent evt)


{
btn0.setEnabled(false);
}

private void ONActionPerformed(java.awt.event.ActionEvent evt)


{
btn0.setEnabled(true);
}
 Submit

 Calculator
package Application;

import Gui.CalculatorGUI;

public class Calculator


{

public static void main(String[] args)


{
CalculatorGUI gui = new CalculatorGUI();
gui.setVisible(true);
}
}
 Application
‫اسماء المشاركين‬

‫(‪1-)3‬‬ ‫ابراهيم محمد احمد رمضان‬


‫(‪2 -)10‬‬ ‫احمد السيد محمد عبدالمنعم‬
‫(‪3 -)11‬‬ ‫احمد ايمن الشحات متولى‬
‫المعتصم ابراهيم محمد يعقوب (‪4 -)36‬‬
‫عبدالرحمن طارق ابراهيم برغش (‪-5)48‬‬

You might also like