SlideShare a Scribd company logo
1 of 4
Download to read offline
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 () . 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);
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
(14)); assertEquals (3, isqrt (15));

More Related Content

Similar to IN JAVA, 1. Put TestCalculator and UnlockTest in the default packa.pdf

شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثةجامعة القدس المفتوحة
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfJUSTSTYLISH3B2MOHALI
 
Import java
Import javaImport java
Import javaheni2121
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладкаDEVTYPE
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsTomek Kaczanowski
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingPathomchon Sriwilairit
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfShashikantSathe3
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfkarymadelaneyrenne19
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 

Similar to IN JAVA, 1. Put TestCalculator and UnlockTest in the default packa.pdf (20)

شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
 
Import java
Import javaImport java
Import java
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdfJAVA.Q4 Create a Time class. This class will represent a point in.pdf
JAVA.Q4 Create a Time class. This class will represent a point in.pdf
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Thread
ThreadThread
Thread
 

More from aggarwalenterprisesf

it must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdfit must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdfaggarwalenterprisesf
 
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfIntroducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfaggarwalenterprisesf
 
Insert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdfInsert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdfaggarwalenterprisesf
 
It is currently January 2011 and the futures price for June WTI cru.pdf
It is currently January 2011 and the futures price for June WTI cru.pdfIt is currently January 2011 and the futures price for June WTI cru.pdf
It is currently January 2011 and the futures price for June WTI cru.pdfaggarwalenterprisesf
 
It has been estimated that only about 30 of California residents ha.pdf
It has been estimated that only about 30 of California residents ha.pdfIt has been estimated that only about 30 of California residents ha.pdf
It has been estimated that only about 30 of California residents ha.pdfaggarwalenterprisesf
 
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdfIrkanias aggregate Irkanias aggregate expenditures function is sho.pdf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdfaggarwalenterprisesf
 
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdf
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdfIrene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdf
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdfaggarwalenterprisesf
 
Issue the commandscript BackupCommandsThis command will record .pdf
Issue the commandscript BackupCommandsThis command will record .pdfIssue the commandscript BackupCommandsThis command will record .pdf
Issue the commandscript BackupCommandsThis command will record .pdfaggarwalenterprisesf
 
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdf
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdfirket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdf
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdfaggarwalenterprisesf
 
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdfInvestigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdfaggarwalenterprisesf
 
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdfIntroducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdfaggarwalenterprisesf
 
Introducci�n El vocabulario, como una de las �reas de conocimient.pdf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdfIntroducci�n El vocabulario, como una de las �reas de conocimient.pdf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdfaggarwalenterprisesf
 
Internet providers can be considered a monopoly where consumers have.pdf
Internet providers can be considered a monopoly where consumers have.pdfInternet providers can be considered a monopoly where consumers have.pdf
Internet providers can be considered a monopoly where consumers have.pdfaggarwalenterprisesf
 
Instructions The paper should be in APA format with 3-4 pages doubl.pdf
Instructions The paper should be in APA format with 3-4 pages doubl.pdfInstructions The paper should be in APA format with 3-4 pages doubl.pdf
Instructions The paper should be in APA format with 3-4 pages doubl.pdfaggarwalenterprisesf
 
InstructionsAssume that your class group has been selected and hir.pdf
InstructionsAssume that your class group has been selected and hir.pdfInstructionsAssume that your class group has been selected and hir.pdf
InstructionsAssume that your class group has been selected and hir.pdfaggarwalenterprisesf
 
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdf
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdfInstrucciones Imagine que forma parte de un equipo de investigaci�.pdf
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdfaggarwalenterprisesf
 
In what way are the emerging trends of working couples, lower birthr.pdf
In what way are the emerging trends of working couples, lower birthr.pdfIn what way are the emerging trends of working couples, lower birthr.pdf
In what way are the emerging trends of working couples, lower birthr.pdfaggarwalenterprisesf
 
In this assignment, you examine the Supreme Court case of Terry v. O.pdf
In this assignment, you examine the Supreme Court case of Terry v. O.pdfIn this assignment, you examine the Supreme Court case of Terry v. O.pdf
In this assignment, you examine the Supreme Court case of Terry v. O.pdfaggarwalenterprisesf
 
In the SS partnership (to which Fozzie seeks admittance), the capita.pdf
In the SS partnership (to which Fozzie seeks admittance), the capita.pdfIn the SS partnership (to which Fozzie seeks admittance), the capita.pdf
In the SS partnership (to which Fozzie seeks admittance), the capita.pdfaggarwalenterprisesf
 
IN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdfIN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdfaggarwalenterprisesf
 

More from aggarwalenterprisesf (20)

it must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdfit must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdf
 
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfIntroducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
 
Insert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdfInsert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdf
 
It is currently January 2011 and the futures price for June WTI cru.pdf
It is currently January 2011 and the futures price for June WTI cru.pdfIt is currently January 2011 and the futures price for June WTI cru.pdf
It is currently January 2011 and the futures price for June WTI cru.pdf
 
It has been estimated that only about 30 of California residents ha.pdf
It has been estimated that only about 30 of California residents ha.pdfIt has been estimated that only about 30 of California residents ha.pdf
It has been estimated that only about 30 of California residents ha.pdf
 
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdfIrkanias aggregate Irkanias aggregate expenditures function is sho.pdf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdf
 
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdf
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdfIrene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdf
Irene, yerel bir kolejdeki �renciler hakknda bilgi topluyor. te topl.pdf
 
Issue the commandscript BackupCommandsThis command will record .pdf
Issue the commandscript BackupCommandsThis command will record .pdfIssue the commandscript BackupCommandsThis command will record .pdf
Issue the commandscript BackupCommandsThis command will record .pdf
 
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdf
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdfirket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdf
irket bakan, �ou posta yoluyla ve dierleri irketin intraneti araclyl.pdf
 
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdfInvestigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
 
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdfIntroducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
 
Introducci�n El vocabulario, como una de las �reas de conocimient.pdf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdfIntroducci�n El vocabulario, como una de las �reas de conocimient.pdf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdf
 
Internet providers can be considered a monopoly where consumers have.pdf
Internet providers can be considered a monopoly where consumers have.pdfInternet providers can be considered a monopoly where consumers have.pdf
Internet providers can be considered a monopoly where consumers have.pdf
 
Instructions The paper should be in APA format with 3-4 pages doubl.pdf
Instructions The paper should be in APA format with 3-4 pages doubl.pdfInstructions The paper should be in APA format with 3-4 pages doubl.pdf
Instructions The paper should be in APA format with 3-4 pages doubl.pdf
 
InstructionsAssume that your class group has been selected and hir.pdf
InstructionsAssume that your class group has been selected and hir.pdfInstructionsAssume that your class group has been selected and hir.pdf
InstructionsAssume that your class group has been selected and hir.pdf
 
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdf
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdfInstrucciones Imagine que forma parte de un equipo de investigaci�.pdf
Instrucciones Imagine que forma parte de un equipo de investigaci�.pdf
 
In what way are the emerging trends of working couples, lower birthr.pdf
In what way are the emerging trends of working couples, lower birthr.pdfIn what way are the emerging trends of working couples, lower birthr.pdf
In what way are the emerging trends of working couples, lower birthr.pdf
 
In this assignment, you examine the Supreme Court case of Terry v. O.pdf
In this assignment, you examine the Supreme Court case of Terry v. O.pdfIn this assignment, you examine the Supreme Court case of Terry v. O.pdf
In this assignment, you examine the Supreme Court case of Terry v. O.pdf
 
In the SS partnership (to which Fozzie seeks admittance), the capita.pdf
In the SS partnership (to which Fozzie seeks admittance), the capita.pdfIn the SS partnership (to which Fozzie seeks admittance), the capita.pdf
In the SS partnership (to which Fozzie seeks admittance), the capita.pdf
 
IN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdfIN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
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
  • 4. (14)); assertEquals (3, isqrt (15));