Question: public class Fundraiser { private String name; private AuctionItem [ ] items; public Fundraiser ( ) { this.name = Default Fundraiser; this.items = new AuctionItem
public class Fundraiser
private String name;
private AuctionItem items;
public Fundraiser
this.name "Default Fundraiser";
this.items new AuctionItem;
public FundraiserString name, AuctionItem items
this.name name;
this.items items.clone;
public String getName
return name;
public AuctionItem getItems
return items;
public String toString
if items null items.length
return "Fundraiser without any items";
String s name
auction items:
;
for int i ; i items.length; i
s itemsitoString;
return s;
Purpose: get the money raised, which will be the
sum of all auction items that are sold
Parameters: none
Returns: int the total money this fundraiser raises
public int moneyRaised
int totalMoney ;
if items null
for AuctionItem item : items
if item null
totalMoney item.getPrice;
return totalMoney;
Purpose: get the total money spent at this fundraiser
by those with the given name
Parameters: String name the name to search for
Returns: int the total money spent by name
public int moneySpentString name
int totalMoneySpent ;
if items null && name null
for AuctionItem item : items
if item null && name.equalsIgnoreCaseitemgetBidderName
totalMoneySpent item.getHighestBid;
return totalMoneySpent;
Purpose: get the most expensive auction item at this fundraiser
Parameters: none
Returns: AuctionItem the most expensive item
Preconditions: items is not null, and items.length
public AuctionItem mostExpensive
if items null items.length
return null;
AuctionItem mostExpensive null;
for AuctionItem item : items
if item null
if mostExpensive null item.getHighestBid mostExpensive.getHighestBid
mostExpensive item;
return mostExpensive;
Purpose: adds the new item to the items sold at this fundraiser
Parameters: AuctionItem newItem the item to add to the fundraiser
Returns: void nothing
public void addToFundraiserAuctionItem newItem
TODO: implement this
if items null
items new AuctionItem;
items newItem;
else
AuctionItem newArray new AuctionItemitemslength ;
for int i ; i items.length; i
newArrayi itemsi;
newArrayitemslength newItem;
items newArray;
import java.util.Arrays;
public class ATester
private static int testPassCount ;
private static int testCount ;
private static double THRESHOLD ; allowable margin of error for floating point results
public static void mainString args
Tests for methods inside Fundraiser.java
testConstructor;
testMoneyRaised;
testMoneySpent;
testMostExpensive;
testAddToFundraiser;
Tests for methods inside AExercises.java
testTotalMoneyRaised;
testTotalSpent;
testMostExpensiveItems;
testAverageOfMostExpensive;
System.out.println;
System.out.printlnPASSED testPassCounttestCount TESTS";
public static void testConstructor
System.out.println
Testing Fundraiser Constructor";
String nameResult;
AuctionItem itemsResult;
Testing default constructor
the constructor with arguments
Fundraiser f new Fundraiser;
nameResult fgetName;
displayResultsnameResultnull, "empty constructor name";
itemsResult fgetItems;
displayResultsitemsResultnull, "empty constructor items";
Setting up AuctionItems for Fundraiser objects
AuctionItem a new AuctionItemcolorful seashell", "Sam";
AuctionItem a new AuctionItemautographed photo", "Ali";
AuctionItem a new AuctionItemevent ticket", "Ali";
AuctionItem arra;
AuctionItem arra a a;
Testing second constructor with f and f
Fundraiser f new FundraiserFamily Fundraiser", arr;
Fundraiser f new FundraiserCommunity Fundraiser", arr;
String expectedName;
AuctionItem expectedItems;
nameResult fgetName;
itemsResult fgetItems;
expectedName new StringFamily Fundraiser";
expectedItems arr;
displayResultsexpectedNameequalsnameResultf constructor name";
displayResultsArraysequalsitemsResultexpectedItemsf constructor items";
nameResult fgetName;
itemsResult fgetItems;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
