123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
-
- /**
- * Write a description of class Operations here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.util.Scanner;
- public class Operations
- {
- Scanner scan = new Scanner(System.in);
-
- protected static boolean isError = false;
-
- protected static double currentNumber;
-
- protected double numInMemory;
-
- protected double firstNumber;
-
- protected double secondNumber;
-
- /**
- * Constructor for objects of class Operations
- */
- public Operations()
- {
- // initialise instance variables
- }
-
- public double getCurrentNumber() {
- return currentNumber;
- }
-
- public void display() {
- System.out.println(currentNumber);
- }
-
- public void update(double z) {
- System.out.println(z);
- currentNumber = z;
- }
-
- public void clear() {
- currentNumber = 0;
- System.out.println(currentNumber);
- isError = false;
- }
-
- public void remember() {
- numInMemory = currentNumber;
- System.out.println("Stored : " + numInMemory);
- }
-
- public void recall() {
- System.out.println("Stored value: " + numInMemory);
- currentNumber = numInMemory;
- }
-
- public void invertSign() {
- if (currentNumber == 0) {
- currentNumber = 0;
- update(currentNumber);
- } else if (currentNumber > 0){
- currentNumber -= (2 * currentNumber);
- update(currentNumber);
- } else {
- currentNumber += (-2 * currentNumber);
- update(currentNumber);
- }
- }
-
- public void addToNumInMemory() {
- numInMemory += currentNumber;
- System.out.println("Stored value: " + numInMemory);
- }
-
- public void switchDisplayMode() {
- System.out.print("Binary : 'Y' or 'N'");
- String choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
- int binary = (int)currentNumber;
- System.out.println(Integer.toBinaryString(binary));
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.println("Octal: 'Y' or 'N'");
- choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
-
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.println("Decimal: 'Y'or 'N'");
- choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
-
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.println("Hexadecimal: 'Y' or 'N'");
- choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
-
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.println(currentNumber);
- }
- }
- }
- }
- }
-
- public void switchUnitsMode() {
- System.out.print("Degrees : 'Y' or 'N'");
- String choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
- double degree = Math.toDegrees(currentNumber);
- double regular = currentNumber;
- update(degree);
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.println("Radians: 'Y' or 'N'");
- choice = scan.next();
- if (choice.equalsIgnoreCase("Y")) {
- double radians = Math.toRadians(currentNumber);
- double regular = currentNumber;
- update(radians);
- } else if (choice.equalsIgnoreCase("N")) {
- System.out.print(currentNumber);
- }
- }
- }
-
- }
|