Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. The goal of this step is to create a class of Integer objects that count how

ID: 3809457 • Letter: 5

Question

5. The goal of this step is to create a class of Integer objects that count how many times they are compared or copied. This will allow you (in the next step) to measure the performance of sorting algorithms by observing how many times they compare or copy elements. When elements are large, these are the most expensive operations performed by the algorithms. The Integer objects will allow you to count these operations without having to modify the sorting algorithms. You can do this step in one of two ways, as described below. The original way is the one that was in the first version of this project description. De- pending on the standard library implementation that your compiler uses, it may give you compilation problems. The preferred way avoids those problems. As a bonus, it also gives you more accurate results. (Because it allows you to count operations performed on all Integer objects, in cluding temporary objects created by the sorting algorithms. The original way only allows you to retrieve the number of operations performed on Integer objects you create yourself) Do this step the preferred way unless you had already done it the original way and didn't have compilation problems

Explanation / Answer

Hi,

Please see the class below:


public class Integer {
  
   public static int Integer_count;
   private Integer inval;

  
   //Default constructor
   public Integer() {
       inval = new Integer(0);
   }
  
  
   //Constructor Integer(x)
   public Integer(int x) {
       inval = new Integer(x);
   }
  
   //Copy constructor
   public Integer(Integer x) {
       inval = x;
       Integer_count=Integer_count +1;
   }
  
   public int value(){
       return inval.value();
   }
  
  
   public boolean lessThan (Integer i){
       int currVal = this.inval.value();
       int secondVal = i.value();
       if(currVal < secondVal){
           return true;
       }
       return false;
   }
  
   public void assignment(Integer i){
      
       this.inval = i;
      
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote