Question

In: Computer Science

Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...

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!

Solutions

Expert Solution

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:


Related Solutions

Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! Item Class: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public...
Convert this pseudo code program into sentences. import java.util.ArrayList; import java.util.Collections; class Bulgarian {    public static void main(String[] args)    {        max_cards=45;        arr->new ArraryList        col=1;        card=0;        left=max_cards;        do{            col->random number            row->new ArrayList;            for i=0 to i<col            {                card++                add card into row            }   ...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public static void main(String[] args) {        System.out.println("This program will ask the user for three sets of two numbers and will calculate the average of each set.");        Scanner input = new Scanner(System.in);        int n1, n2;        System.out.print("Please enter the first number: ");        n1 = input.nextInt();        System.out.print("Please enter the second number: ");        n2 =...
Please convert this code written in Python to Java: import string import random #function to add...
Please convert this code written in Python to Java: import string import random #function to add letters def add_letters(number,phrase):    #variable to store encoded word    encode = ""       #for each letter in phrase    for s in phrase:        #adding each letter to encode        encode = encode + s        for i in range(number):            #adding specified number of random letters adding to encode            encode = encode +...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
Can you please rewrite this Java code so it can be better understood. import java.util.HashMap; import...
Can you please rewrite this Java code so it can be better understood. import java.util.HashMap; import java.util.Scanner; import java.util.Map.Entry; public class Shopping_cart {       static Scanner s= new Scanner (System.in);    //   declare hashmap in which key is dates as per mentioned and Values class as value which consists all the record of cases    static HashMap<String,Item> map= new HashMap<>();    public static void main(String[] args) {        // TODO Auto-generated method stub        getupdates();    }...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution {...
Convert this java code from hashmap into arraylist. import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap labs = new HashMap(); while (true) { System.out.println("Choose operation : "); System.out.println("1. Create a Lab"); System.out.println("2. Modify a Lab"); System.out.println("3. Delete a Lab"); System.out.println("4. Assign a pc to a Lab"); System.out.println("5. Remove a pc from a Lab"); System.out.println("6. Quit"); int choice = sc.nextInt(); String name=sc.nextLine(); switch (choice) { case 1:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT