Code it in Java please The following are the steps that you should follow: (1) C
ID: 3734830 • Letter: C
Question
Code it in Java please
The following are the steps that you should follow: (1) Create an array of String objects and populate it with the the following colors: (Red, Purple, Orange, Yellow, Green) (2) Create an array parallelto the one created in (1) to store the Fruit or Vegetable that goes along with the colors (i.e., Apple for Red, Eggplant for Purple, etc.). However, you do not have this information, so you will need to write a loop that prompts the user to enter a Fruit or Vegetable that goes with that color. This prompt should include the color for which you are asking for the information (e.g., "What Fruit or Vegetable goes with this color?") (3) Create another parallel array that stores the number of fruit or vegetables wanted. You will also need to collect this information from the user. This time, your prompt should include the name of the color or fruit/vegetable for which you are asking for the number. (4) Print out each array item on it's own line such as follows / Color Fruit or Vegetable Number Wanted /I Red Purple Orange Yellow Green Apple Eggplant Orange Banana Lime 10 20 NOTE 1) Remember when to use print vs printn 2) Remember when to use Tab and how to use Tab in your print statement 3) Your program must use the Array name to output the Array values and not just hardcode the values. (i.e. color[index] instead of just putting "Purple" in your print statements)Explanation / Answer
package org.students;
import java.util.Scanner;
public class FruitsOrVegitablesWanted {
public static void main(String[] args) {
//Declaring variables
String colors[]={"Red","Purple","Orange","Yellow","Green"};
String friuts[]=new String[5];
int qty[]=new int[5];
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user and populate those values into an array
for(int i=0;i<friuts.length;i++)
{
System.out.print("What Fruit or vegitable that goes with the color "+colors[i]+" ?");
friuts[i]=sc.nextLine();
System.out.print("How many "+friuts[i]+" you want ?");
qty[i]=sc.nextInt();
sc.nextLine();
}
//Displaying the report
System.out.println(" ////////////////////////////////////////");
System.out.println("Color Fruit Or Vegitable Number Wanted");
System.out.println("////////////////////////////////////////");
for(int i=0;i<colors.length;i++)
{
System.out.printf("%5s %10s %d ",colors[i],friuts[i],qty[i]);
}
System.out.println("////////////////////////////////////////");
}
}
__________________
Output:
What Fruit or vegitable that goes with the color Red ?Apple
How many Apple you want ?10
What Fruit or vegitable that goes with the color Purple ?Eggplant
How many Eggplant you want ?8
What Fruit or vegitable that goes with the color Orange ?Orange
How many Orange you want ?11
What Fruit or vegitable that goes with the color Yellow ?Banana
How many Banana you want ?6
What Fruit or vegitable that goes with the color Green ?Lime
How many Lime you want ?20
////////////////////////////////////////
Color Fruit Or Vegitable Number Wanted
////////////////////////////////////////
Red Apple 10
Purple Eggplant 8
Orange Orange 11
Yellow Banana 6
Green Lime 20
////////////////////////////////////////
_______________Thank You