subject

Complete the code for this PiggyBank class. I have also included a main program (TestPiggy) for you to use to test your class. When I grade your PiggyBank class, I will use this exact same main program so be sure your class compiles and runs with it. I have also attached a screenshot of what your output should look like. Note the way the numeric values are formatted; yours should be the same. public class PiggyBank implements Measurable, Comparable {
private int numNickels, numPennies, numDimes, numQuarters;
// to do; complete the constructor
public PiggyBank() {
}
// to do; complete the constructor
public PiggyBank(int quarters, int dimes, int nickels, int pennies){
}
// to do; it just returns 0; code it so that it returns the monetary
// amount of the piggy bank
public double getMeasure(){
return 0.0;
}
// to do; it just returns 0; code it so that it correctly compares
public int compareTo(Object other){
return 0;
}
// to do; it just returns a blank string right now
public String toString(){
return "";
}
}
public class Data{
public static double average(Measurable[] objects){
double sum = 0;
for (Measurable obj : objects){
sum = sum + obj. getMeasure();
}
if (objects. length > 0){return sum / objects. length;}
else {return 0;}
}
}
import java. text. NumberFormat;
import java. util. Arrays;
public class TestPiggy {
public static void main(String[] args) {
PiggyBank [] banks = new PiggyBank[10];
banks[0] = new PiggyBank(5, 10, 19, 32);
banks[1] = new PiggyBank(6, 0, 2, 1);
banks[2] = new PiggyBank(0, 20, 15, 3);
banks[3] = new PiggyBank(1, 3, 99, 591);
banks[4] = new PiggyBank(0, 0, 10, 0);
banks[5] = new PiggyBank(15, 3, 0, 25);
banks[6] = new PiggyBank();
banks[7] = new PiggyBank(11, 3, 0, 1);
banks[8] = new PiggyBank(0, 0, 1, 5);
banks[9] = new PiggyBank(8, 10, 20, 100);
NumberFormat formatter = NumberFormat. getCurrencyInstance();
String moneyString = formatter. format(Data. average(banks));
System. out. println ("The average of all the piggy banks is " + moneyString);
Arrays. sort(banks);
System. out. println ("The piggy banks in sorted order, smallest to largest, are:");
for (int i = 0; i < 10; i++) System. out. println (banks[i]);
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:00
Freya realizes she does not have enough in her bank account to use the debit card. she decides to use a credit card instead. which questions should freya answer before using a credit card? check all that apply. can i pay at least the minimum payment each month? can i make payments on time and avoid late fees? will i have to take out a loan? how much in finance charges can i afford to pay? should i talk to a consumer credit counseling service?
Answers: 1
question
Computers and Technology, 24.06.2019 07:30
Jason is working on a microsoft excel worksheet and he wants to create a print preview shortcut. his teacher asks him to access the customization option to create the new shortcut. which two tabs should jason select to place the print preview shortcut on the worksheet toolbar? a. new tab (custom) and new group (custom) b. new file tab (custom) and new tab (custom) c. new custom group and new command d. new custom tab and new command
Answers: 2
question
Computers and Technology, 24.06.2019 08:30
Formatting rows and columns is similar to cell formatting. in an openoffice calc spreadsheet, you can format data entered into rows and columns with the of the rows and columns options. you can insert rows and columns into, or delete rows and columns from, a spreadsheet. use the insert or delete rows and columns option on the insert tab. alternatively, select the row or column where you want new rows or columns to appear, right-click, and select insert only row or only column options. you can hide or show rows and columns in a spreadsheet. use the hide or show option on the format tab. for example, to hide a row, first select the row, then choose the insert tab, then select the row option, and then select hide. alternatively, you can select the row or columns, right-click, and select the hide or show option. you can adjust the height of rows and width of columns. select row and then select the height option on the format tab. similarly, select column, then select the width option on the format tab. alternatively, you can hold the mouse on the row and column divider, and drag the double arrow to the position. you can also use the autofit option on the table tab to resize rows and columns.
Answers: 1
question
Computers and Technology, 24.06.2019 16:30
Pressing the backspace key deletes the text to the of the insertion point. the left or the right?
Answers: 1
You know the right answer?
Complete the code for this PiggyBank class. I have also included a main program (TestPiggy) for you...
Questions
question
History, 19.09.2019 06:00