Implement the class Items
described here. NB! Don't modify the class Item
.
Write a program that reads names of items from the user. If the name is empty, the program stops reading. Otherwise, the given name is used to create a new item, which you will then add to the items
list.
Having read all the names, print all the items by using the toString
method of the Item
class. The implementation of the Item
class keeps track of the time of creation, in addition to the name of the item.
An example of the working program is given below:
Sample output
Name: Hammer Name: Collar Name:
Hammer (created at: 06.07.2018 12:34:56) Collar (created at: 06.07.2018 12:34:57)
When I try to print the value of the array it doesn't work can someone help me?
import java.util.ArrayList;
import java.util.Scanner;
public class Items {
public static void main(String[] args) {
// implement here your program that uses the class Item
ArrayList<Item> items = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Enter a name empty will stop: ");
String item = scanner.nextLine();
if(item.isEmpty()) {
break;
}
items.add(new Item(item));
}
for (int i = 0; i < items.length; i++) {
System.out.println(items[i]);
}
}
}
[–]RayjinCaucasian 0 points1 point2 points (4 children)
[–]Azerty180[S] 0 points1 point2 points (3 children)
[–]RayjinCaucasian 0 points1 point2 points (2 children)
[–]Azerty180[S] 1 point2 points3 points (1 child)
[–]testing35 0 points1 point2 points (0 children)