Question

In: Computer Science

Create a JUNIT test program in Java for this program: package edu.odu.cs.cs350; import java.util.Arrays; /** *...

Create a JUNIT test program in Java for this program:

package edu.odu.cs.cs350;


import java.util.Arrays;


/**
 * A duration represents a period of elapsed time, e.g., 4 hours, 23 minutes, 2 seconds.
 * This is differentiated from a point in time (e.g., 4:23:02AM). A meeting that
 * has a duration of 2 hours has that same duration no matter where it was held. A 
 * starting time (point) for that of 2:00PM EST can be unambiguous only if the time
 * zone is added.
 * 
 * <p>
 * Because durations are often used in calculations, both positive and
 * negative values are possible.
 * 
 * <p>
 * Most of the accessor functions for this class will respond with normalized
 * values, where the normalization rules are as follows:
 * <ul>
 *   <li>The seconds and minutes components will have an absolute
 *       value in the range 0..59, inclusive.</li> 
 *   <li>The hours component will have an absolute value in the 
 *       range 0..23, inclusive.</li>
 *   <li>The sign of each component matches the sign of the 
 *       overall duration.  A duration of -61 seconds, for example,
 *       has normalized components of -1 seconds and -1 minutes.</li>
 * </ul>
 * Inputs to the member functions are not, however, required to 
 * be normalized. new Duration(0,0,3,-61) and new Duration(0,0,1,59)
 * are both acceptable (and the resulting Duration objects are equal).  
 * 
 * @author zeil
 *
 */
public class Duration implements Cloneable {



  /**
   * Construct a new duration, equivalent to
   * Duration(0,0,0,0).
   */
  public Duration() {
      //ToDo
  }

  /**
   * Create a new duration.
   * 
   * @param totalSeconds total number of seconds in duration
   */
  public Duration(long totalSeconds) {
      //ToDo
  }

  /**
   * Create a new duration.
   * 
   * @param days  number of days in duration
   * @param hours number of hours in duration
   * @param minutes number of minutes in duration
   * @param seconds number of seconds in duration
   */
  public Duration(int days, int hours, int minutes, int seconds) {
      //ToDo
  }

  
  /**
   * Get the total seconds of this duration, including the contributions
   * of the days, hours, minutes, & seconds components.
   *  
   * @return the total seconds
   */
  public long getTotalSeconds() {
      //ToDo
      return 0;
  }

  /**
   * Set the total seconds of this duration, potentially altering
   * the days, hours, minutes, & seconds components.

   * @param totalSeconds the total seconds to set
   */
  public void setTotalSeconds(long totalSeconds) {
      //ToDo
  }

  /**
   * How many days in this duration?.
   * 
   * @return the normalized days component
   */
  public int getDays() {
      //ToDo
      return 0;
  }
  
  private static final long secondsPerHour = 60 * 60; 

  /**
   * How many hours in this duration?.
   * 
   * @return the normalized hours component
   */
  public int getHours() {
      //ToDo
      return 0;
  }

  
  /**
   * How many minutes in this duration?.
   * 
   * @return the normalized minutes component
   */
  public int getMinutes() {
      //ToDo
      return 0;
  }
  

  /**
   * How many seconds in this duration?.
   * 
   * @return the normalized seconds component
   */
  public int getSeconds() {
      //ToDo
      return 0;
  }

  /**
   * Add another duration to this one.
   * @param dur a duration
   */
  public void add(Duration dur) {
      //ToDo
  }

  /**
   * Subtract another duration from this one.
   * @param dur a duration
   */
  public void subtract(Duration dur) {
      //ToDo
  }

  /**
   * Multiply this duration by a scaling factor,
   * rounding to the closest second.
   * @param factor a scaling factor
   */
  public void scale(double factor) {
      //ToDo
  }

  /**
   * Render the duration as
   *     d:h:m:s
   * (preceded by a '-'if the duration is negative)
   * where the four components are normalized non-negative
   * integer values. The final three components are always rendered 
   * in 2 digits. The two leading components and their 
   * associated ':' delimiters are omitted if the leading values
   * are zero.  E.g., Duration(0,-1,-59,-61) would be rendered as
   * "-02:00:01".
   */
  public String toString() {
      //ToDo
      return "";
  }
  
  

  // Comparison and hashing

  /**
   * Compares two durations for equality. They are considered equal if
   * their getTotalSeconds() values are equal.
   *
   * @param obj object to be compared for equality with this duration
   * @return <tt>true</tt> if the specified object is equal to this one
   */
  public boolean equals(Object obj) {
      //ToDo
      return false;
  }

  /**
   * Returns the hash code value for this object.
   *
   * @return the hash code value for this duration
   */
  public int hashCode() {
      //ToDo
      return 0;
  }

  /**
   * Return a (deep) copy of this object.
   */
  @Override
  public Object clone()  {
      //ToDo
      return null;
  }


}

*This is the template to fill in for the solution - please fill in these functions to complete the JUNIT Test Class*

/**
*
*/
package edu.odu.cs.cs350;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author Colten Everitt
*
*/
public class DurationClassTest {

   /**
   * @throws java.lang.Exception
   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @Before
   public void setUp() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @After
   public void tearDown() throws Exception {
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#hashCode()}.
   */
   @Test
   public final void testHashCode() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration()}.
   */
   @Test
   public final void testDuration() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(long)}.
   */
   @Test
   public final void testDurationLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(int, int, int, int)}.
   */
   @Test
   public final void testDurationIntIntIntInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getTotalSeconds()}.
   */
   @Test
   public final void testGetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#setTotalSeconds(long)}.
   */
   @Test
   public final void testSetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getDays()}.
   */
   @Test
   public final void testGetDays() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getHours()}.
   */
   @Test
   public final void testGetHours() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getMinutes()}.
   */
   @Test
   public final void testGetMinutes() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getSeconds()}.
   */
   @Test
   public final void testGetSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#add(edu.odu.cs.cs350.Duration)}.
   */
   @Test
   public final void testAdd() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#subtract(edu.odu.cs.cs350.Duration)}.
   */
   @Test
   public final void testSubtract() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#scale(double)}.
   */
   @Test
   public final void testScale() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#toString()}.
   */
   @Test
   public final void testToString() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#equals(java.lang.Object)}.
   */
   @Test
   public final void testEqualsObject() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#clone()}.
   */
   @Test
   public final void testClone() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#Object()}.
   */
   @Test
   public final void testObject() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#getClass()}.
   */
   @Test
   public final void testGetClass() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#equals(java.lang.Object)}.
   */
   @Test
   public final void testEqualsObject1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#clone()}.
   */
   @Test
   public final void testClone1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#toString()}.
   */
   @Test
   public final void testToString1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#notify()}.
   */
   @Test
   public final void testNotify() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#notifyAll()}.
   */
   @Test
   public final void testNotifyAll() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait(long)}.
   */
   @Test
   public final void testWaitLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait(long, int)}.
   */
   @Test
   public final void testWaitLongInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait()}.
   */
   @Test
   public final void testWait() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#finalize()}.
   */
   @Test
   public final void testFinalize() {
       fail("Not yet implemented"); // TODO
   }

}

Solutions

Expert Solution

package edu.odu.cs.cs350;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public static void main(String[] args) {
//ArrayList of type String
ArrayList data = new ArrayList();
try{
Scanner s = new Scanner(new FileInputStream("C:/Documents/assn2data.txt"));
String line;
int sum=0;
// Read Each line of File Using hasNextLine()
while(s.hasNextLine()){
line = s.nextLine(); // nextLine() is to retrieve
sum = sum+line.length();
data.add(line); //Adding line to ArrayList
}
  
System.out.println("The number of Entries are:"+data.size());
System.out.println("The number of characters:"+sum);
  

/**
* @author Colten Everitt
*
*/
public class DurationClassTest {

   /**
   * @throws java.lang.Exception
   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @Before
   public void setUp() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @After
   public void tearDown() throws Exception {
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#hashCode()}.
   */
   @Test
   public final void testHashCode() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration()}.
   */
   @Test
   public final void testDuration() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(long)}.
   */
   @Test
   public final void testDurationLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(int, int, int, int)}.
   */
   @Test
   public final void testDurationIntIntIntInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getTotalSeconds()}.
   */
   @Test
   public final void testGetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

}

  
data.add(0, "*****The file has been modified on*****");
data.add(data.size(), "*****Number of lines remaining are******");
  
System.out.println("Storing Data into file after being modified..");
  
int j=0;
  
//Writing modified data into file
PrintWriter p = new PrintWriter("C:/Users/Documents/assn2data-modified.txt");
BufferedWriter b = new BufferedWriter(p);
while(data.size()>j){
b.write(data.get(j));
b.newLine();
j++;
}
b.close();
p.close();
  
System.out.println("Data is stored into modified file..");
}   

}


Related Solutions

JAVA SHOW YOUR OUTPUT package exampletodo; import java.util.Arrays; import stdlib.*; /** * Edit the sections marked...
JAVA SHOW YOUR OUTPUT package exampletodo; import java.util.Arrays; import stdlib.*; /** * Edit the sections marked TODO * * Unless specified otherwise, you must not change the declaration of any * method. */ public class example {        /**        * valRange returns the difference between the maximum and minimum values in the        * array; Max-Min. Precondition: the array is nonempty. Your solution must go        * through the array at most once.        *        * Here are...
Download labSerialization.zip and unzip it: ListVsSetDemo.java: package labSerialization; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List;...
Download labSerialization.zip and unzip it: ListVsSetDemo.java: package labSerialization; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; /** * Demonstrates the different behavior of lists and sets. * Author(s): Starter Code */ public class ListVsSetDemo { private final List<ColoredSquare> list; private final Set<ColoredSquare> set; /** * Initializes the fields list and set with the elements provided. * * @param elements */ public ListVsSetDemo(ColoredSquare... elements) { list = new ArrayList<>(Arrays.asList(elements)); set = new HashSet<>(Arrays.asList(elements)); } /** * Creates a string...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Test Your Understanding Create a JAVA package by name ClassEx2 and in the main() method of...
Test Your Understanding Create a JAVA package by name ClassEx2 and in the main() method of the class, assign your name to a String object and your father name to a different String object and do the following; Concatenate your name and your father name. Get the length of your full name. Find the index of any character in your full name. Replace the occurrence of any lower case character in your full name to capital character. Compare your first...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java,...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java, BubbleSortTestCaseMaker.java, and Statistician.java. PART 1: Implementing BubbleSorter Implement a very simple BubbleSorter class that records how many array visits and how many swaps are performed. Look at the starter file before reading on. This class has an instance variable called “a”. Its type is int[]. This is the array that will be bubble-sorted in place. Usually a single letter is a bad variable name,...
Java: Complete the methods marked TODO. Will rate your answer! -------------------------------------------------------------------------------------------------- package search; import java.util.ArrayList; import...
Java: Complete the methods marked TODO. Will rate your answer! -------------------------------------------------------------------------------------------------- package search; import java.util.ArrayList; import java.util.List; /** * An abstraction over the idea of a search. * * @author liberato * * @param <T> : generic type. */ public abstract class Searcher<T> { protected final SearchProblem<T> searchProblem; protected final List<T> visited; protected List<T> solution; /**    * Instantiates a searcher.    *    * @param searchProblem    *            the search problem for which this searcher will find and   ...
import java.util.Scanner; import java.util.Arrays; /* You have 3 small methods to write for this exam; public...
import java.util.Scanner; import java.util.Arrays; /* You have 3 small methods to write for this exam; public static int smallest(int[] v1, int[] v2) public static int[] convert1(String str) public static String convert2(int[] v)    The comments right before each of them tell you exactly what they are expected to do. Read all requirements first, then start implementing the easiest methods first. You may work on them in any order. You are also provided with a main method and two other methods...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside of main declare two static final variables and integer for number of days in the week and a double for the revenue per pizza (which is $8.50). Create a method called main Inside main: Declare an integer array that can hold the number of pizzas purchased each day for one week. Declare two additional variables one to hold the total sum of pizzas sold...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public...
create code for deletestudentbyID Number for choice == 4 package courseecom616; import java.util.Scanner; import java.util.ArrayList; public class CourseeCOM616 {        private String courseName;     private String[] studentsName = new String[1];     private String studentId;        private int numberOfStudents;        public CourseeCOM616(String courseName) {         this.courseName = courseName;     }     public String[] getStudentsName() {         return studentsName;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getStudentId() {         return studentId;    ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT