IN JAVA,
1. Put TestCalculator and UnlockTest in the default package.
2. Put Calculator, CalculatorGUI and Operation in another package.
3. Put IntMath in another package.
4. Complete the Calculator class by implementing all methods from the TestCalculator class
using the IntMath class do define the sqrt() method.
5. Make sure all tests pass in TestCalculator.// Import Intmath here import java.util.
EmptystackException; import java.util.Stack: - Class to perform integer calculations online given
method calls. * It uses normal arithmetic operator precedence, defined on the operation enum, *
and assumes left associativity. A calculator can be in one of three states: - <0l> - clear: Nothing
pending - Ready: A value is available * li> waiting: An operator has been started and we're
waiting for a value * * At any point if a division by zero is caused, the appropriate exception is
raised. r/ public class calculator \{ // The stack of operands for the calculator Stack operandStack
= new Stack(); / The stack of operators for the calculator Stack operatorstack = new Stack ( ); //
The value of the current expression long value; // Whether the current expression is expected to
be a valid expression boolean expected;
import java.awt. BorderLayout; import java.awt. Color: import java.awt.Dimension; import java.
awt. Font; import java.awt. Graphics; import java.awt. GridLayout; import java.awt. Toolkit;
import java.awt.event. Actionevent; import java.awt, event. ActionListener; import java.util.
EmptyStackException; import javax.swing.JButton; import javax. swing. JFrame; import javax.
swing. JPane :; import javax.swing. Swingutilities; import javax. swing.WindowConstants;
public class calculatorGUI extends JFrame \{ F Keep Eclipse happy / private static final long
seriatversionUID = 1L; public static void main(String[] args) \{ Swingutilities.invokeLater (new
Runnab le() \{ public void run() \{ CalculatorGUI c= new calculatorGUI(); c.setSize (300,300);
c.setvisible(true); 3); private static final int FONT SIZE = 20; private Font buttonFont = new
Font ("Monospaced",Font. PLAIN, FONT SIZE); public calculatorguI( ) \{ super("Hexidecimal
Calculator"); JPanel contentPane = new JPanel () ; contentPane.setLayout (new BorderLayout
()); JPanel buttonPane = new JPanel(); contentPane. add ( buttonPane, BorderLayout, CENTER);
resultpane = new ResultPane(); resultPane. setPreferredSize (new Dimension(FONT SIZE*
(16+1), FONT SIZE*2)); contentPane. add ( resultPane, BorderLayout . NORTH);
buttonPane.setLayout (new GridLayout (5,5) ); JButton [ ] buttons = new JButton [16]; for (int
i=0;i<16;++i){ String hexits =+( char )((i<10?0:(A10))+i); buttons [i]= new JButton(hexits);
buttons [i].setFont (buttonFont); buttons [i]. addActionListener (new AddHexitsactionListener
(hexits)); \} JButton byteButton = new JButton("0"); byteButton. setFont (buttonFont);
byteButton.addActionListener (new AddHexitsActionListener("0")); JButton [] opButtons = new
JButton [Operation. values ().
Procuring digital preservation CAN be quick and painless with our new dynamic...
IN JAVA, 1. Put TestCalculator and UnlockTest in the default packa.pdf
1. IN JAVA,
1. Put TestCalculator and UnlockTest in the default package.
2. Put Calculator, CalculatorGUI and Operation in another package.
3. Put IntMath in another package.
4. Complete the Calculator class by implementing all methods from the TestCalculator class
using the IntMath class do define the sqrt() method.
5. Make sure all tests pass in TestCalculator.// Import Intmath here import java.util.
EmptystackException; import java.util.Stack: - Class to perform integer calculations online given
method calls. * It uses normal arithmetic operator precedence, defined on the operation enum, *
and assumes left associativity. A calculator can be in one of three states: - <0l> - clear: Nothing
pending - Ready: A value is available * li> waiting: An operator has been started and we're
waiting for a value * * At any point if a division by zero is caused, the appropriate exception is
raised. r/ public class calculator { // The stack of operands for the calculator Stack operandStack
= new Stack(); / The stack of operators for the calculator Stack operatorstack = new Stack ( ); //
The value of the current expression long value; // Whether the current expression is expected to
be a valid expression boolean expected;
import java.awt. BorderLayout; import java.awt. Color: import java.awt.Dimension; import java.
awt. Font; import java.awt. Graphics; import java.awt. GridLayout; import java.awt. Toolkit;
import java.awt.event. Actionevent; import java.awt, event. ActionListener; import java.util.
EmptyStackException; import javax.swing.JButton; import javax. swing. JFrame; import javax.
swing. JPane :; import javax.swing. Swingutilities; import javax. swing.WindowConstants;
public class calculatorGUI extends JFrame { F Keep Eclipse happy / private static final long
seriatversionUID = 1L; public static void main(String[] args) { Swingutilities.invokeLater (new
Runnab le() { public void run() { CalculatorGUI c= new calculatorGUI(); c.setSize (300,300);
c.setvisible(true); 3); private static final int FONT SIZE = 20; private Font buttonFont = new
Font ("Monospaced",Font. PLAIN, FONT SIZE); public calculatorguI( ) { super("Hexidecimal
Calculator"); JPanel contentPane = new JPanel () ; contentPane.setLayout (new BorderLayout
()); JPanel buttonPane = new JPanel(); contentPane. add ( buttonPane, BorderLayout, CENTER);
resultpane = new ResultPane(); resultPane. setPreferredSize (new Dimension(FONT SIZE*
(16+1), FONT SIZE*2)); contentPane. add ( resultPane, BorderLayout . NORTH);
buttonPane.setLayout (new GridLayout (5,5) ); JButton [ ] buttons = new JButton [16]; for (int
i=0;i<16;++i){ String hexits =+( char )((i<10?0:(A10))+i); buttons [i]= new JButton(hexits);
buttons [i].setFont (buttonFont); buttons [i]. addActionListener (new AddHexitsactionListener
(hexits)); } JButton byteButton = new JButton("0"); byteButton. setFont (buttonFont);
2. byteButton.addActionListener (new AddHexitsActionListener("0")); JButton [] opButtons = new
JButton [Operation. values () . Length]; for (operation op : operation.values( )) {
import java.util. EmptystackException; import edu.uwm. apc 430 . Calculator; import edu.uwm.
apc 430 . Operation; import edu.utim.cs.junit. LockedTestCase; public class Testcalculator
extends LockedTestcase { private Calculator calc; Boverride protected void setup() throws
Exception { super setUp(); calc= new Calculator () ; 3 public void test() { // getcurrent() should
show what number the calculator is showing calc.value(2); assertEquals(Ti(112243502), calc.
getcurrent()); calc.binop(operation.PLUS); assertEquals( Ti ( 1121703203), calc . getcurrent ());
calc. value (3); assertEquals (Ti(2023348392), calc. getcurrent()); calc.binop(operation. TIMES);
assertEquals(Ti(543417517), calc.getcurrent()); calc. value(4); assertEquals(Ti(93138e893), calc.
getcurrent()); calc.binop(Operation. MINUS); assertEquals(14, calc. getcurrent()); // hard to
guess calc. value (5); calc. compute( ); assertEquals (Ti(1422690652), calc, getcurrent());
calc.sqrt(); assertEquals(Ti (209034868), calc.getcurrent()); } public void testinit() {
assertEquals ( , calc. getcurrent ()); assertEquals ( 0 , calc. compute()); 3 public void testvalue()
{ calc.value (7); assertEquals (7, calc getCurrent ()); assertequals ( 7 , calc. compute ()); 3 public
void testadd() { calc. value(1); calc.binop(operation.PLUS); calc. value(2); assertEquals ( 2 ,
calc. getcurrent ( )); assertequals ( 3, calc. compute( ) ) assertEquals ( 3 , calc. getcurrent ()); 3
public void testsub() { calc.binop(operation.MINUS); calc. value (2);
3. public enum Operation { PLUS("+", 1) { Boverride public long operate(long d1, long d2){ } 3
MINUS (",1,1){ Boverride public long operate(long d1, long d2) { return d1 - d2; } }. TIMES
(1n,2){ Boverride public long operate(long d1, long d2 ) { return d1 = d2; 3 3, DIVIDE ("/",2){
Boverride public long operate(long d1, long d2) { return d1/d2; 3 3 ir LPAREN (" (",0),
RPAREN (") ", ), ; private final string name; private final int precedence; private operation(string
name, int prec) { - name = name; _precedence = prec: } public static operation find(string
name) { for (Operation op : Operation. values()) { if (op._name. equals(name)) return op; 3
throw new Illegalargumentexception("no such operation: " + name); 3 public string tostring() {
return_name; 3 public long operate(long d1, long d2 ) { throw new
UnsupportedoperationException( "unbalanced parenthesis"); 3 public int precedence() { return
precedence; 3 }
import junit. framework. TestCase; public class Intmath { / * Return the integer square root
(rounded down) of an unsigned 64 bit integer. * eparam x value to perform square root on,
treated unsigned * Greturn largest value y for which yy<=x where x is treated as unsigned.
public static long isqrt( long x ) { // System.out.println("isqrt(" +x+ ")"); if (x>1){ long y=2; do
{ // System.out.print ln(" "+y+" is isqrt of "+x+ "?"); long r=x/y; if (r==y) return y; if (r>y &&
(y+1)(y+1)>x) return y; y=(y+r)/2; 3 while (true); } else if (x<1){ long y=
Integer.MAX_VALUE; do { // System.out.println(" "+y+" is isqrt of "+x+ "?"); long r=(x+
Long.MAX_VALUE +2)/y+ LOng.MAX_VALUE /y; // System.out.print ln(" quotient ="+r); if
(r==y) return r; if (r==y+1){ long z=y - Integer. MAX_VALUE; //y+1=z+(231) long nextsquare
=zz+(z32)+(1L62); // System.out.print ln("(y+1)2="+ nextsquare); if (nextsquare >x ) return y;
return r; } y=(y+r)/2; } while (true); } else if (x==1){ return (1L<32)1; } else return x;// and 1
3 public static class Test extends TestCase { public void testFirst25() { assertequals (, isqrt ());
assertEquals (1, isqrt (1)); assertEquals (1, isqrt (2)); assertEquals (1, isqrt (3)); assertEquals 2 ,
isqrt (4)); assertequals (2, isqrt (5)); assertEquals (2, isqrt (6)); assertEquals (2, isqrt (7)):
assertequals (2, isqrt (8)); assertequals (3, isqrt (9)); assertEquals (3,isqrt(10)); assertEquals (
3,iisqrt(11) ); assertEquals (3, isqrt (12)); assertequals ( 3 , isqrt (13)); assertequals ( 3 , isqrt