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

Simple java JUint test help! Okay I was wondering if someone could show me somet

ID: 668715 • Letter: S

Question

Simple java JUint test help!

Okay I was wondering if someone could show me something, Iets say I have a class boat like this -

public class boat
{
   private int _speed;
   private double _weight;

   public boat(int speed, double weight)
   {
       _speed = speed;
       _weight = weight;

   }
  
   public String toString()
   {
       return "speed is " + _speed + " weight is" + _weight;
   }
}

can someone show me how I would edit the boat class to have a method to add each boat object into an array (1 dimentional) and then write a tester that will create a few boat objects, add them to the array and then test the array to make sure the objects are the correct value and in the correct order in the array.

Explanation / Answer

To add a method to the class boat :

Just declare like : private LinkedList<Boat> lb = new LinkedList<Boat>();

or declaring a client method like : private Clients clients = new Clients();

To create a few objects :

just declare the values as speed and weight like :

lb.add(new Boat(103, 24));

lb.add(new Boat(123, 23));

// public void removeClient()

{

  clients.removeTheClient();

}

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