Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Astro1123 committed Nov 21, 2021
1 parent 2c96372 commit 3491872
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
63 changes: 33 additions & 30 deletions calc/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.awt.event.WindowEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.DecimalFormat;

class Calculator extends JFrame implements KeyListener, ActionListener, ItemListener {
String title;
Expand Down Expand Up @@ -750,44 +751,46 @@ public void paint(Graphics g) {
g.drawLine((int)xc(xmin + dx * 3),(int)yc(0)-2,(int)xc(xmin + dx * 3),(int)yc(0)+2);
g.drawLine((int)xc(xmin + dx * 4),(int)yc(0)-2,(int)xc(xmin + dx * 4),(int)yc(0)+2);

DecimalFormat format = new DecimalFormat("0.######");

if ((int)yc(0)+25 > dimension.height) {
g.drawString("O", (int)xc(0)+5, (int)yc(0)-5);

if (xmin != 0)
g.drawString(String.valueOf(xmin), (int)xc(xmin), (int)yc(0)-5);
if (xmin + dx != 0)
g.drawString(String.valueOf(xmin + dx), (int)xc(xmin + dx), (int)yc(0)-5);
if (xmin + 2*dx != 0)
g.drawString(String.valueOf(xmin + 2*dx), (int)xc(xmin + 2*dx), (int)yc(0)-5);
if (xmin + 3*dx != 0)
g.drawString(String.valueOf(xmin + 3*dx), (int)xc(xmin + 3*dx), (int)yc(0)-5);
if (xmin + 4*dx != 0)
g.drawString(String.valueOf(xmin + 4*dx), (int)xc(xmin + 4*dx)-20, (int)yc(0)-5);
if (!(format.format(xmin).equals("0")))
g.drawString(format.format(xmin), (int)xc(xmin), (int)yc(0)-5);
if (!(format.format(xmin+dx).equals("0")))
g.drawString(format.format(xmin + dx), (int)xc(xmin + dx), (int)yc(0)-5);
if (!(format.format(xmin+dx*2).equals("0")))
g.drawString(format.format(xmin + 2*dx), (int)xc(xmin + 2*dx), (int)yc(0)-5);
if (!(format.format(xmin+dx*3).equals("0")))
g.drawString(format.format(xmin + 3*dx), (int)xc(xmin + 3*dx), (int)yc(0)-5);
if (!(format.format(xmin+dx*4).equals("0")))
g.drawString(format.format(xmin + 4*dx), (int)xc(xmin + 4*dx)-20, (int)yc(0)-5);
} else {
g.drawString("O", (int)xc(0)+5, (int)yc(0)+15);

if (xmin != 0)
g.drawString(String.valueOf(xmin), (int)xc(xmin), (int)yc(0)+15);
if (xmin + dx != 0)
g.drawString(String.valueOf(xmin + dx), (int)xc(xmin + dx), (int)yc(0)+15);
if (xmin + 2*dx != 0)
g.drawString(String.valueOf(xmin + 2*dx), (int)xc(xmin + 2*dx), (int)yc(0)+15);
if (xmin + 3*dx != 0)
g.drawString(String.valueOf(xmin + 3*dx), (int)xc(xmin + 3*dx), (int)yc(0)+15);
if (xmin + 4*dx != 0)
g.drawString(String.valueOf(xmin + 4*dx), (int)xc(xmin + 4*dx)-20, (int)yc(0)+15);
if (!(format.format(xmin).equals("0")))
g.drawString(format.format(xmin), (int)xc(xmin), (int)yc(0)+15);
if (!(format.format(xmin+dx).equals("0")))
g.drawString(format.format(xmin + dx), (int)xc(xmin + dx), (int)yc(0)+15);
if (!(format.format(xmin+dx*2).equals("0")))
g.drawString(format.format(xmin + 2*dx), (int)xc(xmin + 2*dx), (int)yc(0)+15);
if (!(format.format(xmin+dx*3).equals("0")))
g.drawString(format.format(xmin + 3*dx), (int)xc(xmin + 3*dx), (int)yc(0)+15);
if (!(format.format(xmin+dx*4).equals("0")))
g.drawString(format.format(xmin + 4*dx), (int)xc(xmin + 4*dx)-20, (int)yc(0)+15);
}

if (ymin + 4*dy != 0)
g.drawString(String.valueOf(ymin + 4*dy), (int)xc(0)+5, (int)yc(ymin + 4*dy)+15);
if (ymin + 3*dy != 0)
g.drawString(String.valueOf(ymin + 3*dy), (int)xc(0)+5, (int)yc(ymin + 3*dy)+10);
if (ymin + 2*dy != 0)
g.drawString(String.valueOf(ymin + 2*dy), (int)xc(0)+5, (int)yc(ymin + 2*dy)+10);
if (ymin + dy != 0)
g.drawString(String.valueOf(ymin + dy), (int)xc(0)+5, (int)yc(ymin + dy)+10);
if (ymin != 0)
g.drawString(String.valueOf(ymin), (int)xc(0)+5, (int)yc(ymin)-5);
if (!(format.format(ymin+dy*4).equals("0")))
g.drawString(format.format(ymin + 4*dy), (int)xc(0)+5, (int)yc(ymin + 4*dy)+15);
if (!(format.format(ymin+dy*3).equals("0")))
g.drawString(format.format(ymin + 3*dy), (int)xc(0)+5, (int)yc(ymin + 3*dy)+10);
if (!(format.format(ymin+dy*2).equals("0")))
g.drawString(format.format(ymin + 2*dy), (int)xc(0)+5, (int)yc(ymin + 2*dy)+10);
if (!(format.format(ymin+dy*1).equals("0")))
g.drawString(format.format(ymin + dy), (int)xc(0)+5, (int)yc(ymin + dy)+10);
if (!(format.format(ymin).equals("0")))
g.drawString(format.format(ymin), (int)xc(0)+5, (int)yc(ymin)-5);


g.setColor(Color.blue);
Expand Down
9 changes: 9 additions & 0 deletions calc/rpn/Calc.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ private void calculation(Deque<Double> stack, String op) throws ArithmeticExcept
} else if (op.equals("tan")) {
a = StackPop(stack);
stack.push(Math.tan(a));
} else if (op.equals("sinh")) {
a = StackPop(stack);
stack.push(Math.sinh(a));
} else if (op.equals("cosh")) {
a = StackPop(stack);
stack.push(Math.cosh(a));
} else if (op.equals("tanh")) {
a = StackPop(stack);
stack.push(Math.tanh(a));
} else if (op.equals("atan")) {
a = StackPop(stack);
stack.push(Math.atan(a));
Expand Down
6 changes: 6 additions & 0 deletions calc/rpn/ToRPN.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ private void oplinit(OperatorList opl, boolean mode) {
opl.list.add(opl.InputOperatorList("sqrt",100));
opl.list.add(opl.InputOperatorList("sin",100));
opl.list.add(opl.InputOperatorList("cos",100));
opl.list.add(opl.InputOperatorList("sinh",100));
opl.list.add(opl.InputOperatorList("cosh",100));
opl.list.add(opl.InputOperatorList("tanh",100));
opl.list.add(opl.InputOperatorList("tan",100));
opl.list.add(opl.InputOperatorList("asin",100));
opl.list.add(opl.InputOperatorList("acos",100));
Expand Down Expand Up @@ -220,6 +223,9 @@ private void oplinit(OperatorList opl, boolean mode) {
opl.list.add(opl.InputOperatorList("sin",10));
opl.list.add(opl.InputOperatorList("cos",10));
opl.list.add(opl.InputOperatorList("tan",10));
opl.list.add(opl.InputOperatorList("sinh",10));
opl.list.add(opl.InputOperatorList("cosh",10));
opl.list.add(opl.InputOperatorList("tanh",10));
opl.list.add(opl.InputOperatorList("asin",10));
opl.list.add(opl.InputOperatorList("acos",10));
opl.list.add(opl.InputOperatorList("atan",10));
Expand Down

0 comments on commit 3491872

Please sign in to comment.