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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:50, cheyennecarrillo14
Which is the best minecraft server? a. mineplex b. worldonecraft c. 9b9t d. 2b2t
Answers: 2
image
Computers and Technology, 23.06.2019 21:30, shadoris26
To move a file or folder in microsoft windows, you can click and hold down the left mouse button while moving your mouse pointer to the location you want the file or folder to be, which is also known as.
Answers: 3
image
Computers and Technology, 24.06.2019 01:30, kellygaytan
Suppose a cpu with a write-through, write-allocate cache achieves a cpi of 2. what are the read and write bandwidths (measured by bytes per cycle) between ram and the cache? (assume each miss generates a request for one block.)
Answers: 1
image
Computers and Technology, 24.06.2019 06:30, titalili0204
Adrawing that places all lines parallel to the z axis at an angle from the horizon is 99 ! a. an oblique drawing b. a perspective drawing c. an auxiliary view d. a one-point perspective drawing
Answers: 2
You know the right answer?
Complete the code for this PiggyBank class. I have also included a main program (TestPiggy) for you...

Questions in other subjects:

Konu
Mathematics, 09.12.2020 23:20
Konu
Mathematics, 09.12.2020 23:20
Konu
Mathematics, 09.12.2020 23:20