011-002-006
Constructor Call: Object Array
Easy
Problem Description
constructor Call: Object array
In this problem, you will create a program that constructs an array of Menu objects, reads each menu's name and price from input, and displays them as a numbered list to standard output.
Learning Objective: Manage multiple objects with array
Create a program managing multiple menu items. Create a Menu[] array and store objects in each element with new. Array declaration alone doesn't create objects.
Input
Line 1: Number of menus (integer)
Following lines: Name and price of each menu (string integer)
Output
Menu 1: [name] - [price] yen
Menu 2: [name] - [price] yen
...
Examples
Example 1: 3 menus
Input:
3
Curry 800
Ramen 600
Yakiniku 1200
Output:
Menu 1: Curry - 800 yen
Menu 2: Ramen - 600 yen
Menu 3: Yakiniku - 1200 yen
Example 2: 2 menus
Input:
2
Pasta 900
Pizza 1000
Output:
Menu 1: Pasta - 900 yen
Menu 2: Pizza - 1000 yen
Example 3: 1 menu (boundary)
Input:
1
A 1
Output:
Menu 1: A - 1 yen
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up