I have the following code: public class Money { private int dollar; private int cent; final static int MIN_CENT_VALUE=0; final static int MAX_CENT_VALUE=99; public Money(){ this.dollar=0; this.cent=0; } public Money(int dollar,int cent){ this.dollar=dollar; if(cent>=MIN_CENT_VALUE&¢<=MAX_CENT_VALUE){ this.cent=cent; }else{ cent=0; } } public int getDollar(){ return this.dollar; } public void setDollar(int dol){ this.dollar=dol; } public int getCent(){ return this.cent; } public void setCent(int c){ if(c>=MIN_CENT_VALUE&&c<=MAX_CENT_VALUE){ this.cent=c; } } public Money add(Money otherMoney) { Money m = new Money(); m.dollar=dollar + otherMoney.dollar; m.cent=cent + otherMoney.cent; if(m.cent >= 100) { m.dollar++; m.cent -= 100; } return m; } public Money subtract(Money otherMoney) { Money m = new Money(); m.dollar=dollar - otherMoney.dollar; m.cent=cent -otherMoney.cent; if(m.dollar<0||m.cent<0){ return null; } return m; } public boolean equals(Money otherMoney){ return this==otherMoney; } public int compareTo(Money otherMoney){ if(this.dollar
I have the following code:
public class Money {
private int dollar;
private int cent;
final static int MIN_CENT_VALUE=0;
final static int MAX_CENT_VALUE=99;
public Money(){
this.dollar=0;
this.cent=0;
}
public Money(int dollar,int cent){
this.dollar=dollar;
if(cent>=MIN_CENT_VALUE&¢<=MAX_CENT_VALUE){
this.cent=cent;
}else{
cent=0;
}
}
public int getDollar(){
return this.dollar;
}
public void setDollar(int dol){
this.dollar=dol;
}
public int getCent(){
return this.cent;
}
public void setCent(int c){
if(c>=MIN_CENT_VALUE&&c<=MAX_CENT_VALUE){
this.cent=c;
}
}
public Money add(Money otherMoney)
{
Money m = new Money();
m.dollar=dollar + otherMoney.dollar;
m.cent=cent + otherMoney.cent;
if(m.cent >= 100)
{
m.dollar++;
m.cent -= 100;
}
return m;
}
public Money subtract(Money otherMoney)
{
Money m = new Money();
m.dollar=dollar - otherMoney.dollar;
m.cent=cent -otherMoney.cent;
if(m.dollar<0||m.cent<0){
return null;
}
return m;
}
public boolean equals(Money otherMoney){
return this==otherMoney;
}
public int compareTo(Money otherMoney){
if(this.dollar<otherMoney.dollar){
return 1;
}else if(this.dollar==otherMoney.dollar){
return 0;
}else{
return -1;
}
}
public String toString(){
return "$"+this.dollar+"."+ this.cent;
}
public static Money max(Money[] m)
{
int max = m[0].dollar;
int index = 0;
for(int i=0;i<m.length;i++)
{
if(max < m[i].dollar)
{
max = m[i].dollar;
index = i;
}
}
return m[index];
}
public static void selectionSort(Money arr[])
{
int n = arr.length;
for (int i = 0; i < n-1; i++)
{
int min = i;
for (int j = i+1; j < n; j++)
if (arr[j].dollar < arr[min].dollar)
min = j;
// Swap the found minimum element with the first element
Money temp = new Money();
temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
}
public static void printList(Money[] m, int i) //This method takes an array of object as parameter
{
for(Money mm : m)
System.out.println(mm);
}
}
_______________________________________________
I am running into a few issues, formatting and then my compareTo method result
![Your output
$5.45 + $10.95 is $16.40
$5.45 $10.95 is null
$10.95
$5.45 is $5.50
equals method result: false
compareTo method result: 1
Unsorted list
$4.804
$4.90€
$17.564
$8.884
$22.144
$14.994
$22.84
$16.804
$17.534
$14.38
$24.94
$16.84
$6.494
$15.704
$9.50
The Max is $24.9
Sorted list
$4.804
$4.904
$6.494
$8.884
$9.504
$14.994
$14.384
$15.704
$16.84
$16.80
$17.534
$17.564
$22.84
$22.144
$24.9
$5.45 + $10.95 is $16.40
$5.45 $10.95 is null
$10.95
$5.45 is $5.50
equals method result: false
compareTo method result: -550
Unsorted list
Expected output $4.80 $4.90 $17.56 $8.88 $22.14 $14.99 $22.08 $16.80 $17.53 $14.
$24.09 $16.08 $6.49 $15.70 $9.50
The Max is $24.09
Sorted list
$4.80 $4.90 $6.49 $8.88 $9.50 $14.38 $14.99 $15.70 $16.08 $16.80
$17.53 $17.56 $22.08 $22.14 $24.09](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe4e826cb-c133-47e8-aeaa-858e7b3a09da%2Fb6fa30a1-d11b-47cf-8ca4-ecc087a24209%2F12qt0blo_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 6 steps with 7 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)