Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding inverse sine function #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
# Mac OS System
.DS_Store*
._*
/bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Simple-Java-Calculator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
5 changes: 4 additions & 1 deletion src/simplejavacalculator/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum BiOperatorModes {
}

public enum MonoOperatorModes {
square, squareRoot, oneDividedBy, cos, sin, tan ,log , rate, abs
square, squareRoot, oneDividedBy, cos, sin, tan, inverseSin, log, rate, abs
}

private Double num1, num2;
Expand Down Expand Up @@ -118,6 +118,9 @@ public Double calculateMono(MonoOperatorModes newMode, Double num) {
if (newMode == MonoOperatorModes.abs){
return Math.abs(num);
}
if (newMode == MonoOperatorModes.inverseSin){
return Math.toDegrees(Math.asin(num));
}

// never reach
throw new Error();
Expand Down
13 changes: 10 additions & 3 deletions src/simplejavacalculator/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class UI implements ActionListener {
private final JTextArea text;
private final JButton but[], butAdd, butMinus, butMultiply, butDivide,
butEqual, butCancel, butSquareRoot, butSquare, butOneDividedBy,
butCos, butSin, butTan, butxpowerofy, butlog, butrate, butabs, butBinary;
butCos, butSin, butTan, butxpowerofy, butlog, butrate, butabs, butBinary, butInverseSin;
private final Calculator calc;

private final String[] buttonValue = {"0", "1", "2", "3", "4", "5", "6",
Expand Down Expand Up @@ -99,13 +99,14 @@ public UI() throws IOException {
butOneDividedBy = new JButton("1/x");
butCos = new JButton("Cos");
butSin = new JButton("Sin");
butTan = new JButton("Tan");
butTan = new JButton("Tan");
butInverseSin = new JButton("Sin^-1");
butxpowerofy = new JButton("x^y");
butlog = new JButton("log10(x)");
butrate = new JButton("x%");
butabs = new JButton("abs(x)");
butCancel = new JButton("C");
butBinary = new JButton("Bin");
butBinary = new JButton("Bin");

calc = new Calculator();

Expand Down Expand Up @@ -135,6 +136,7 @@ public void init() {
butCos.setFont(font);
butSin.setFont(font);
butTan.setFont(font);
butInverseSin.setFont(font);
butxpowerofy.setFont(font);
butlog.setFont(font);
butrate.setFont(font);
Expand Down Expand Up @@ -184,6 +186,7 @@ public void init() {
panelSub7.add(butCos);
panelSub7.add(butSin);
panelSub7.add(butTan);
panelSub7.add(butInverseSin);
panel.add(panelSub7);

panelSub8.add(butlog);
Expand All @@ -205,6 +208,7 @@ public void init() {
butCos.addActionListener(this);
butSin.addActionListener(this);
butTan.addActionListener(this);
butInverseSin.addActionListener(this);
butxpowerofy.addActionListener(this);
butlog.addActionListener(this);
butrate.addActionListener(this);
Expand Down Expand Up @@ -280,6 +284,9 @@ public void actionPerformed(ActionEvent e) {
if (source == butTan)
writer(calc.calculateMono(Calculator.MonoOperatorModes.tan, reader()));

if (source == butInverseSin)
writer(calc.calculateMono(Calculator.MonoOperatorModes.inverseSin, reader()));

if (source == butlog)
writer(calc.calculateMono(Calculator.MonoOperatorModes.log, reader()));

Expand Down
12 changes: 9 additions & 3 deletions src/simplejavacalculatorTest/CalculatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,25 @@ void CalculateMonoOneDividedByTest() {
@Test
void CalculateMonoSinTest() {
Calculator calculator = new Calculator();
Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.sin, java.lang.Math.PI / 6), 0.0000000001);
Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.sin, Math.toDegrees(java.lang.Math.PI) / 6), 0.0000000001);
}

@Test
void CalculateMonoCosTest() {
Calculator calculator = new Calculator();
Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.cos, java.lang.Math.PI / 3), 0.0000000001);
Assertions.assertEquals(0.5, calculator.calculateMono(Calculator.MonoOperatorModes.cos, Math.toDegrees(java.lang.Math.PI) / 3), 0.0000000001);
}

@Test
void CalculateMonoTanTest() {
Calculator calculator = new Calculator();
Assertions.assertEquals(1.0, calculator.calculateMono(Calculator.MonoOperatorModes.tan, java.lang.Math.PI / 4), 0.0000000001);
Assertions.assertEquals(1.0, calculator.calculateMono(Calculator.MonoOperatorModes.tan, Math.toDegrees(java.lang.Math.PI) / 4), 0.0000000001);
}

@Test
void CalculateMonoInverseSinTest() {
Calculator calculator = new Calculator();
Assertions.assertEquals(90.0, calculator.calculateMono(Calculator.MonoOperatorModes.inverseSin, 1.0), 0.0000000001);
}

@Test
Expand Down