You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.3 KiB

6 years ago
  1. // The StackApps class that implements two Stack applications
  2. // Your name here
  3. import java.util.Scanner;
  4. public class StackApps
  5. {
  6. // convert a decimal number into a binary number and save it in a stack
  7. // Do not create any arrays! Do not use any Java libraries to do the convertion.
  8. // Doing so will result in points deduction.
  9. public String decToBin(int numDec)
  10. {
  11. CharStack stackBinary = new CharStack(64); // stack used to store the result binary number
  12. // TODO: complete this method
  13. return stackBinary.toString(); // return a string representation of the stack
  14. }
  15. // compute the sum of the two big intergers and save the result in a stack
  16. // Do not create any arrays! Do not use any Java libraries to do the calculation.
  17. // Doing so will result in points deduction.
  18. public String addBigIntegers(String num1, String num2)
  19. {
  20. CharStack stackNum1 = new CharStack(64); // stack used to store number 1
  21. CharStack stackNum2 = new CharStack(64); // stack used to store number 2
  22. CharStack stackResult = new CharStack(64); // stack used to store the result of the addition
  23. // TODO: complete this method
  24. return stackResult.toString(); // return a string representation of the stack
  25. }
  26. }