Question

In: Computer Science

Fix the following java code package running; public class Run {    public double distance; //in...

Fix the following java code

package running;

public class Run {
   public double distance; //in kms
   public int time; //in seconds

   public Run prev;
   public Run next;

   //DO NOT MODIFY - Parameterized constructor
   public Run(double d, int t) {
       distance = Math.max(0, d);
       time = Math.max(1, t);
   }
  
   //DO NOT MODIFY - Copy Constructor to create an instance copy
   //NOTE: Only the data section should be copied over, not the links
   public Run(Run source) {
       this(source.distance, source.time);
   }

   //DO NOT MODIFY (return speed in kmph)
   public double speed() {
       return distance*3600/time;
   }

   /**
   * add an INSTANCE COPY of the passed object (using the copy constructor)
   * at the end of the list in which the calling object exists.
   * @param run
   */
   public void addToEnd(Run run) {
       System.out.println(run.next);
       //to be completed
   }

   /**
   * add an INSTANCE COPY of the passed object (using the copy constructor)
   * at the front of the list in which the calling object exists
   * @param run
   */
   public void addToFront(Run run) {
       //to be completed
   }

   /**
   *
   * @return number of objects in the list in which the calling object exists
   */
   public int size() {
       return 0; //to be completed
   }

   /**
   *
   * @return the index of the calling object in the list.
   * the index of the first object in the list is 0.
   */
   public int getIndex() {
       return 0; //to be completed
   }

   /**
   *
   * @param idx
   * @return the object that exists in the list at the passed index.
   * return null if there is no object at that index
   */
   public Run get(int idx) {
  
       return null; //to be completed
   }
  
   /**
   * return a text version of the list in which the calling object exists.
   * use "->" as the separator.
   */
   public String toString() {
       return null; //to be completed
   }
  
   //DO NOT MODIFY
   public String toStringIndividual() {
       return distance+" in "+time;
   }
  
   /**
   * insert an INSTANCE COPY of the second parameter (using the copy constructor)
   * at index idx, thereby pushing all subsequent items one place higher
   * (in terms of index).
   * @param idx
   * @param run
   * @return true if an INSTANCE COPY was successfully added at
   * the given index in the list, false otherwise.
   */
   public boolean add(int idx, Run run) {
       return false; //to be completed
   }

   /**
   *
   * @param thresholdSpeed
   * @return the highest number of consecutive items in the list
   * (to which the calling object belongs) that have a speed more than
   * the thresholdSpeed.
   */
   public int longestSequenceOver(double thresholdSpeed) {
       return 0; //to be completed
   }

   /**
   *
   * @param thresholdSpeed
   * @return an array containing representations of the runs (in order of sequence)
   * in the list to which the calling object belongs, that have a speed more than
   * the thresholdSpeed. return null if no such item exists in the list.
   */
   public String[] getRunsOver(double thresholdSpeed) {
       return null; //to be completed
   }
}

Solutions

Expert Solution

The above code is not having a public main method, which is necessary for running every Java program.

Answer will be updated soon as you need please don't yet rate the answer just say what parts you need to be changed in comments below, thanks!

CODE:

package running;

public class Run {
public double distance; //in kms
public int time; //in seconds

public Run prev;
public Run next;

//DO NOT MODIFY - Parameterized constructor
public Run(double d, int t) {
distance = Math.max(0, d);
time = Math.max(1, t);
}
  
//DO NOT MODIFY - Copy Constructor to create an instance copy
//NOTE: Only the data section should be copied over, not the links
public Run(Run source) {
this(source.distance, source.time);
}

//DO NOT MODIFY (return speed in kmph)
public double speed() {
return distance*3600/time;
}

/**
* add an INSTANCE COPY of the passed object (using the copy constructor)
* at the end of the list in which the calling object exists.
* @param run
*/
public void addToEnd(Run run) {
System.out.println(run.next);
//to be completed
}

/**
* add an INSTANCE COPY of the passed object (using the copy constructor)
* at the front of the list in which the calling object exists
* @param run
*/
public void addToFront(Run run) {
//to be completed
}

/**
*
* @return number of objects in the list in which the calling object exists
*/
public int size() {
return 0; //to be completed
}

/**
*
* @return the index of the calling object in the list.
* the index of the first object in the list is 0.
*/
public int getIndex() {
return 0; //to be completed
}

/**
*
* @param idx
* @return the object that exists in the list at the passed index.
* return null if there is no object at that index
*/
public Run get(int idx) {
  
return null; //to be completed
}
  
/**
* return a text version of the list in which the calling object exists.
* use "->" as the separator.
*/
public String toString() {
return null; //to be completed
}
  
//DO NOT MODIFY
public String toStringIndividual() {
return distance+" in "+time;
}
  
/**
* insert an INSTANCE COPY of the second parameter (using the copy constructor)
* at index idx, thereby pushing all subsequent items one place higher
* (in terms of index).
* @param idx
* @param run
* @return true if an INSTANCE COPY was successfully added at
* the given index in the list, false otherwise.
*/
public boolean add(int idx, Run run) {
return false; //to be completed
}

/**
*
* @param thresholdSpeed
* @return the highest number of consecutive items in the list
* (to which the calling object belongs) that have a speed more than
* the thresholdSpeed.
*/
public int longestSequenceOver(double thresholdSpeed) {
return 0; //to be completed
}

/**
*
* @param thresholdSpeed
* @return an array containing representations of the runs (in order of sequence)
* in the list to which the calling object belongs, that have a speed more than
* the thresholdSpeed. return null if no such item exists in the list.
*/
public String[] getRunsOver(double thresholdSpeed) {
return null; //to be completed
}

public static void main(String[] args){
//Put the code to run the main program and test above build functions
}


}

//CODE END


Related Solutions

COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
Using the following in Java- package intersectionprinter; import java.awt.Rectangle; public class IntersectionPrinter { public static void...
Using the following in Java- package intersectionprinter; import java.awt.Rectangle; public class IntersectionPrinter { public static void main(String[] args) { Rectangle r1 = new Rectangle(0,0,100,150); System.out.println(r1);    Rectangle r2 = new Rectangle(50,75,100,150); System.out.println(r2);    Rectangle r3 = r1.intersection(r2);    } } Write a program that takes both Rectangle objects, and uses the intersection method to determine if they overlap. If they do overlap, then print it's coordinates along with its width and height. If there is no intersection, then have the...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public static void main(String[] args) {        System.out.println("This program will ask the user for three sets of two numbers and will calculate the average of each set.");        Scanner input = new Scanner(System.in);        int n1, n2;        System.out.print("Please enter the first number: ");        n1 = input.nextInt();        System.out.print("Please enter the second number: ");        n2 =...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int hours, shift, retirement = 0; do { System.out.print("Enter the number of hours worked (>0): "); hours = scanner.nextInt(); } while (hours <= 0); do { System.out.print("Enter shift [1 2 or 3]: "); shift = scanner.nextInt(); } while (shift < 1 || shift > 3); if (shift == 2 || shift ==...
package hw; public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically...
package hw; public class MyArrayForDouble { double[] nums; int numElements; public MyArrayForDouble() { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[5]; } public MyArrayForDouble(int capacity) { // Constructor. automatically called when creating an instance numElements = 0; nums = new double[capacity]; } public MyArrayForDouble(double[] nums1) { nums = new double[nums1.length]; for(int i=0;i<nums1.length;i++) nums[i] = nums1[i]; numElements = nums1.length; } void printArray(){ // cost, times System.out.printf("printArray(%d,%d): ",numElements,nums.length); for(int i=0; i<numElements;i++) System.out.print(nums[i]+" "); System.out.println(); }...
The following code is included for the java programming problem: public class Bunny {        private...
The following code is included for the java programming problem: public class Bunny {        private int bunnyNum;        public Bunny(int i) {               bunnyNum = i;        }        public void hop() {               System.out.println("Bunny " + bunnyNum + " hops");        } } Create an ArrayList <????> with Bunny as the generic type. Use an index for-loop to build (use .add(….) ) the Bunny ArrayList. From the output below, you need to have 5. Use an index for-loop...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance);...
Base Class class TransportationLink { protected: string _name; double _distance; public: TransportationLink(const string &name, double distance); const string & getName() const; double getDistance() const; void setDistance(double); // Passes in the departure time (as minute) and returns arrival time (as minute) // For example: // 8 am will be passed in as 480 minutes (8 * 60) // 2:30 pm will be passed in as 870 minutes (14.5 * 60) virtual unsigned computeArrivalTime(unsigned minute) const = 0; }; #endif Derived Classes...
In Java, please write a tester code. Here's my code: public class Bicycle {     public...
In Java, please write a tester code. Here's my code: public class Bicycle {     public int cadence; public int gear;   public int speed;     public Bicycle(int startCadence, int startSpeed, int startGear) {         gear = startGear;   cadence = startCadence; speed = startSpeed;     }     public void setCadence(int newValue) {         cadence = newValue;     }     public void setGear(int newValue) {         gear = newValue;     }     public void applyBrake(int decrement) {         speed -= decrement;    ...
USING JAVA: Complete the following class. input code where it says //TODO. public class BasicBioinformatics {...
USING JAVA: Complete the following class. input code where it says //TODO. public class BasicBioinformatics { /** * Calculates and returns the complement of a DNA sequence. In DNA sequences, 'A' and 'T' are * complements of each other, as are 'C' and 'G'. The complement is formed by taking the * complement of each symbol (e.g., the complement of "GTCA" is "CAGT"). * * @param dna a char array representing a DNA sequence of arbitrary length, * containing only...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT