Question

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

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);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
Look for some finshing touches java help with this program. I just two more things added...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • Here is the finsihed java program, it just needs to be converted to MIPs assembly language:...

    Here is the finsihed java program, it just needs to be converted to MIPs assembly language: import java.util.*; public class LoveCS { public static void main(String[] args) { int timesMessagePrinted; int count = 0; int sum = 0; Scanner input = new Scanner(System.in); System.out.print("How many times should the message be printed?: "); timesMessagePrinted = input.nextInt(); for(int x = 1; x <= timesMessagePrinted; x++) { System.out.println(x +" I love Computer Science!!"); count++; sum += x; } System.out.print("Printed this message " +count...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at...

    I have this code but when there's 0 pennies, it doesn't output "and 0 pennies" at all, it is just left blank. package edu.wit.cs.comp1050; /** * Solution to the third programming assignment * When it runs it outputs the amount in quarters, dimes, nickels and pennies * * @author Rose Levine * */ import java.util.Scanner; public class PA1c {       /**    * Error message to display for negative amount    */    public static final String ERR_MSG =...

  • 1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into...

    1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into an appropriate folder in your drive. a) Go through the codes then run the file and write the output with screenshot (please make sure that you change the location of the file) (20 points) b) Write additional Java code that will show the average of all numbers in input.txt file (10 points) import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.io.*; 1- * @author mdkabir...

  • Help check why the exception exist do some change but be sure to use the printwriter...

    Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT