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);
}
}
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.
Look for some finshing touches java help with this program. I just two more things added...
Can I get help with implementing a quick sort in my program? Starter Code: import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class RQS { public static int[] prepareData(int[] patients){ /* Data is prepared by inserting random values between 1 and 1000. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ // what is our range? int max = 1000; // create instance of Random class Random randomNum...
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 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 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: 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 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...
Write a Java method that should take an ArrayList as a parameter, print its element in the reverse order. The main function that calls the method is the following: import java.util.*; public class ReverseGen { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("How many numbers do you want to input?"); int num = input.nextInt(); ArrayList<Double> d = new ArrayList<Double>(num); for(int i = 0 ; i < num; i++){ System.out.print("Enter...
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 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 =...
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...