Question: Using MethodsGiven String variables stored in foodItem 1 , foodItem 2 , foodItem 3 , foodItem 4 , foodItem 5 , foodItem 6 , and

Using MethodsGiven String variables stored in foodItem1, foodItem2, foodItem3, foodItem4, foodItem5, foodItem6, and foodItem7, do the following:
Declare a new ArrayList called pantry
Put the given variables into the pantry
Print to the console the following concatenations of a String and the results of a method:
Print "Size: "+ a method that will return the size of the List
Print "First element: "+ a method that will retrieve the first element in the List
Print "Is it Empty: "+ a method that will return a Boolean after checking if the List is empty
import java.io.*;
import java.util.*;
public class CodingQuestion {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String foodItem1= in.nextLine();
String foodItem2= in.nextLine();
String foodItem3= in.nextLine();
String foodItem4= in.nextLine();
String foodItem5= in.nextLine();
String foodItem6= in.nextLine();
String foodItem7= in.nextLine();
/***** DO NOT CHANGE THE CODE ABOVE THIS LINE *****/
// WRITE YOUR CODE HERE
// DO NOT CHANGE CODE BELOW THIS LINE
}// end of main()
}
STDOUT
Expected STDOUT
Size:7
Firstelement:Apples
IsitEmpty:false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!