Question

In: Computer Science

I have to complete all //to do comments for the following code: /** * A ShoppingBasket...

I have to complete all //to do comments for the following code:

/**
* A ShoppingBasket holds zero or more Products and can provide information
* about the Products. One can add Products to a ShoppingBasket during its
* lifetime, reset the ShoppingBasket, create a copy which contains Products of
* at least a certain value, and make various queries to the ShoppingBasket.
* (Thus, the number of Products that will be stored by a ShoppingBasket object
* is not yet known when the new object is created, and it may grow and shrink
* over the lifetime of a ShoppingBasket object.)
*
* @author Carsten Fuhs
*/
public class ShoppingBasket {
// TO DO instance variables
/* Constructors */
/**
* Constructs a new ShoppingBasket without any Products.
*/
public ShoppingBasket() {
// TO DO
}
/**
* Constructs a new ShoppingBasket containing the non-null Products in
* products. The products array may be modified by the caller afterwards
* without affecting this ShoppingBasket, and it will not be modified by
* this constructor.
*
* @param products must not be null; non-null elements are added to the
* constructed ShoppingBasket
*/
public ShoppingBasket(Product[] products) {
// TO DO
}
/* Modifiers */
/**
* Adds a Product e to this ShoppingBasket if e is not null; does not
* modify this ShoppingBasket otherwise. Returns true if e is not null,
* false otherwise.
*
* @param e an product to be added to this ShoppingBasket
* @return true if e is not null, false otherwise
*/
public boolean add(Product e) {
// TO DO
return false;
}
/**
* Adds all non-null Products in products to this ShoppingBasket.
*
* @param products contains the Product objects to be added to
* this ShoppingBasket; must not be null (but may contain null)
* @return true if at least one element of products is non-null;
* false otherwise
*/
public boolean addAll(Product[] products) {
// TO DO
return false;
}
/**
* Removes certain Products from this ShoppingBasket. Exactly those
* Products are kept whose price in pence is greater than or equal to the
* specified minimum price in pence.
*
* @param minProductPriceInPence the minimum price in pence for the
* Products that are kept
*/
public void keepOnlyProductsWith(long minProductPriceInPence) {
// TO DO
}
/* Accessors */
/**
* Returns the number of non-null Products in this ShoppingBasket.
*
* @return the number of non-null Products in this ShoppingBasket
*/

Solutions

Expert Solution

***Please upvote/thumbsup if you liked the answer***

N.B I do not have the description of the Product class so cannot run the code

Screenshot of the Java code:-

Java code to copy:-

public class ShoppingBasket {
    private int index = 0;
    private Product[] products;

    /* Constructors */
    /**
     * Constructs a new ShoppingBasket without any Products.
     */
    public ShoppingBasket() {
        //Initialising the instance variable to hold 100 products
        //but initially all positions are empty
        this.products = new Product[100];

    }
    /**
     * Constructs a new ShoppingBasket containing the non-null Products in
     * products. The products array may be modified by the caller afterwards
     * without affecting this ShoppingBasket, and it will not be modified by
     * this constructor.
     *
     * @param products must not be null; non-null elements are added to the
     * constructed ShoppingBasket
     */
    public ShoppingBasket(Product[] products) {

        for (Product e:products)
        {
            if(e != null) {
                this.products[index] = e;
                index++;
            }
        }
    }
    }
    /* Modifiers */
    /**
     * Adds a Product e to this ShoppingBasket if e is not null; does not
     * modify this ShoppingBasket otherwise. Returns true if e is not null,
     * false otherwise.
     *
     * @param e an product to be added to this ShoppingBasket
     * @return true if e is not null, false otherwise
     */
    public boolean add(Product e) {
        if (e != null)
        {
            products[index] = e;
            index++;
            return true;
        }
        return false;
    }
    /**
     * Adds all non-null Products in products to this ShoppingBasket.
     *
     * @param products contains the Product objects to be added to
     * this ShoppingBasket; must not be null (but may contain null)
     * @return true if at least one element of products is non-null;
     * false otherwise
     */
    public boolean addAll(Product[] products) {

        boolean flag = false;
        for (Product e:products) {
            {
                if (e != null)
                {
                    this.products[index] = e;
                    index++;
                    flag = true;
                }
            }
            }

        return flag;
    }
    /**
     * Removes certain Products from this ShoppingBasket. Exactly those
     * Products are kept whose price in pence is greater than or equal to the
     * specified minimum price in pence.
     *
     * @param minProductPriceInPence the minimum price in pence for the
     * Products that are kept
     */
    public void keepOnlyProductsWith(long minProductPriceInPence) {
        for (Product e:this.products) {
            {
                if (e.getProductPriceInPence() >= minProductPriceInPence)
                {
                    products[index] = e;
                    index++;
                    flag = true;
                }
            }
        }
    }
    /* Accessors */
    /**
     * Returns the number of non-null Products in this ShoppingBasket.
     *
     * @return the number of non-null Products in this ShoppingBasket
     */
    public Product[] getProducts() {
        return products;
    }
}

Related Solutions

I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Please do in java with code available for copy and with comments so I can follow...
Please do in java with code available for copy and with comments so I can follow along :)\ Develop a program that prints out the sum of each column of a two-dimensional array. The program defines method sumColumn() takes a two-dimensional array of integers and returns a single-dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and then calls method sumColumns()....
I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS ....
I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS . Add the following functions to the class arrayListType: Then, update the main function to test these new functions. removeAll - which removes ALL of the instances of a value in the list min - which returns the minimum value in the list max - which returns the maximum value in the list arrayListType.h : #ifndef H_arrayListType #define H_arrayListType class arrayListType { public: bool isEmpty()...
Can someone please complete the following code(Java). The stuff in comments are the things you need...
Can someone please complete the following code(Java). The stuff in comments are the things you need to look at and code that package mini2; import static mini2.State.*; /** * Utility class containing the key algorithms for moves in the * a yet-to-be-determined game. */ public class PearlUtil { private PearlUtil() { // disable instantiation } /**    * Replaces all PEARL states with EMPTY state between indices    * start and end, inclusive.    * @param states    * any...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
I have a countdown sequence i have to do for a code, when the result is...
I have a countdown sequence i have to do for a code, when the result is entered it starts to countdown, i tried imputting some codes but i am clueless ( javascript): /******************************************************************************* * Problem 3: create count-down number sequence strings * * A count-down sequence is a String made up of a descending list of numbers. * For example, the count-down sequence for the number 3 would be: * * "321" * * Write the countDownSequence function below, allowing...
complete this code for me, this is java question. // Some comments omitted for brevity import...
complete this code for me, this is java question. // Some comments omitted for brevity import java.util.*; /* * A class to demonstrate an ArrayList of Player objects */ public class ListOfPlayers { // an ArrayList of Player objects private ArrayList players; public ListOfPlayers() { // creates an empty ArrayList of Players players = new ArrayList<>(); } public void add3Players() { // adds 3 Player objects players.add(new Player("David", 10)); players.add(new Player("Susan", 5)); players.add(new Player("Jack", 25)); }    public void displayPlayers()...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a border to the header of the page (a) a simple type selector, and (b) the style property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the text of the h1 element by using (a) the first-child pseudo selector, and (b) the innerHTML property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the background-color of the section with id...
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT