Need help writing Java code 3. Write a computer program to play the \"Jump lt\"
ID: 3849813 • Letter: N
Question
Need help writing Java code
3. Write a computer program to play the "Jump lt" game described in Programming Projects #4 of chapter 11 (page 689.) You should read the BinarySearch algorithm in chapter 11 before doing this assignment. Define a class named Jump It as follows public class Jump It private String fileName: name of the file private int count 0; number of valid integers in the file private final int MAX SIZE 15; the size of the array constructor to set the game by reading integers from file read only MAX SIZE integers from the file, bad ints are ignored print out a message if file cannot be opened public JumpIt (String theName) constructor to set the file name this fileName new String (the Name) you may or may not want to do other stuffs here return the lowest total cost of the game throws an exception if the first int is not 0 public int play throws BadInputExceptionl print the all integers in the array public void print Game My File public class BadInput Exception extends Exception f public BadInput Exception f super The first int should be 0") or anything you like public BadInput Exception (String message) super (message)Explanation / Answer
public boolean canJump(int[] A) {
if(A.length <= 1)
return true;
int max = A[0];
for(int i=0; i<A.length; i++){
//if not enough to go to next
if(max <= i && A[i] == 0)
return false;
if(i + A[i] > max){
max = i + A[i];
}
if(max >= A.length-1)
return true;
}
return false;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.