Replace the 3 System outprintln lines of code by some code t
Replace the 3 System out.println lines of code by some code that will compute and displays the total sum of the integers in the numbers array. Use a FOR loop. The total should be 725. Now copy/paste the following into a file called ArrayTestProgram2Java. In a similar manner as you did above, complete the code so that it displays true if the majority of booleans in the values array are true and displays false otherwise. Make sure that your code works for any boolean array. A count variable is provided. You can use it by adding 1 to the count when a true is encountered and subtracting l otherwise. Do you know how to use the final count to determine the answer? public class ArrayTestProgram2 {public static void main (String args []) {int count = 0; boolean [] values = {true false, false, false, true, true, true, false);}} Download the Team and League classes. Also download a test program (i.e., LeagueTestProgram.java) that you can use to test your methods. Compile all 3 files. Now write a method called teamMostPlayed in the League class which return a Team object s representing the team that has played the most games. Compile your code. Add the following code to the LeagueTestProgram to test your code:
Solution
Please find my code.
Please let me know in case of any isseu.
public class ArrayTestProgram2 {
public static void main(String[] args) {
int count = 0;
boolean[] values = {true, false, false, true, true, true, false};
for(int i=0; i<values.length; i++){
if(values[i]) // current value is true
count++;
else // current value from array values is false, so decrement count value
count--;
}
if(count <= 0){ // we have number of false >= true
System.out.println(\"false\");
}else{ // true are more than false
System.out.println(\"true\");
}
}
}
