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 =...
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;    ...
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(); }...
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...
JAVA package stringPractice1068; public class SomePracticeStringMethods { /* returns true if c is a punctuation mark...
JAVA package stringPractice1068; public class SomePracticeStringMethods { /* returns true if c is a punctuation mark or false otherwise * * Punctuation mark is defined as: * apostrophe ' * comma , * period . * semicolon ; * colon : * exclamation point ! * question mark ? * * (You don't have to worry about any others) */ public static boolean isPunct(char c) {    /* placeholder just so that the function    * compiles. fill in your...
----fix code to search and delete a student by Identification number import java.util.Scanner; public class COurseCom666...
----fix code to search and delete a student by Identification number import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public int DeleteStudentsByID() {         return...
Fill in the following blanks for java code::: import java.util.NoSuchElementException; public class CircularQueue<E> {    private...
Fill in the following blanks for java code::: import java.util.NoSuchElementException; public class CircularQueue<E> {    private E[] queue;    private int front = 0, rear = 0;    private static final int DEFAULT_CAPACITY = 5;       public CircularQueue(int capacity)    {    queue = (E[]) new Object[capacity + 1];    }       public CircularQueue()    {        this(DEFAULT_CAPACITY); }       //Add a method that will determine if the queue is empty. Recall that the queue is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT