1

Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following...

Question

Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following...

Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following attributes: a number of quarters, a number of dims, a number of nickels, and a number of pennies. Include a constructor (accept 4 numbers that represent the number of coins for each coin type), mutator and accessot methods, and method tostring. The tostring method should return a string in the following format: Total Value: $5.50 10 quarters, 20 dimes, 19 nickels, and 5 pennies Also code the following methods: public double totalAmount(, which returns the mount of money in dollar notation with two significant digits after the decimal point. Write a client class named CoinsTester.java to test all the methods in your Coins.java
Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following attributes: a number of quarters, a number of dims, a number of nickels, and a number of pennies. Include a constructor (accept 4 numbers that represent the number of coins for each coin type), mutator and accessot methods, and method tostring. The tostring method should return a string in the following format: Total Value: $5.50 10 quarters, 20 dimes, 19 nickels, and 5 pennies Also code the following methods: public double totalAmount(, which returns the mount of money in dollar notation with two significant digits after the decimal point. Write a client class named CoinsTester.java to test all the methods in your Coins.java

Answers


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

Coins.java
-=-----

public class Coins {
private int numQuarters;
private int numDimes;
private int numNickels;
private int numPennies;

public Coins()
{
}

public Coins(int quarters, int dimes, int nickels, int pennies)
{
numQuarters = quarters;
numDimes = dimes;
numNickels = nickels;
numPennies = pennies;
}


public int getNumQuarters() {
return numQuarters;
}

public void setNumQuarters(int numQuarters) {
this.numQuarters = numQuarters;
}

public int getNumDimes() {
return numDimes;
}

public void setNumDimes(int numDimes) {
this.numDimes = numDimes;
}

public int getNumNickels() {
return numNickels;
}

public void setNumNickels(int numNickels) {
this.numNickels = numNickels;
}

public int getNumPennies() {
return numPennies;
}

public void setNumPennies(int numPennies) {
this.numPennies = numPennies;
}

public double totalAmount()
{
double total = numQuarters * 25 + numDimes * 10 + numNickels * 5 + numPennies; //total no. of pennies
return total/100; //dollar cents
}


public String toString()
{
return String.format("Total Value:$%.2f \t %d quarters, %d dimes, %d nickels, %d pennies",
totalAmount(), numQuarters, numDimes, numNickels, numPennies);
}

}

CoinsTester.java
--------

public class CoinsTester {
public static void main(String[] args) {
Coins c = new Coins(10, 20, 19, 5);
System.out.println(c.toString());
}
}


output
=======
Total Value:$5.50 10 quarters, 20 dimes, 19 nickels, 5 pennies


Similar Solved Questions

1 answers
Okay i want to check and see if my answers are corrects before i submit my stuff
okay i want to check and see if my answers are corrects before i submit my stuff. can someone help ? i think i know the answers but the questions are: 1. The cotton gin changed agriculture in the South by (1 point) A. simplifying the planting process. B. making cotton the dominant crop. C. combini...
1 answers
Prime factorization of 980
prime factorization of 980...
1 answers
0 The state test scores for 12 randomly selected high school seniors are shown on the...
0 The state test scores for 12 randomly selected high school seniors are shown on the right Complete parts (a) through (c) below. Assume the population is normally distributed 1420 697 721 622 1225 722 745 1445 984 834 542 943 (a) Find the sample mean. (Round to one decimal place as needed.) (b) Fin...
1 answers
Present Value of Bonds Payable; Premium Moss Co. issued $440,000 of four-year, 13% bonds, with interest...
Present Value of Bonds Payable; Premium Moss Co. issued $440,000 of four-year, 13% bonds, with interest payable semiannually, at a market (effective) interest rate of 11%. Determine the present value of the bonds payable, using the present value tables in Exhibit 5 and Exhibit 7. Round to the neares...
1 answers
Patient complain about discomfort and unsightliness of varicose veins. Express concern about potential problems with treatment....
Patient complain about discomfort and unsightliness of varicose veins. Express concern about potential problems with treatment. What are her options?...
1 answers
Using 74F163 synchronous binary counter 74HC112 dual J-K Flip- Flop, draw MOD32 counter (either using IC's...
Using 74F163 synchronous binary counter 74HC112 dual J-K Flip- Flop, draw MOD32 counter (either using IC's pinout or as a block diagram). Use other ICs if necessary....
1 answers
If the force moving an object point's at least partially in the opposite direction of the object's motion, the work is considered to be what
If the force moving an object point's at least partially in the opposite direction of the object's motion, the work is considered to be what...
1 answers
Based on the following information, what is the variance? State of Economy Probability of State of...
Based on the following information, what is the variance? State of Economy Probability of State of Economy Rate of Return if State Occurs Recession 0.29 − 9.70% Normal 0.40 11.20% Boom 0.31 22.20% A) 0.12536 B) 0.02357 C) 0.01572 D) 0.03143 E) 0.07840...
1 answers
The phase diagram for the iron-carbon Fe-C system is shown below. use it to answer the...
The phase diagram for the iron-carbon Fe-C system is shown below. use it to answer the following questions a) How many different solid allotropes (phases) does pure iron have? b) what is the maximum carbon solubility of carbon in austentite? c) what is the maximum carbon solubility of carbon in fer...
1 answers
(b) (5 points) Using CLT, approximate the probability that P(X = 18). (c) (5 points) Calculate...
(b) (5 points) Using CLT, approximate the probability that P(X = 18). (c) (5 points) Calculate P(X = 18) exactly and compare to part(b). 8. (15 points) Let X~Binomial(30,0.6). (a) (5 points) Using the Central Limit Theorem (CLT), approximate the probability that P(X > 20)....
1 answers
How do i find the amount of moles of H2O in a hydrate
how do i find the amount of moles of H2O in a hydrate?...
1 answers
An average person can produce considerable power output for short periods of time. However, over an...
An average person can produce considerable power output for short periods of time. However, over an entire 8-hour workday, a person might be able to average 1/10 hp output of physical power. If energy is valued at $0.12/kWh (about the average cost of electricity from a public utility), what is the m...
1 answers
Using only the 68-95-99.7 rule answer the following question. Let the variable Z be a z-score...
Using only the 68-95-99.7 rule answer the following question. Let the variable Z be a z-score of a normal distribution. Calculate P(Z ≤ 3).   Draw a picture of the situation first. Shade the area that corresponds to the desired proportion being sought. Please explain how you would use t...
1 answers
Agrobacterium tumefaciens uses the Ti plasmid to create galls to provide a nutrient rich environment for...
Agrobacterium tumefaciens uses the Ti plasmid to create galls to provide a nutrient rich environment for this species. Discuss how this process is used by companies like Bayer to create genetically modified corn plants that can produce a toxin that kills corn borer worms.....
1 answers
What is difference between the polymer crystals grown from solution and polymer melt?
What is difference between the polymer crystals grown from solution and polymer melt?...
1 answers
At a certain temperature, the K_p, for the decomposition of H_2S is 0.704 H_2S(g) reversible H_2(g)...
At a certain temperature, the K_p, for the decomposition of H_2S is 0.704 H_2S(g) reversible H_2(g) + S(g) Initially, only H_2S is present at a pressure of 0.163 atm m a closed container What is the total pressure in the container at equilibrium?...
1 answers
The following table lists some enthalpy of formation values for selected substances. Substance ΔfH∘ΔfH∘ (kJ mol−1)(kJ...
The following table lists some enthalpy of formation values for selected substances. Substance ΔfH∘ΔfH∘ (kJ mol−1)(kJ mol−1) CO2(g)CO2(g) −393.5−393.5 Ca(OH)2(s)Ca(OH)2(s) −986.1−986.1 H2O(l)H2O(l) −285.8−285.8 CaCO3(...
1 answers
Please do a-d! thank you!! Homework: Homework #2 (Chapter 7 and 8) 4 Score: 0 of...
please do a-d! thank you!! Homework: Homework #2 (Chapter 7 and 8) 4 Score: 0 of 1 pt 35 of compen HW Score: 86.08%, 58.81 of 89 pts > Question Help Bus Econ 7.4.49 o long they would wait for pago d found the following Find the probabies that person would wait the following amounts A survey n...
1 answers
Really need questions 6 and 7 answered... 8-37Activity-based costing, batch-level varlance analysis. Rae Steven Publishing Company...
Really need questions 6 and 7 answered... 8-37Activity-based costing, batch-level varlance analysis. Rae Steven Publishing Company specializes in printing specialty textbooks for a small but profitable college market. Due to the high setup costs for each batch printed, Rae Steven holds the book ...

-- 0.011723--