Question
Program1.java public class Program1 { public static void main(String[] args) { final int BSIZ = 1000; Bools bTest; bTest = new Bools(BSIZ); boolean b1 =
Program1.java
public class Program1 {
public static void main(String[] args) { final int BSIZ = 1000; Bools bTest; bTest = new Bools(BSIZ); boolean b1 = bTest.isSet(300); System.out.print("B1 == "); System.out.println(b1); bTest.set(300); b1 = bTest.isSet(300); System.out.print("B1 == "); System.out.println(b1); bTest.reset(); b1 = bTest.isSet(300); System.out.print("B1 == "); System.out.println(b1); } }
Bools.java
public class Bools { private final Boolean[] bArr; private final int size; public Bools(final int s) { bArr = new Boolean[s]; size = s; for(int i=0; i bArr[i] = false; } public final void reset() { for(int i=0; i bArr[i] = false; } public final void set(final int i) { bArr[i] = true; } public final boolean isSet(final int i) { final boolean t = bArr[i]; return t; } }
Assume you were given the accompanying two java files, a unit test file and a Bools class. Bools.java holds a class, Bools, containing an array of Booleans which can be set and tested via the set and isSet methods of the class. When reset is called all of the array values are set to false. The functions set and isSet are (1). That is, the time and resources these functions take are the same regardless of the size of n, the number of elements in the array. The reset function, on the other hand, is (n) because all n values must be cleared when called. Your task is to (each worth 20 points):
1. Change the reset method so it is (1).
2. Write the algorithm for reset method.
a. When the reset is called after n resets you should output a message that the array was reinitialized if an internal DEBUG constant is set to true. If set to false no message is output. The DEBUG value should be set to true.
3. Add a clear(final int i) method to the Bools class that will set bArr[i] to false. After n resets, you should reinitialize the array to zeroes and reset the internal true value to 1.
4. Provide a more comprehensive set of test cases than those provided to demonstrate your updated Bools class is correct. Demonstrate 3a above.
5. Adequately comment the unit test driver and Bools class to include ensuring both the driver and the Bools class have adequate comments. At a minimum you should include comments describing the methods in the Bools class and what was changed. And YOUR name should be in both the files, ideally in some sort of a header.
You may use whatever IDE (Ellipse, NetBeans ) javac *.java and the files should compile in the default package.
and
java CSCI6836Program1 to run the unit test and see the output. Write a java program. two java file here and you can read the question after you can implement .
The English description of the reset method is, we will now be working with an array of integers instead of booleans. Begin with all values of the array set to zero and a new private int variable, call it indx, set to 1. Whenever set(i) is called. iArr[i] is set to indx. The isSet(final int i) function returns true if iArr[i] is set to indx, false otherwise. The function clear(final int i) would set iArr[i] to indx-1 (you may want to maintain a private variable indxM1 set to indx-1 so you dont have to do the subtraction each time clear is called). Now all the reset function has to do is (set indxM1 to indx), increment indx and the state is reset. One statement would do it: indxM1 = indx--; If you can think of another way to do it, that is fine, just be sure reset is (1) and supply the algorithm.
View comments (1)
C: Windows system32\cmd.exe CaUserswilliamp Desktop>CSCI6836ProgranlFa112015>javac *.java CNUserswilliampDesktop\CSCI6836ProgramiFa112615>jaua -classpath . CSCI6836Pro gram1 B1 -- false B1true B1False C:\Users\willianp\DesktopCSCI 68 36Prograni Fal 12015>- C: Windows system32\cmd.exe CaUserswilliamp Desktop>CSCI6836ProgranlFa112015>javac *.java CNUserswilliampDesktop\CSCI6836ProgramiFa112615>jaua -classpath . CSCI6836Pro gram1 B1 -- false B1true B1False C:\Users\willianp\DesktopCSCI 68 36Prograni Fal 12015>Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started