Question

Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray th

We are using blueJ for my java class, if you can help me id greatly appreciate it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
import java.util.Random;

public class ChangeUp{
    public static void main(String [] args){
        int n = 6;
        int[] arr= new int[n];
        populateArray(arr); //We call populateArray by passing arrayWe.
        printArray(arr); //We call the printArray to output/print the components of array.
    }
    //here we interpret populateArray method
    public static void populateArray(int[] array){
        
        Random myrandom = new Random();
        Scanner s = new Scanner(System.in);
        int i = myrandom.nextInt(5) + 1; //We select random index for user to submit the numbr
        System.out.println("Enter the value in randomly chosen index number " + i + ":"); //asked to submit a value here.
        array[i] = s.nextInt();
   }
   //here we interpret the printArray method
    public static void printArray(int[] array){
        System.out.println("The upgraded array will be ");
        for(int a=0; a < array.length; a++){ //we will be using for loop here in order to print the values.
            System.out.print(array[a]); //System.out.print prints the array value.
            System.out.print("\t");// tab space
        }
    }
}
  • As asked, first we create the empty array of size 6
  • Further, creating a method named populateArray that passes an array which uses random class to choos a random index and further prompting the user to enter a value and store the value in array
  • Finally the printArray method prints the contents of the array for ench enhanced loop

I did not have blueJ compiler software so I used an online compiler to execute the code. Don't worry, it is just the same and make sure to save the program as ChangeUp.
Here is the screenshot to the code with output:

import java.util.Scanner; import java.util. Random; 8 9 4- public class Changeup{ 5 public static void main(String [] args) {

✓ Execute Mode, Version, Inputs & Arguments JDK 11.0.4 Interactive Stdin Inputs CommandLine Arguments 3 Execute Result CPU Ti

PLEASE UPVOTE

Add a comment
Know the answer?
Add Answer to:
We are using blueJ for my java class, if you can help me id greatly appreciate...
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
  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Create a method called printArray that prints the contents of the array using the for each...

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java class called AverageWeight. Create two arrays: an array to hold 3 different names and an array to hold their weights. Use Scanner to prompt for their name and weight and store in correct array. Compute and print the average of the weights entered using printf command. Use a loop to traverse and print the elements of each array or...

  • We are using blueJ for my java class, if you can help me id greatly appreciate...

    We are using blueJ for my java class, if you can help me id greatly appreciate it. Create a new Java program called Flip. Write code that creates and populates an array of size 25 with random numbers between 1-50. Print the array. Print array in reverse.

  • We use bluej for our JAVA class. If you can help me id greatly appreciate it....

    We use bluej for our JAVA class. If you can help me id greatly appreciate it. Create a new Java class called AverageWeight. Create two arrays: an array to hold 3 different names and an array to hold their weights. Use Scanner to prompt for their name and weight and store in correct array. Compute and print the average of the weights entered using printf command. Use a loop to traverse and print the elements of each array or use...

  • We use bluej for our JAVA program. If you can help id greatly appreciate it. Create...

    We use bluej for our JAVA program. If you can help id greatly appreciate it. Create a new Java program called Flip. Write code that creates and populates an array of size 25 with random numbers between 1-50. Print the array. Print array in reverse.

  • Java programming The purpose of this problem is to practice using a generic Urn class. NOTE:...

    Java programming The purpose of this problem is to practice using a generic Urn class. NOTE: Refer to the code for the ArrayStack class from Chapter 12. Use that code as a starting point to create the Urn class, modifying it to remove the methods in the ArrayStack class (push, pop, etc) then add the methods described below. Also change the variable names to reflect the new class. For example the array name should NOT be stack, instead it should...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers....

    Please complete the lab following the guidelines using JAVA Activity 1 Write a program called AnalyzeNumbers. This program will have array that holds 10 random integers from 1 to 5. Output the 10 random numbers to the screen using an enhanced for loop. This program will also have a method called frequency that takes an integer array as the parameter and it will return an array that holds the frequency of numbers. Index 0 will hold the frequency of 1,...

  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

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