Arraylist Questions
Arraylist Questions
QUESTION 1
Mark all of them as private and included appropriate getters/setters, also include
constructors. And override the toString method to print details of the ItemType
object.
Create a class ArrayListObjectMain and in the main method get the details of
ItemTypes and store them in an ArrayList.
All class names, attribute names, and method names should be the same as specified
in the problem statement.
Input format :
Number of items(N) in first-line as integer
Name, Deposit, and cost per day for each item in next lines as shown in sample
input
Output format :
Print the item details as shown in the sample output.
QUESTION 2
Problem Statement
Misha is planning a birthday party and wants to create a list of guests for the
party. She decided to use an ArrayList to store the names of the guests who were
invited.
She writes a program that takes input for the number of guests and then reads and
stores their names in an ArrayList. Finally, the program should display the list of
guests invited.
Input format :
The first line of input is an integer N, representing the number of guests Misha
wants to invite.
The next N lines each of input consists of a string, representing the name of a
guest.
Output format :
The output displays the names of the guests, each on a new line.
Code constraints :
In this scenario, the test cases will fall under the following constraints:
1 ≤ N ≤ 10
QUESTION 3
Problem Statement
Mesa, a store manager, needs a program to manage inventory items. Define a class
ItemType with private attributes for name, deposit, and cost per day. Create an
ArrayList in the Main class to store ItemType objects, allowing input and display.
Note: Use "%-20s%-20s%-20s" for formatting output in tabular format, display double
values with 1 decimal place.
Input format :
The first line of input consists of an integer n, representing the number of items.
Code constraints :
1 ≤ n ≤ 10
QUESTION 4
Problem Statement
Input format :
The first line of input consists of an integer N, representing the number of names
to be read.
Output format :
The output prints a single integer, representing the frequency of the specified
name in the given list.
QUESTION 5
Problem Statement
Raman, a computer science teacher, is responsible for registering students for his
programming class. To streamline the registration process, he wants to develop a
program that stores students' names and allows him to retrieve a student's name
based on their index in the list.
Raman has decided to use an ArrayList to store the names of students, as it
provides efficient dynamic resizing and indexing.
Write a program that enables Raman to input the names of students and fetch a
student's name using the specified index. If the entered index is invalid, the
program should return an appropriate message.
Input format :
The first line of input consists of an integer n, representing the number of
students to register.
The next n lines of input consist of the names of each student, one by one.
The last line of input is an integer, representing the index (0-indexed) of the
element to retrieve.
Output format :
If the index is valid (within the bounds of the ArrayList), print "Element at index
[index]: " followed by the element.
Code constraints :
The given test cases fall under the following constraints:
2 ≤ n ≤ 10
3 ≤ student's name ≤ 50
0 ≤ index < n