5. Explain the difference between a traditional tests and JUnit tests. Why would you prefer one of these test types over the other? Give an example.

9. What is an ArrayList object? How does is it similar to and how does it differ from a traditional array.

13. What is the output? Explain how you obtain this answer by hand, not using a computer.
for(int i = 1; i <= 26; i *= 2) {
   System.out.print(alphabet.charAt(i - 1));

14. What is the output? Explain how you obtain this answer by hand, not using a computer.
int n = 500;
int count = 0;
while (n > 1) {
    if (n % 2 == 0) {
       n /= 3;
    else {
       n /= 2;

15. A Java Swing application contains this paintComponent method for a panel. Sketch what is drawn by this method.
public void paintComponent(Graphics g) {
    g.fillRect(100, 100, 200, 100);
    g.fillRect(300, 200, 200, 100);
g.fillRect(500, 100, 200, 100);

Part B: Find errors and test a class.
For this problem, submit an Eclipse project file named CoinStoreYourLastName with your corrected source code for the classes Coin and Main1, and the new class Main2 that you write in Problem 3.

1. 15 points. Find the errors in the Coin and Main1 classes. Submit a list of all the errors and their corrections in a Word text file.

2. For the Coin class, write getter and setter methods for the _price instance variable. Include these methods in your project file.

3. Write a second class named Main2 with static methods main, getOnSaleCount, setTotalPrice methods:

a. The main method should:
read comma delimited data lines from the input file coins.txt,
use the String method split to split the line into fields,
use the values of the fields to create a Coin object,
insert the Coin object into an ArrayList collection defined by
    ArrayList<Coin> col = new ArrayList<Coin>( );

b. The getOnSaleCount method should have this header:

private static int getOnSaleCount(
    ArrayListCoin<Coin> myCol)

It should use a for loop to look at all of the Coin objects in the collection and count the number of coins that are on sale and return that count. To test this method in Main2, here is how you can set the coins with indices 2 and 4 in the collection to be on sale:

Include a statement or statement that tests the getOnSaleCount method in Main2.

c. The getTotalPrice method should have this header:
private static double getTotalPrice(
    ArrayListCoin<Coin> myCol)
It should use a loop to find the total of the prices of all Coin objects in the ArrayList collection and return that total. Include a statement or statement that tests the getOnSaleCount method in Main2.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

package coinstore;
public class Coin {private double _denomination;
private int _year;
private char _mintLocation;
private String _condition;
private double _price;
private boolean _onSale;

// Constructor
public Coin(double theDenom, int theYear, char theMint,
    String theCondition, double thePrice) {

    // Face value of the coin, for example
    // Quarter = 0.25, Dime = 0.10.
    _denomination = theDenom;

    // Year that the coin was minted.
    _year = theYear;

    // Location coin was minted. Values are
    // 'D'=Denver, 'S'=San Francisco,
    // 'P'=Philadelphia, 'C'=Carson City.
    _mintLocation = theMint;

    _price = thePrice;

    // Condition of the coin. Values are
    // "XF"=Extra Fine, "VF"=Very Fine, "F"=Fine,
    // "VG"=Very Good, "G"=Good, "P"=Poor.
    _condition = theCondition;

    // Is the coin on sale?
    _onSale = false;

public boolean isOnSale() {
    return _onSale;

public void setOnSale(boolean onSale) {
    _onSale = onSale...

By purchasing this solution you'll be able to access the following files: and Solution.pdf.

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats