In: Computer Science
Can you please add comments to this code?
JAVA Code:
import java.util.ArrayList;
public class Catalog
{
String catalog_name;
ArrayList<Item> list;
Catalog(String cs_Gift_Catalog) {
list=new ArrayList<>();
catalog_name=cs_Gift_Catalog;
}
String getName() {
int size() {
return list.size();
}
Item get(int i) {
return list.get(i);
}
void add(Item item) {
list.add(item);
}
}
Thanks!
The complete source code with comments is given below:
//import ArrayList
import java.util.ArrayList;
//class Catalog
public class Catalog
{
//data member declaration
String catalog_name;
ArrayList<Item> list;
//parameterize construction
Catalog(String cs_Gift_Catalog)
{
//assign the list
list=new ArrayList<>();
//assign the catalog name
catalog_name=cs_Gift_Catalog;
}
//method to get the name of the catalog
String getName()
{
//return statement
return catalog_name;
}
//method to return the size of the list
int size()
{
//return statement
return list.size();
}
//method to get the item from the list
Item get(int i)
{
//return statement
return list.get(i);
}
//method to add the item into the list
void add(Item item)
{
//add item into the list
list.add(item);
}
}
The screenshot of the source code is given below: