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

Need help ASAP please, posted question yesterday and recieved no answer so I\'m

ID: 3682241 • Letter: N

Question

Need help ASAP please, posted question yesterday and recieved no answer so I'm posting again hoping I get an answer within 4 hours :(

JAVA:

Measurable and MeasurableSet

1: Create an interface Measurable.

The Measurable interface should have one method,
int getMeasure()

2: Choose any two of the Wall, Field and Word classes that have been provided to you. Modify the classes you choose to implement the Measurable interface.
The measure of a Wall is its area (height * length)
The measure of a Field is its perimeter (2 * width + 2 * length)
The measure of a Word is the number of vowels it has (a, e, i, o and u). So, for example, the measure of a Word "Sophie" is 3, and the measure of "Sally" is 1.

3: Create a MeasurableSet class that stores and analyzes Measurable objects. The MeasurableSet class should have three instance variables:

ArrayList<Measurable> that holds all Measurable objects that have been added to the MeasurableSet

Measurable min that holds the object with the smallest measure that has been added to the MeasurableSet

Measurable max that holds the object with the largest measure that has been added to the MeasurableSet .


The MeasurableSet class has the following constructor
MeasurableSet ()

The MeasurableSet class has the following methods

// mutator to add a new Measurable object to the MeasurableSet . Set min if the object is smaller than any previously seen object, max if the object is larger than any previously seen object.
void add(Measurable m)

// accessor to return the min object
Measurable getMin()

// accessor to return the max object
Measurable getMax()

// accessor to return the Measurable objects in the MeasurableSet whose Measurable value is greater than or equal to floor, and less than or equal to ceiling
ArrayList<Measurable> getMiddle(int floor, int ceiling)

4: Write a class with a main method. The main method should create a MeasurableSet object, and four objects from the Wall/Field/Word classes that you created for Steps 2 and 3. Add these objects to the MeasurableSet, and print the smallest and largest values returned from the MeasurableSet. Test the getMiddle method. (Does it make any sense to mix Wall, Field and Word objects in the same MeasurableSet? Does the MeasurableSet object care? By implementing Measurable, applications using Wall, Field or Word objects can use the exact same MeasurableSet to analyze data.)

Field:


public class Field {
  
   private int length;
   private int width;
  
   public Field(int len, int wid) {
       length = len;
       width = wid;
   }

   public int getLength() {
       return length;
   }

   public int getWidth() {
       return width;
   }
  
   public String toString() {
       return "Field length:" + length + " width:" + width;
   }

}

Wall:


public class Wall {
  
   private int height;
   private int length;
  
   public Wall(int len, int hgt) {
       length = len;
       height = hgt;
   }

   public int getHeight() {
       return height;
   }

   public int getLength() {
       return length;
   }
  
   public String toString() {
       return "Wall length:" + length + " height:" + height;
   }

}

Word:


public class Word {
  
   private String myWord;
  
   public Word(String word) {
       myWord = word;
   }
  
   public String getWord() {
       return myWord;
   }

   public String toString() {
       return "Word " + myWord;
   }

}

Thank you so much!

Explanation / Answer

interface Measurable
{
   int getMeasure();
}

public class Field impliments Measurable
{
  
    private int length;
    private int width;
  
    public Field(int len, int wid)
   {
    length = len;
    width = wid;
    }
    public int getLength() {
    return length;
    }
    public int getWidth() {
    return width;
    }
  
    public String toString() {
    return "Field length:" + length + " width:" + width;
    }

   public int getMeasure()
   {
       return 2*width+2*length;
   }
}


public class Wall {
  
private int height;
private int length;
  
public Wall(int len, int hgt) {
length = len;
height = hgt;
}
public int getHeight() {
return height;
}
public int getLength() {
return length;
}

   public int getMeasure()
   {
       return height*width;
   }
  
public String toString() {
return "Wall length:" + length + " height:" + height;
}
}

class MeasurableSet
{
   MeasurableSet ()
   {
   }

   public static void main(String args[])
   {
       Field o=new Field(10,20);
       Field o1=new Field(20,30);

       Wall o2=new Wall(10,20);
       Wall o3=new Wall(20,30);

       int aa=o.getMeasure();
       int bb=o1.getMeasure();
       int cc=o2.getMeasure();
       int dd=o3.getMeasure();
       System.out.println(aa);
       System.out.println(bb);
       System.out.println(cc);
       System.out.println(dd);

   }
}

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