Read the specification for the Train class, its constructor, and the getUnicodeString method.      2. Create a JUnit test class for its constructor in the appropriate package based

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I was told to 

  1. Read the specification for the Train class, its constructor, and the getUnicodeString method.

     2. Create a JUnit test class for its constructor in the appropriate package based
      (You may have to build the class package yourself)

I don't understand how to make a Junit test class. My code is listed below. 

/**
 * Represents a train with some number of cars,
 * that will be printed using Unicode characters.
 * 
 * @author 
 * @version 
 */
public class Train {

    private int numCars;
    
    private static String ENGINE = "?";
    private static String CABOOSE = "?";
    private static final String RAILCAR = "?";
    
    /**
     * Creates a train with the given number of cars.
     * If the train has zero cars it is just an engine and caboose.
     * 
     * @precondition numCars >= 0
     * @postcondition getNumCars()==numCars
     * 
     * @param numCars the number of cars (excepting engine and caboose)
     *  for the train
     */
    public Train(int numCars) {
        if (numCars < 0) {
            throw new IllegalArgumentException("numCars should be > 0");
        }
        
        this.numCars = numCars;
    }
    
    /**
     * Gets the number cars in the train,
     * not including the engine and caboose.
     * 
     * @return the number of cars
     */
    public int getNumCars() {
        return this.numCars;
    }
    
    /**
     * Returns the total length of the train.
     * 
     * @return the total length of the train, including the
     * engine and caboose
     */
    public int length() {
        return this.numCars + 2;
    }
    
    /**
     * Builds a unicode train consisting of an engine,
     * followed by getNumCars() railcars, followed by a
     * caboose. A train will always have at least an engine
     * and a caboose.
     * 
     * @return a Unicode string as described above.
     */
    public String getUnicodeString() {
        // replace the return statement with your solution
        return null;
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Thank you for your response! I am supposed to use a for-loop to generate the railcars. Any idea how I can do this? Also the value of these Strings are all emojis even though they may show as questions marks. I hope this makes my question more clear!

private static String ENGINE = "?";
private static String CABOOSE = "?";
private static final String RAILCAR = "?";


Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY