Money.java:48: error: method add (Money) is already defined in class Money public Money add (Money otherMoney) { Money.java:75: error: cannot find symbol public Money max (ArrayList m) { symbol: class ArrayList location: class Money Money.java:85: error: cannot find symbol public void publicList (ArrayList m) { symbol: class ArrayList location: class Money TestMoney.java:12: error: cannot find symbol Money diffm1.subtract (m2) ; symbol: method subtract (Money) location: variable ml of type Money TestMoney.java:14: error: cannot find symbol diff = m2.subtract (m1); symbol: method subtract (Money) location: variable m2 of type Money TestMoney.java:24: warning: [cast] redundant cast to int list[i] = new Money ((int) (1+rnd.nextInt (30)), rnd.nextInt (100)); TestMoney.java:28: error: cannot find symbol Money.printList (list, 10); symbol: method printList (Money [], int) location: class Money TestMoney.java:30: error: non-static method max () cannot be referenced from a static co System.out.println("The Max is "+Money.max (list)); TestMoney.java:33: error: cannot find symbol Money.selectionSort (list); symbol: method selectionSort (Money []) location: class Money TestMoney.java:34: error: cannot find symbol Money.printList (list, 10); symbol: method printList (Money [], int) location: class Money 9 errors 1 warning

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have the following code:

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&&cent<=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){
      this.dollar+=otherMoney.dollar;
      this.cent+=otherMoney.cent;
      return this;
  }
  public Money add(Money otherMoney){
      this.dollar-=otherMoney.dollar;
      this.cent-=otherMoney.cent;
      if(this.dollar<0||this.cent<0){
          return null;
      }
      return this;
  }
  
  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 "Dollar is"+this.dollar+"and cents is"+this.cent;
  }
   public Money max(ArrayList<Money> m){
       Money res=m.get(0);
       for(int i=0;i<m.size();i++){
           if(res.dollar<m.get(i).dollar){
               res=m.get(i);
           }
       }
       return res;
   }
   
   public void publicList(ArrayList<Money>  m){
       for(int i=0;i<m.size();i++){
           System.out.print(m.get(i)+" ");
       }
   }
   
}

_________________________________________________

for use with this driver program, testMoney.java

import java.util.*;
public class TestMoney
{
public static void main(String[] args)
{
Random rnd = new Random(10);
Money m1 = new Money(5,45);
Money m2 = new Money(10,95);
m1.setCent(101);
Money sum = m1.add(m2);
System.out.println(m1+" + "+m2+" is "+sum);
Money diff = m1.subtract(m2);
System.out.println(m1+" - "+m2+" is "+diff);
diff = m2.subtract(m1);
System.out.println(m2+" - "+m1+" is "+diff);
System.out.println("equals method result: "+m1.equals(m2));
System.out.println("compareTo method result: "+m1.compareTo(m2));


Money[] list = new Money[15];
// Generate 15 random Money objects
for(int i=0;i<list.length;++i)
{
list[i] = new Money((int)(1+rnd.nextInt(30)),rnd.nextInt(100));
}
// print the list of Money objects, 10 per line
System.out.println("Unsorted list");
Money.printList(list,10);
// Find the largest Money object
System.out.println("The Max is "+Money.max(list));
// Sort and print
System.out.println("Sorted list");
Money.selectionSort(list);
Money.printList(list,10);
}
}

____________________________________________

but I keep getting these error messages:

The image depicts an error output from a Java compiler with a focus on a class named `Money`. Below is a detailed transcription of the errors and warnings as they would appear on an educational website.

---

## Java Compiler Errors and Warnings

### Compilation Output:

#### Errors:
1. **Money.java:48** - Method Error: 
   - **Issue:** `add(Money)` is already defined in the class `Money`.
   - **Code:** `public Money add(Money otherMoney)`

2. **Money.java:75** - Symbol Error:
   - **Issue:** Cannot find symbol `ArrayList`.
   - **Code:** `public Money max(ArrayList<Money> m)`

3. **Money.java:85** - Symbol Error:
   - **Issue:** Cannot find symbol `ArrayList`.
   - **Code:** `public void publicList(ArrayList<Money> m)`

4. **TestMoney.java:12** - Symbol Error:
   - **Issue:** Cannot find symbol method `subtract(Money)`.
   - **Code:** `Money diff = m1.subtract(m2);`

5. **TestMoney.java:14** - Symbol Error:
   - **Issue:** Cannot find symbol method `subtract(Money)`.
   - **Code:** `diff = m2.subtract(m1);`

6. **TestMoney.java:28** - Symbol Error:
   - **Issue:** Cannot find symbol method `printList(Money[], int)`.
   - **Code:** `Money.printList(list,10);`

7. **TestMoney.java:30** - Static Context Error:
   - **Issue:** Non-static method `max(<any>)` cannot be referenced from a static context.
   - **Code:** `System.out.println("The Max is "+Money.max(list));`

8. **TestMoney.java:33** - Symbol Error:
   - **Issue:** Cannot find symbol method `selectionSort(Money[])`.
   - **Code:** `Money.selectionSort(list);`

9. **TestMoney.java:34** - Symbol Error:
   - **Issue:** Cannot find symbol method `printList(Money[], int)`.
   - **Code:** `Money.printList(list,10);`

#### Warning:
1. **TestMoney.java:24** - Redundant Casting Warning:
   - **Issue:** [cast] Redundant cast to `int`.
   - **Code:** `list[i]
Transcribed Image Text:The image depicts an error output from a Java compiler with a focus on a class named `Money`. Below is a detailed transcription of the errors and warnings as they would appear on an educational website. --- ## Java Compiler Errors and Warnings ### Compilation Output: #### Errors: 1. **Money.java:48** - Method Error: - **Issue:** `add(Money)` is already defined in the class `Money`. - **Code:** `public Money add(Money otherMoney)` 2. **Money.java:75** - Symbol Error: - **Issue:** Cannot find symbol `ArrayList`. - **Code:** `public Money max(ArrayList<Money> m)` 3. **Money.java:85** - Symbol Error: - **Issue:** Cannot find symbol `ArrayList`. - **Code:** `public void publicList(ArrayList<Money> m)` 4. **TestMoney.java:12** - Symbol Error: - **Issue:** Cannot find symbol method `subtract(Money)`. - **Code:** `Money diff = m1.subtract(m2);` 5. **TestMoney.java:14** - Symbol Error: - **Issue:** Cannot find symbol method `subtract(Money)`. - **Code:** `diff = m2.subtract(m1);` 6. **TestMoney.java:28** - Symbol Error: - **Issue:** Cannot find symbol method `printList(Money[], int)`. - **Code:** `Money.printList(list,10);` 7. **TestMoney.java:30** - Static Context Error: - **Issue:** Non-static method `max(<any>)` cannot be referenced from a static context. - **Code:** `System.out.println("The Max is "+Money.max(list));` 8. **TestMoney.java:33** - Symbol Error: - **Issue:** Cannot find symbol method `selectionSort(Money[])`. - **Code:** `Money.selectionSort(list);` 9. **TestMoney.java:34** - Symbol Error: - **Issue:** Cannot find symbol method `printList(Money[], int)`. - **Code:** `Money.printList(list,10);` #### Warning: 1. **TestMoney.java:24** - Redundant Casting Warning: - **Issue:** [cast] Redundant cast to `int`. - **Code:** `list[i]
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education