Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this program tomorrow, i need help pleaseeeeeee. Please if you can follow

ID: 3687773 • Letter: I

Question

I need this program tomorrow, i need help pleaseeeeeee.

Please if you can follow the instructions. Please



ArrayList


This lab will help you practice using ArrayList methods (such as get, set, add, and remove) using an Integer ArrayList named iArray. Each time we test a method you have defined, we will empty (clear) the previous values from the ArrayList and repopulate the ArrayList with random Integer values. Open the ArrayListTest file and examine the following inside:

A constant defined named TEST_SIZE: each time we repopulate the ArrayList, we will populate it with 12 values, therefore this constant was created.

A static ArrayList named iArray: because we are in an application class, no objects will be created from this class. Therefore any data fields created are linked to the class itself, which is why this defined as static. This ArrayList will be used throughout the program.

printArray method: this method accepts a String parameter. In the main method, each time we repopulate the ArrayList, we will call this method to print a message indicating

what method we are about to test and to print all of the values in the ArrayList. Because this method is not modifying the ArrayList, an enhanced for loop (for each loop) has been used for printing.

populateArray method: this method takes 2 integer parameters. Inside of the method the ArrayList is cleared so that all previous Integers inside of iArray are deleted. A for loop executes TEST_SIZE amount of times, populating the ArrayList with new random numbers starting at offset (inclusive) and going through offset + range (exclusive). Because the ArrayList is being modified (values are being added), a traditional for loop must be used.

Next there are several methods that you must define. Each method is doing something with the contents of iArray. Use the comments above each method to

complete the method definition. Sample values as well as hints will be shown above each method.

The main method is completed for you. Inside of the main method, each time a method is tested, the populateArray method is called to put random numbers into iArray, the printArray method is called to print the contents of iArray, the method being tested is called, and then printArray is called again to show the contents of the iArray after the tested method has executed.




Cookies sales


An organization raises money by selling boxes of cookies. A cookie order specifies the variety of cookie and the number of boxes ordered (see CookieOrder.java).
Create the MasterOrder class to maintain a list of cookies to be purchased.

MasterOrder.java should include the following:
1 data field representing an ArrayList of Cookie Orders

1 constructor to instantiate the data field. Note the constructor does not need any arguments, as an ArrayList can be initialized on its own, with no size or previous data to reference required.

public void addOrder(CookieOrder theOrder): adds the parameter to the MasterOrder

public int getTotalBoxes(): computes and returns the sum of the number of boxes of all cookie orders. If there are no orders in the master order, return 0. Requirement: you must use the enhanced for loop in this method.

public int removeVariety(String cookieVar): updates the master order by removing all of the cookie orders in which the variety of cookie matches the parameter cookieVar. The

master order may contain zero or more cookie orders with the same variety as cookieVar. The method returns the total number of boxes removed from the master order.

Use the CookieSales.java driver to test your code.


import java.util.ArrayList;

Explanation / Answer

public class CookieOrder
{
private String v ;
private int b ;
  
public CookieOrder ( String variety ,int numBoxes )
{
v = variety ;
b = numBoxes ;
}
public String toString ( )
{
return v +" : " +b ;
}
  
public int getNumboxes ( )
{
return b ;
}
public String getVariety ( )
{
return v ;
}
}

----------------------------------------------------

public class CookiesSales
{
private String company ;
private MasterOrder masterOrder ;
  
public CookiesSales ( String c ,MasterOrder mo )
{
company = c ;
masterOrder = mo ;
}
public String toString ( )
{
return company + masterOrder ;
}
public MasterOrder getMasterOrder ( )
{
return masterOrder ;
}
public String getCompany ( )
{
return company ;
}

}
----------------------------------------------------

import java.util.List ;
import java.util.ArrayList ;

public class MasterOrder
{
private ArrayList< CookieOrder > orders ;
  
public MasterOrder ( )
{
orders = new ArrayList< CookieOrder > ( ) ;
}
public void addOrder ( CookieOrder theOrder )
{
orders.add ( theOrder ) ;
}
public int getTotalBoxes ( )
{
int sum = 0 ;
for ( int i = 0 ;i <orders.size ( ) ;i++ )
{
CookieOrder c = orders.get ( i ) ;
sum =sum +c.getNumboxes ( ) ;
}
return sum ;
}
public int removeVariety ( String cookieVar )
{
int sum = 0 ;
int x = 0 ;
for ( int i = orders.size ( ) - 1 ;i >= 0 ;i-- )
{
CookieOrder c =orders.get ( i ) ;
if ( c.getVariety ( ).equals ( cookieVar ) )
{
x = c.getNumboxes ( ) ;
sum =sum + x ;
orders.remove ( i ) ;
}
}
return sum ;
}
public String toString ( )
{
String s ="" ;
s =s +orders ;
return s ;
}
}

-----------------------------------------------------

import java.util.ArrayList ;

public class CookieTester
{
public static void main ( String [] args )
{
CookieOrder a =new CookieOrder ( " Chocolate Chip " ,1 ) ;
CookieOrder b =new CookieOrder ( " Shortbread " ,5 ) ;
CookieOrder c =new CookieOrder ( " Macaroon " ,2 ) ;
CookieOrder d =new CookieOrder ( " Chocolate Chip " ,3 ) ;
  
a.getVariety ( ) ;
b.getVariety ( ) ;
c.getVariety ( ) ;
d.getVariety ( ) ;

a.getNumboxes ( ) ;
b.getNumboxes ( ) ;
   c.getNumboxes ( ) ;
d.getNumboxes ( ) ;
  
ArrayList< CookieOrder > x = new ArrayList< CookieOrder > ( ) ;
x.add ( a ) ;
x.add ( b ) ;
x.add ( c ) ;
x.add ( d ) ;
MasterOrder mm = new MasterOrder ( ) ;
mm.addOrder ( a ) ;
mm.addOrder ( b ) ;
mm.addOrder ( c ) ;
mm.addOrder ( d ) ;
CookiesSales dd =new CookiesSales ( " Peter " ,mm ) ;
System.out.println ( dd.getMasterOrder ( ) ) ;
System.out.println ( dd.getCompany ( ) ) ;
MasterOrder mmm = new MasterOrder ( ) ;
mmm.addOrder ( a ) ;
mmm.addOrder ( b ) ;
mmm.addOrder ( c ) ;
mmm.addOrder ( d ) ;
System.out.println ( mm.getTotalBoxes ( ) ) ;
System.out.println ( mmm.removeVariety ( " Chocolate Chip " ) ) ;
CookiesSales ddd =new CookiesSales ( " Agrim " ,mmm ) ;
System.out.println ( ddd.getMasterOrder ( ) ) ;
System.out.println ( ddd.getCompany ( ) ) ;
ArrayList< CookieOrder > y =new ArrayList< CookieOrder > ( ) ;
y.add ( b ) ;
y.add ( a ) ;
y.add ( d ) ;
y.add ( c ) ;
ArrayList< CookiesSales > ad =new ArrayList< CookiesSales > ( ) ;
// ad.add ( dd ) ;
// ad.add ( ddd ) ;
WeeklyOrders ww = new WeeklyOrders ( ad ) ;
ww.addDistribution ( dd ) ;
ww.addDistribution ( ddd ) ;
System.out.println ( ww.toString ( ) ) ;
System.out.println ( ww.totalNumOfBoxesOrdered ( " Peter " ) ) ;
System.out.println ( ww.totalNumOfBoxesOrdered ( ) ) ;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote