Question

Using Java(netbeans), please create the following arrays: myArray, which contains the numbers 1-5 stringArray, which contains...

Using Java(netbeans), please create the following arrays:

  1. myArray, which contains the numbers 1-5
  2. stringArray, which contains 5 strings
  3. An emptyArray
  4. An inventory array
  5. lengthArray, which contains 0-10

Once you have done that, please do the following:

  1. Print the number “1” from myArray
  2. Print the 3rdelement in the stringArray
  3. Append the word “foo” to the emptyArray
  4. Add six items to the inventory
  5. Print the length of the lengthArray
  6. Loop through lengthArray using a for loop, adding 5 to each element
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks!
===========================================================================

// need an Inventory class to create Inventory array
class Inventory {

    String name;
    double price;

    public Inventory(String name, double price) {
        this.name = name;
        this.price = price;
    }
}

public class ArrayProblem {

    public static void main(String[] args) {

        //myArray, which contains the numbers 1-5
        int[] myArray = {1, 2, 3, 4, 5};

        //stringArray, which contains 5 strings
        String[] stringArray = {"John", "Peter", "Paul", "Jacob", "Issac"};

        //An emptyArray
        String emptyArray[];

        //An inventory array
        Inventory inventory[];

        //lengthArray, which contains 0-10
        int[] lengthArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

        // -------------------------------------------------------  //

        //Print the number “1” from myArray
        System.out.println("myArray[0] = " + myArray[0]);

        //Print the 3rdelement in the stringArray
        System.out.println("stringArray[2] = " + stringArray[2]);

        // Append the word “foo” to the emptyArray
        emptyArray = new String[1];
        emptyArray[0] = "foo";


        // Add six items to the inventory
        inventory = new Inventory[6];
        inventory[0] = new Inventory("Apples",12);
        inventory[1] = new Inventory("Oranges",5);
        inventory[2] = new Inventory("Grapes",3);
        inventory[3] = new Inventory("Kiwi",2.99);
        inventory[4] = new Inventory("Apricot",1.99);
        inventory[5] = new Inventory("Banana",5.99);


        // Print the length of the lengthArray
        System.out.println("lengthArray.length = " + lengthArray.length);


        // oop through lengthArray using a for loop, adding 5 to each element
        for(int i=0; i<lengthArray.length;i++){
            lengthArray[i]+=5;
        }
    }
}

==================================================================

Add a comment
Know the answer?
Add Answer to:
Using Java(netbeans), please create the following arrays: myArray, which contains the numbers 1-5 stringArray, which contains...
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
  • by netBeans C++ java by netBeans C++ java by netBeans C++ java 1. Answer the following...

    by netBeans C++ java by netBeans C++ java by netBeans C++ java 1. Answer the following question a) (4 marks) Write a Java method, which takes an integer array and two integers x and y as input parameters. The method should exchange the value in position x with the value in the position y in the array. Example: If x = 1, y=2 Input Array Output Array b) (4 marks) Write the main method to do the following: 1. Define...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Using arrays create a personal phone directory that contains room for first names and phone numbers...

    Using arrays create a personal phone directory that contains room for first names and phone numbers for 20 people. Using the "names.txt" retrieve the first name and phone number for each person and store in arrays (parallel). Prompt the user for a name, search for the name, and if name is found in the array, display the corresponding phone number. If the name is not found, prompt the user to enter a phone number, and add the new name and...

  • Create a new ArrayPractice project in Eclipse and a class named ArrayPractice.java. Put everything that follows...

    Create a new ArrayPractice project in Eclipse and a class named ArrayPractice.java. Put everything that follows into the main method except the method arrayAverage. Create a 5 element array of doubles called grades that contains the following numbers in this order: 81.2, 92.5, 48.9, 78.8, and 45.5. Create a 7 element array of ints called numbers that contains the following numbers in this order: 12, 42, 33, 67, 92, 58, and 33. Create a 9 element array of Strings called...

  • please help fill out the class menu create a prototype that will display information about housing...

    please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to...

    Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array    Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....

  • 3. Arrays Question_code) [16 Marks] Develop a Java application which stores the following number of online...

    3. Arrays Question_code) [16 Marks] Develop a Java application which stores the following number of online flight ticket bookings for each of the last 4 months into an array. Month Number of Flight Ticket Bookings February 6150 March 9085 April 6689 May 8365 Your answer should include the following: a) Give an appropriate name to your array, initialize it with an appropriate datatype and add the number of flight ticket bookings for the last 4 months to the array as...

  • Array lists are objects that, like arrays, provide you the ability to store items sequentially and...

    Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to develop some basic skills. Let's start with the code below: The main method imports java.utii.ArrayList and creates an ArrayList that can hold strings by using the new command along with the ArrayList default constructor. It also prints out the ArrayList and, when it does, we see that...

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