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, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 22.06.2019 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 23.06.2019 17:10
Ac++an of of pi. in , pi is by : pi = 4 – 4/3 + 4/5 – 4/7 + 4/9 - 4/11 + 4/13 - 4/15 + 4/17 . ., to pi (9 ). , if 5 to pi,be as : pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 = 4 – 1. + 0.8 - 0. + 0. = 3.. atoofbe to pi?
Answers: 2
question
Computers and Technology, 23.06.2019 17:30
When making changes to optimize part of a processor, it is often the case that speeding up one type of instruction comes at the cost of slowing down something else. for example, if we put in a complicated fast floating-point unit, that takes space, and something might have to be moved farther away from the middle to accommodate it, adding an extra cycle in delay to reach that unit. the basic amdahl's law equation does not take into account this trade-off. a. if the new fast floating-point unit speeds up floating-point operations by, on average, 2ă—, and floating-point operations take 20% of the original program's execution time, what is the overall speedup (ignoring the penalty to any other instructions)? b. now assume that speeding up the floating-point unit slowed down data cache accesses, resulting in a 1.5ă— slowdown (or 2/3 speedup). data cache accesses consume 10% of the execution time. what is the overall speedup now? c. after implementing the new floating-point operations, what percentage of execution time is spent on floating-point operations? what percentage is spent on data cache accesses?
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
question
Health, 02.03.2021 09:00
question
Mathematics, 02.03.2021 09:00
question
History, 02.03.2021 09:00
question
English, 02.03.2021 09:00
Questions on the website: 13722367