Alright, I have been working on a project for my cs class. Here are the specs: http://www.cs.utsa.edu/~wagner/CS171.../project3.html
I have finished phase 2, but am not satisfied with the result. Here are the three files from the project created with JBuilder9:
public class ThreeHalvesTest {
public static void main(String[] args){
System.out.println("Project 3, Phase II: Longest run of any integer less than initial integer");
System.out.print("Enter Integer ---> ");
int n = Keyboard.readInt();
ThreeHalves test = new ThreeHalves(n+1);
ThreeHalvesRun[] test2;
test2 = test.getRunsArray();
ThreeHalvesRun test3 = (ThreeHalvesRun)findMax(test2);
System.out.println(test3);
}
public static Comparable findMax(Comparable[] c){
Comparable theMin = new ThreeHalvesRun(1);
int i = 0;
for(i=1;i<c.length;i++){
if(theMin.compareTo(c[i])<0){
theMin = c[i];
}
else{
theMin = theMin;
}
}
return theMin;
public class ThreeHalves {
public ThreeHalvesRun[] runs;
public ThreeHalves(int n){
runs = new ThreeHalvesRun[n];
for(int i=0;i<n;i++){
if(i == 0)
runs[i] = new ThreeHalvesRun(1);
else
runs[i] = new ThreeHalvesRun(i);
}
}
public ThreeHalvesRun[] getRunsArray(){
return runs;
}
}
If you look at ThreeHavesTest.java there is a part like this
ThreeHalves test = new ThreeHalves(n+1);
on about the sixth line of the main part of the program. That is a little patch I put in. The program is supposed to take in a value and do all the little tests on it found in ThreeHalvesRun.java on it for every value up to the one you entered. So if you entered 500, it would do the tests from 1-500. When I didn't put the n+1 in the parenthesis and just had n, it would only go up to 499. I know that the program is probably fine how it is, but this is bugging me. I completely understand if no one replies to this because this project is a pain. What I want the program to do is take in the amount you enter without adding 1 to it and still do the same as if you did add one to it. When messing around with this with certain changes I would get indexoutofbounds errors. The whole point of the program is to check each run for every number up to the number you input and see which is the longest.
Here is the output I get with the patch:
Project 3, Phase II: Longest run of any integer less than initial integer
Enter Integer ---> 27
Initial integer: 25, Length: 17, Maximum value: 44
25, 38, 19, 29, 44, 22, 11, 17, 26, 13,
20, 10, 5, 8, 4, 2, 1
Don't kill yourself on this, I just thought maybe someone could fix it up a bit. It runs with the little patch just fine so if need be I will just leave it at that.
Thanks.