Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Look for some finshing touches java help with this program. I just two more thin

ID: 3823143 • Letter: L

Question

Look for some finshing touches java help with this program.

I just two more things added to this code. A loop at the end that will ask the user if they want to quit if they do want to quit the program stops if they don't it loads a new number sequence.

import java.util.Random;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;


public class main {

public static void main(String[] args) {

List < Sequence > list = new ArrayList < Sequence > ();
list.add(new Fibonnaci());
list.add(new MultipleOf3());
list.add(new MultipleOf5());
list.add(new MultipleOf8());
list.add(new MultipleOf10());

Random rand = new Random();
int n = rand.nextInt(2) + 1;

Sequence seq = list.get(n);
System.out.print("What is the next number in this sequence? ");

Integer nums[] = seq.getSequence();
  
for (int i = 0; i < 6; i++){
System.out.print(nums[i] + ", ");
}

System.out.println("...");


List < Integer > randomNum = getrandomNum(nums);

if (!randomNum.contains(nums[6])) {

int index = rand.nextInt(3) + 1;

randomNum.set(index, nums[6]);

}


for (int i = 0; i < 4; i++) {

System.out.println(randomNum.get(i));

}

Scanner scan = new Scanner(System.in);
System.out.print("Enter the number: ");

int num = scan.nextInt();
if (nums[6] == num)
System.out.println("You are correct");
else

System.out.println("You missed the question");
scan.close();

}
  


public static List<Integer> getrandomNum(Integer arr[]){

Integer[] numArray = new Integer[10];

for(int i=0;i<10;i++)
   numArray[i] = numArray[i];

List<Integer> list = Arrays.asList(numArray);
Collections.shuffle(list);

return list.subList(0, 4);

}

}

Explanation / Answer

1) In method getrandomNum(Integer arr[])

given code is taking value from numArray and putting again in numArray, i think there is no logical point doing it instead it should be
numArray[i] = arr[i]; //The array which is there in function argument

2) Integer nums[] = seq.getSequence();

The function needs a input argument as per its definition
public static Sequence getSequence(URL url)
throws InvalidMidiDataException,
IOException

This function is defined in MidiSystem class of javax.sound.midi package and returns a Sequence based object of MIDI file data which is pointed by provided File as argument.

So taking the response in Sequnce object is correct but without passing agrument it won't work hence please enter the file from which you want to read the data.

3) import the package javax.sound.midi.* in order to get Sequence class.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote