Project 6

profilelasonia73
archive6.zip

Using an LLM Report - Project 6-1.docx

Report Template: Evaluating LLM-Assisted Code Generation from SDS and Unit Tests

1. Introduction

Purpose: Explain the primary goal of this project or experiment. Were you testing the feasibility of LLM-assisted development, the accuracy of generated code, or its effectiveness in a TDD workflow?

Background: Briefly describe the context — the SDS and unit tests provided, the programming environment (e.g., Java, SDK dependencies), and any prior challenges motivating this approach.

2. Tools and Setup

LLM and Environment: Identify the model used (e.g., ChatGPT, GPT-5, etc.), its version, and any relevant configuration settings.

Supporting Tools: List the development tools or environments used (e.g., IntelliJ, JUnit, Git, Android Studio) and note any SDKs or APIs (such as iPal SDK).

Artifacts Provided to the LLM: Describe the specific inputs given to the LLM — such as the SDS, UML diagrams, or unit test files — and how they were formatted or presented.

3. Methodology

Prompting Strategy: Explain how you instructed the LLM to generate code. Include examples of initial prompts and follow-up instructions if iterative refinement was required.

Code–Test Cycle: Describe how you validated the LLM’s output. Did you run the generated code immediately, revise prompts, or feed test failures back into the model?

Evaluation Criteria: Define the criteria used to assess success — e.g., test pass rate, adherence to design, efficiency, readability, or maintainability.

4. Results

Functional Correctness: Report how much of the generated code passed the unit tests on the first attempt. Include percentages or counts if available.

Design Adherence: Discuss how well the generated classes and methods aligned with the specifications outlined in the SDS.

Iteration Summary: Indicate how many prompt–response cycles were needed before the code functioned correctly.

Performance: Comment on whether the generated code met expected performance or efficiency benchmarks (if applicable).

5. Analysis and Discussion

LLM Strengths: Describe where the LLM performed well — for example, in scaffolding class structures, creating helper methods, or generating testable logic.

LLM Limitations: Identify recurring issues such as misunderstanding SDK functions, generating incorrect syntax, or missing test cases.

Comparison to Manual Coding: Discuss how the LLM-based approach compared to traditional hand-coded development in terms of time, effort, and quality.

Testing and Coverage: Evaluate test coverage levels and whether the generated code satisfied most or all unit tests. Include observations about false positives or incomplete coverage.

6. Code Quality and Maintainability

Readability: Assess clarity of naming conventions, formatting, and use of comments.

Architecture: Determine whether the LLM followed object-oriented design principles and whether the resulting structure matched the SDS intent.

Maintainability: Discuss whether the code could be easily modified, extended, or reused in future projects.

7. Learning Outcomes

Student Perspective: Reflect on what was learned through using the LLM in a TDD context. Did this process clarify the relationship between design, testing, and implementation?

Skill Development: Describe improvements in understanding test-driven development, debugging, or prompt engineering.

Pedagogical Impact: Comment on how such AI-assisted methods might be incorporated into future coursework or curriculum design.

8. Ethical and Practical Considerations

Authorship and Integrity: Discuss how code attribution was handled and what constitutes original student work when using AI tools.

Reliability and Bias: Reflect on the trustworthiness of LLM-generated code and how human verification remains essential.

Responsible Use Guidelines: Propose rules or best practices for ethically integrating LLMs into programming coursework or research.

9. Conclusions

Summary of Findings: Provide a concise overview of what worked, what didn’t, and how effective the LLM was in supporting code generation from SDS and unit tests.

Recommendations for Future Work: List specific improvements — such as refining prompts, improving test clarity, or supplementing LLM-generated output with manual review.

Feasibility Statement: Conclude with your assessment: under what conditions is LLM-assisted TDD a viable or valuable approach?

10. References (if applicable)

Include references to any supporting materials, SDK documentation, or published sources used to contextualize your findings.

simulate.txt

public void simulate() { int currStop = 1; // current stop starts at 1 int time = 1; // current time boolean loopAgain = true; while (loopAgain) { loopAgain = false; // assume all customers are done boolean printed = false; // controls printing headings for (int i=0; i < custList.size(); i++) // process every customer { Customer cust = custList.get(i); // get current customer if (cust.getStatus() != Customer.CUST_EXITED) // at least one more customer to process { loopAgain = true; } // check if current customer already arrived at train and wants to enter at current stop if (cust.getStatus() == Customer.CUST_NOT_PROCESSED && cust.getArrival() <= time && cust.getEnter() == currStop) { if (!printed) System.out.println("Current Time=" + time + " Current Stop=" + currStop); System.out.println(" Customer enters train: id="+cust.getId()); cust.setStatus(Customer.CUST_ENTERED); custList.set(i, cust); // update customer list with changed status printed = true; } // check if the current customer is in train and wants to exit at current stop if (cust.getStatus() == Customer.CUST_ENTERED && cust.getExit() == currStop) { if (!printed) System.out.println("Current Time=" + time + " Current Stop=" + currStop); System.out.println(" Customer exits train: id="+cust.getId()); cust.setStatus(Customer.CUST_EXITED); custList.set(i, cust); // update customer list with changed status printed = true; } } // loop on customers if (currStop == stops) currStop = 1; // if reached last stop, reset to first stop else currStop++; // go to next stop if (printed) // if there was something printed, we made a stop { madeStops++; // update the number of stops made currTime = time; // update time to process all customers } time++; // increment current time } // while more to process }

tests.zip

bad-dup-id

1 1 2 4 1 2 3 4

bad-enter

1 1 0 2

bad-enter-exit

1 2 3 3

bad-enter2

1 1 x 2

bad-enter3

1 1 8 2

bad-exit

1 1 1 0

bad-exit2

1 1 1 x

bad-exit3

1 1 1 8

bad-id

0 1 1 2

bad-id2

x 1 1 2

bad-time

1 0 1 2

bad-time2

1 x 1 2

customer

1 1 1 2 2 2 1 3

TestCustomerAdvanced.java

TestCustomerAdvanced.java


import   static  org . junit . Assert . * ;
import  org . junit . Test ;

/*
 * Author: Renata Rand McFadden
 * Unit tests for Customer class
 * Checks that Customer class exists with correct implementation of methods
 */
public   class   TestCustomerAdvanced   {

    @ Test
     // Test that constructor correctly updates the attributes and get method returns it:
     //     attribute Id
     public   void  testConstructorAttributeId ()   {
         String  message  =   "Id value passed to Customer Constructor does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        assertEquals ( message ,  id ,  cust . getId ());    // expect same value as passed to constructor
     }
    
    @ Test
     // Test that constructor correctly updates the attributes and get method returns it:
     //     attribute arrival
     public   void  testConstructorAttributeArrival ()   {
         String  message  =   "arrival value passed to Customer Constructor does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        assertEquals ( message ,  time ,  cust . getArrival ());    // expect same value as passed to constructor
     }
    
    @ Test
     // Test that constructor correctly updates the attributes and get method returns it:
     //     attribute enterStop
     public   void  testConstructorAttributeEnter ()   {
         String  message  =   "enter value passed to Customer Constructor does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        assertEquals ( message ,  enter ,  cust . getEnter ());    // expect same value as passed to constructor
     }
    
    @ Test
     // Test that constructor correctly updates the attributes and get method returns it:
     //     attribute exit
     public   void  testConstructorAttributeExit ()   {
         String  message  =   "exit value passed to Customer Constructor does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        assertEquals ( message ,  exit ,  cust . getExit ());    // expect same value as passed to constructor
     }     
    
    @ Test
     // Test that constructor correctly updates the attributes and get method returns it:
     //     attribute status
     public   void  testConstructorAttributeStatus ()   {
         String  message  =   "status value set in Customer Constructor does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        assertEquals ( message ,   Customer . CUST_NOT_PROCESSED ,  cust . getStatus ());    // expect status to be set to CUST_NOT_PROCESSED constant
     }
    
    @ Test
     // Test that setStatus correctly updates the attributes and get method returns it:
     //     attribute status set to CUST_ENTERED
     public   void  testConstructorMethodSetStatusValue1 ()   {
         String  message  =   "status value set in setStatus(int) does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        cust . setStatus ( Customer . CUST_ENTERED );    // set status to allowed value
        assertEquals ( message ,   Customer . CUST_ENTERED ,  cust . getStatus ());    // expect status to be set to value of CUST_ENTERED
     }

    @ Test
     // Test that setStatus correctly updates the attributes and get method returns it:
     //     attribute status set to CUST_EXITED
     public   void  testConstructorMethodSetStatusValue2 ()   {
         String  message  =   "status value set in setStatus(int) does not match one returned by get method" ;
         int  id  =   5 ;
         int  time  =   10 ;
         int  enter  =   6 ;
         int  exit  =   8 ;
         Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
        cust . setStatus ( Customer . CUST_EXITED );    // set status to allowed value
        assertEquals ( message ,   Customer . CUST_EXITED ,  cust . getStatus ());    // expect status to be set to value of CUST_EXITED
     }    
    
    @ Test
     // test that if id attribute is negative throws IllegalArgumentException
     public   void  testIdNegativeValue ()
     {
         try   {
             int  id  =   - 3 ;    // invalid value of id
             int  time  =   10 ;
             int  enter  =   6 ;
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of id" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }
    @ Test
     // test that if id attribute is zero throws IllegalArgumentException
     public   void  testIdZeroValue ()
     {
         try   {
             int  id  =   0 ;    // invalid value of id
             int  time  =   10 ;
             int  enter  =   6 ;
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of id" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }    

    @ Test
     // test that if arrival attribute is negative throws IllegalArgumentException
     public   void  testArrivalNegativeValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   - 1 ;   // invalid value of arrival attribute
             int  enter  =   6 ;
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of arrival" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }
    @ Test
     // test that if arrival attribute is zero throws IllegalArgumentException
     public   void  testArrivalZeroValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   0 ;     // invalid value of arrival attribute
             int  enter  =   6 ;
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of arrival" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }
    
    @ Test
     // test that if enter attribute is negative throws IllegalArgumentException
     public   void  testEnterNegativeValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   - 1 ;    // invalid value of enter
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of enter" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }
    @ Test
     // test that if enter attribute is zero throws IllegalArgumentException
     public   void  testEnterZeroValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   0 ;    // invalid value of enter
             int  exit  =   8 ;
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of enter" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }    

    @ Test
     // test that if exit attribute is negative throws IllegalArgumentException
     public   void  testExitNegativeValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   6 ;   
             int  exit  =   - 1 ;   // invalid value of exit
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of exit" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }
    @ Test
     // test that if exit attribute is zero throws IllegalArgumentException
     public   void  testExitZeroValue ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   6 ;   
             int  exit  =   0 ;    // invalid value of exit
             new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            fail ( "Constructor should throw exception for invalid value of enter" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }    
    
    @ Test
     // test that if status attribute is something other than one of the constants it throws IllegalArgumentException
     public   void  testStatusInvalidLess ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   6 ;   
             int  exit  =   8 ;    // invalid value of exit
             Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            cust . setStatus ( Customer . CUST_NOT_PROCESSED - 1 );    // less than lowest constant
            fail ( "Constructor should throw exception for invalid value of enter" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }    
    
    @ Test
     // test that if status attribute is something other than one of the constants it throws IllegalArgumentException
     public   void  testStatusInvalidHigher ()
     {
         try   {
             int  id  =   5 ;   
             int  time  =   10 ;
             int  enter  =   6 ;   
             int  exit  =   8 ;    // invalid value of exit
             Customer  cust  =   new   Customer ( id ,  time ,  enter ,  exit );   // new instance of Customer
            cust . setStatus ( Customer . CUST_EXITED + 1 );    // less than highest constant
            fail ( "Constructor should throw exception for invalid value of enter" );    // if get here no exception was thrown
         }   catch   ( Exception  e )   {
             if   ( instanceof   IllegalArgumentException )
                assertTrue ( true );   // if here, caught exception
            else
                 fail ( "Caught exception but it was not IllegalArgumentException as documented" );
         }
     }    
}

TestCustomerBasics.java

TestCustomerBasics.java

import   static  org . junit . Assert . * ;

import  java . lang . reflect . Constructor ;
import  java . lang . reflect . Field ;
import  java . lang . reflect . Method ;
import  org . junit . Test ;

/*
 * Author: Renata Rand McFadden
 * Unit tests for Customer class
 * Checks that Customer class exists with correct attributes, constants, constructors, and methods
 */
public   class   TestCustomerBasics   {

    @ Test
     // Check that there is a class Customer
     public   void  testCustomerClassExists ()   {
         try   {
             Class . forName ( "Customer" );
         }   catch   ( ClassNotFoundException  e )  
         {
            fail ( "Should have a class called Customer" );
         }
     }
    
    @ Test
     // Check that Constructor exists: public Customer(int,int,int,int)
     public   void  testCustomerConstructorExists ()
     {
         boolean  found  =   false ;   
         Constructor  list []   =   Customer . class . getConstructors ();    // get all constructors
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )    // loop through list of Constructors
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public Customer(int,int,int,int)" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a constructor passing all four int values for attributes" );
     }
    
    @ Test
     // Check that Customer has the required attribute: 
     //     private int Customer.id
     public   void  testAttributeId ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Customer.id" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a private id attribute of type integer" );
     }
    
    @ Test
     // Check that Customer has the required attribute: 
     //     private int Customer.arrival
     public   void  testAttributeArrival ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Customer.arrival" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a private arrival attribute of type integer" );
     }
    
    @ Test
     // Check that Customer has the required attribute: 
     //     private int Customer.enter
     public   void  testAttributeEnter ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Customer.enter" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a private enter attribute of type integer" );
     }
    
    @ Test
     // Check that Customer has the required attribute: 
     //     private int Customer.exit
     public   void  testAttributeExit ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Customer.exit" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a private exit attribute of type integer" );
     }
    
    @ Test
     // Check that Customer has the required attribute: 
     //     private int Customer.status
     public   void  testAttributeStatus ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Customer.status" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a private status attribute of type integer" );
     }    

    @ Test
     // Check that Customer has constant called  CUST_NOT_PROCESSED and set to 0
     public   void  testConstantCUST_NOT_PROCESSED ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all variables
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of variables
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public static final int Customer.CUST_NOT_PROCESSED" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public constant called CUST_NOT_PROCESSED" );
        assertEquals ( 0 , Customer . CUST_NOT_PROCESSED );    // check the constant value is correct
     }
    
    @ Test
     // Check that Customer has constant called  CUST_ENTERED and set to 1
     public   void  testConstantCUST_ENTERED ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all variables
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of variables
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public static final int Customer.CUST_ENTERED" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public constant called CUST_ENTERED" );
        assertEquals ( 1 , Customer . CUST_ENTERED );    // check the constant value is correct
     }
    
    @ Test
     // Check that Customer has constant called  CUST_EXITED and set to 2
     public   void  testConstantCUST_EXITED ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all variables
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of variables
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public static final int Customer.CUST_EXITED" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public constant called CUST_EXITED" );
        assertEquals ( 2 , Customer . CUST_EXITED );    // check the constant value is correct
     }
    
    @ Test
     // Check that Customer only has the 5 required attributes and 3 constants: 
     public   void  testAttributeOnlyEight ()
     {
         Field  list []   =   Customer . class . getDeclaredFields ();    // get all attributes
         if   ( list . length  >   8 )
            fail ( "Customer class should only have five attributes and three constants defined" );
     }    

    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.getId()  
     public   void  testMethodGetId ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Customer.getId()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called getId" );
     }
    
    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.getEnter()  
     public   void  testMethodGetEnter ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Customer.getEnter()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called getEnter" );
     }
    
    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.getExit()  
     public   void  testMethodGetExit ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Customer.getExit()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called getExit" );
     }
    
    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.getArrival()  
     public   void  testMethodGetArrival ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Customer.getArrival()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called getArrival" );
     }
    
    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.getStatus()  
     public   void  testMethodGetStatus ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Customer.getStatus()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called getStatus" );
     }

    @ Test
     // Check that Customer has the required methods:
     //    public int Customer.setStatus(int)  
     public   void  testMethodSetStatus ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Customer . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public void Customer.setStatus(int)" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Customer class should have a public method called setStatus with integer parameter" );
     }    
    @ Test
     // Check that Customer only has the required 6 methods 
     public   void  testMethodsOnlySix ()
     {
         Method  list []   =   Customer . class . getDeclaredMethods ();    // get all methods
         if   ( list . length  >   6 )
            fail ( "Customer class should only have six methods defined" );
     }    
}

TestSimulatorAdvanced.java

TestSimulatorAdvanced.java

import   static  org . junit . Assert . * ;

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

import  java . io . ByteArrayInputStream ;
import  java . io . ByteArrayOutputStream ;
import  java . io . File ;
import  java . io . PrintStream ;
import  java . util . ArrayList ;

public   class   TestSimulatorAdvanced   {

     //create local variables for streams
     private   final   ByteArrayOutputStream  outContent  =   new   ByteArrayOutputStream ();
     private   final   ByteArrayOutputStream  errContent  =   new   ByteArrayOutputStream ();

    @ Before
     // runs before each test starts - redirects streams to local variables
     public   void  setUpStreams ()   {
         System . setOut ( new   PrintStream ( outContent ));
         System . setErr ( new   PrintStream ( errContent ));
     }

    @ After
     // runs after each test ends - cleans up streams to defaults
     public   void  cleanUpStreams ()   {
         System . setOut ( null );
         System . setErr ( null );
         System . setIn ( System . in );   //reset System.in to its original
     }
    
    @ Test
     public   void  testMain ()   {
         //SimulatorOld.main(null);
         //MyClass.main(new String[] {"arg1", "arg2", "arg3"});
     }
    
    @ Test
     // Check that get correct prompt from method getStopsFromUser   
     public    void  testgetStopsFromUserPrompt ()
     {
         String  promptMessage  =   "Enter number of stops the train has on its route (must be greater than 1):" ;
         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "7" . getBytes ());
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getStopsFromUser ();    // call method to get number of stops
         String  prompt  =  outContent . toString (). trim ();
        assertEquals ( promptMessage ,  prompt );         
     }
    
    @ Test
     // Test that 0 is caught as invalid input and user gets re-prompted
     public    void  testgetStopsFromUserPromptLoop ()
     {
         String  message  =   "Invalid input, try again" ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "0\n7" . getBytes ());    // input 0 on first prompt and 7 on next
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getStopsFromUser ();    // call method to get number of stops
         String  prompt  =  outContent . toString (). trim ();

        assertTrue ( prompt . contains ( message ));    // check that output has the error message
     }
    
    @ Test
     // Test that non-integer is caught as invalid input and user gets re-prompted
     public    void  testgetStopsFromUserPromptLoop2 ()
     {
         String  message  =   "Invalid input, try again" ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "n\n7" . getBytes ());    // input n on first prompt and 7 on next
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getStopsFromUser ();    // call method to get number of stops
         String  prompt  =  outContent . toString (). trim ();

        assertTrue ( prompt . contains ( message ));    // check that output has the error message
     }
    
    
    @ Test
     // Test that there are two prompts on invalid input
     public    void  testgetStopsFromUserPromptDouble ()
     {
         String  message  =   "Enter number of stops the train has on its route \\(must be greater than 1\\):" ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "n\n7" . getBytes ());    // input n on first prompt and 7 on next
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getStopsFromUser ();    // call method to get number of stops
         String  output  =  outContent . toString ();
 
         int  count  =  output . split ( message ,   - 1 ). length - 1 ;    // count number of occurrences of prompt in output
        assertEquals ( 2 ,  count );   // expect two prompt messages
     }

    @ Test
     // Test that if user presses enter and file not exists, he gets error message
     // MUST NOT HAVE customer file at C:/train/customer-data.txt
     // MUST have src/customer file
     public    void  testgetInputFileDefaultFail ()
     {
         String  message  =   "File not found, try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getInputFile ();    // call method to get file name
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // check that output has the error message
     }
    
    @ Test
     // Test that there is correct prompt for file and enter expects that file
     // MUST HAVE customer file at C:/train/customer-data.txt 
     // If file does not exists, the test will fail with java.util.NoSuchElementException: No line found
     public    void  testgetInputFilePrompt ()
     {
         String  message  =   "Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:" ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "\n" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getInputFile ();    // call method to get file name
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // check that output has the correct prompt
     }
    
    @ Test
     // Test that if user presses enter and file not exists, he gets error message
     // MUST have src/customer file
     public    void  testgetInputFileNotExist ()
     {
         String  message  =   "File not found, try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "blahblah\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getInputFile ();    // call method to get file name
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // check that output has the error message
     }
    
    @ Test
     // Test that if user presses enter and file not exists, there will be multiple prompts
     // MUST have src/customer file
     public    void  testgetInputFilePromptLoop ()
     {
         String  message  =   "Enter absolute path for data file or for default \\(C:\\/train\\/customer-data.txt\\) press Enter:" ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "blahblah\nblah\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
        sim . getInputFile ();    // call method to get file name
         String  output  =  outContent . toString ();
 
         int  count  =  output . split ( message ,   - 1 ). length - 1 ;    // count number of occurrences of prompt in output
        assertEquals ( 3 ,  count );   // expect three prompt messages
     }
    
    @ Test
     // Test that for id < 0, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-id
     // If file does not exists, the test will fail 
     public    void  testCheckFileIdInvalid ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-id\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for id non-integer gets error message 
     // MUST HAVE customer files at src/customer  and src/bad-id2
     // If file does not exists, the test will fail 
     public    void  testCheckFileIdInvalid2 ()
     {
         String  message  =   "Each line must have four integers. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-id2\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that for enter < 1, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-enter
     // If file does not exists, the test will fail 
     public    void  testCheckFileEnterInvalid ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-enter\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for enter non-integer gets error message 
     // MUST HAVE customer files at src/customer  and src/bad-enter2
     // If file does not exists, the test will fail 
     public    void  testCheckFileEnterInvalid2 ()
     {
         String  message  =   "Each line must have four integers. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-enter2\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that for enter > stops, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-enter3
     // If file does not exists, the test will fail 
     public    void  testCheckFileEnterInvalid3 ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-enter3\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for exit < 1, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-exit
     // If file does not exists, the test will fail 
     public    void  testCheckFileExitInvalid ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-exit\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for exit non-integer gets error message 
     // MUST HAVE customer files at src/customer  and src/bad-exit2
     // If file does not exists, the test will fail 
     public    void  testCheckFileExitInvalid2 ()
     {
         String  message  =   "Each line must have four integers. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-exit2\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that for exit > stops, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-exit3
     // If file does not exists, the test will fail 
     public    void  testCheckFileExitInvalid3 ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-exit3\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that for duplicate id, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-dup-id
     // If file does not exists, the test will fail 
     public    void  testCheckFileDupId ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-dup-id\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for enter==exit, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-enter-exit
     // If file does not exists, the test will fail 
     public    void  testCheckFileEnterExit ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-enter-exit\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that for time < 1, get error message 
     // MUST HAVE customer files at src/customer  and src/bad-time
     // If file does not exists, the test will fail 
     public    void  testCheckFileTimeInvalid ()
     {
         String  message  =   "Data in input file is not correct. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-time\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }

    @ Test
     // Test that for time non-integer gets error message 
     // MUST HAVE customer files at src/customer  and src/bad-time2
     // If file does not exists, the test will fail 
     public    void  testCheckFileTimeInvalid2 ()
     {
         String  message  =   "Each line must have four integers. Try again." ;

         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/bad-time2\nsrc/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
         String  output  =  outContent . toString ();
 
        assertTrue ( output . contains ( message ));    // passes if message is in output
        assertTrue ( "Expected list==null" , list == null );
     }
    
    @ Test
     // Test that get correct customer list 
     // MUST HAVE customer files at src/customer  
     // If file does not exists, the test will fail 
     public    void  testCheckFileCustomerList ()
     {
         boolean  found  =   true ;
         ByteArrayInputStream  in  =   new   ByteArrayInputStream ( "src/customer" . getBytes ());    // input enter
         System . setIn ( in );

         Customer  c1  =   new   Customer ( 1 ,   1 ,   1 ,   2 );
         Customer  c2  =   new   Customer ( 2 ,   2 ,   1 ,   3 );
        
         Simulator  sim  =   new   Simulator ();    // new instance of Simulator
         File  file  =  sim . getInputFile ();    // call method to get file name
         ArrayList < Customer >  list  =  sim . checkFile ( 7 , file );
        
         if   ( list . get ( 0 ). getId ()   !=  c1 . getId ()   ||  list . get ( 0 ). getArrival ()   !=  c1 . getArrival ()
                 ||  list . get ( 0 ). getEnter ()   !=  c1 . getEnter ()   ||  list . get ( 0 ). getExit ()   !=  c1 . getExit ())    
            found  =   false ;
         if   ( list . get ( 1 ). getId ()   !=  c2 . getId ()   ||  list . get ( 1 ). getArrival ()   !=  c2 . getArrival ()
                 ||  list . get ( 1 ). getEnter ()   !=  c2 . getEnter ()   ||  list . get ( 1 ). getExit ()   !=  c2 . getExit ())    
            found  =   false ;
 
        assertTrue ( "Expected list with 2 customers" ,  found );    // passes if message is in output
     }
        
}

TestSimulatorBasics.java

TestSimulatorBasics.java

import   static  org . junit . Assert . * ;

import  java . lang . reflect . Constructor ;
import  java . lang . reflect . Method ;
import  org . junit . Test ;

/*
 * Author: Renata Rand McFadden
 * Unit tests for Simulator class
 * Checks that Simulator class exists with correct attributes, constants, constructors, and methods
 */
    
public   class   TestSimulatorBasics   {

    @ Test
     // Class exists
     public   void  testSimulatorClassExists ()   {
         try   {
             Class . forName ( "Simulator" );
         }   catch   ( ClassNotFoundException  e )  
         {
            fail ( "Should have a class called Simulator" );
         }
     }
    
    @ Test
     // Only builtin constructor exists with no parameters
     public   void  testSimulatorConstructorExists ()   {
         Constructor  list []   =   Simulator . class . getConstructors ();    // get all constructors
         if   ( list . length  >   1 )
            fail ( "Simulator class should only have builtin constructor" );

     }

    @ Test
     // Check that Simulator has the required methods:
     //    public int Simulator.getStopsFromUser()  
     public   void  testGetStopsFromUserExists ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Simulator . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public int Simulator.getStopsFromUser()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Simulator class should have a public method called getStopsFromUser with no parameters" );
     }
    
    @ Test
     // Check that Simulator has the required methods:
     //    public File Simulator.getInputFile()  
     public   void  testGetInputFileExists ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Simulator . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public java.io.File Simulator.getInputFile()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Simulator class should have a public method called getInputFile with no parameter that returns File" );
     }
    
    @ Test
     // Check that Simulator has the required methods:
     //    public ArrayList<Customer> Simulator.checkFile(int stops, File file)  
     public   void  testCheckFileExists ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Simulator . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public java.util.ArrayList Simulator.checkFile(int,java.io.File)" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Simulator class should have a public method called checkFile with two parameter and returns ArrayList<Customer>" );
     }
    
    @ Test
     // Check that Simulator has the required methods:
     //    public void Simulator.run(int,ArrayList<Customer>)  
     public   void  testRunExists ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Simulator . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public void Simulator.run(int,java.util.ArrayList)" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Simulator class should have a public method called run with 2 parameters - int and ArrayList<Customer>" );
     }
    
    @ Test
     // Check that Simulator has the required methods:
     //    public static void Simulator.main(String[])  
     public   void  testMainExists ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Simulator . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public static void Simulator.main(java.lang.String[])" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Simulator class should have a public method called main with String array parameter" );
     }
    
    @ Test
     // Check that Simulator only has the required 5 methods 
     public   void  testMethodsOnlyFive ()
     {
         Method  list []   =   Simulator . class . getDeclaredMethods ();    // get all methods
         if   ( list . length  >   5 )
            fail ( "Simulator class should only have four methods defined" );
     }

}

TestTrainAdvanced.java

TestTrainAdvanced.java

import   static  org . junit . Assert . * ;

import  java . io . ByteArrayOutputStream ;
import  java . io . PrintStream ;
import  java . util . ArrayList ;

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


public   class   TestTrainAdvanced   {

     //create local variables for streams
     private   final   ByteArrayOutputStream  outContent  =   new   ByteArrayOutputStream ();
     private   final   ByteArrayOutputStream  errContent  =   new   ByteArrayOutputStream ();

    @ Before
     // runs before each test starts - redirects streams to local variables
     public   void  setUpStreams ()   {
         System . setOut ( new   PrintStream ( outContent ));
         System . setErr ( new   PrintStream ( errContent ));
     }

    @ After
     // runs after each test ends - cleans up streams to defaults
     public   void  cleanUpStreams ()   {
         System . setOut ( null );
         System . setErr ( null );
         System . setIn ( System . in );   //reset System.in to its original
     }

    @ Test
     // Test that constructor does not fail when called
     public   void  testConstructor ()   {
         int  stops  =   5 ;
         ArrayList < Customer >  list  =   new   ArrayList < Customer > ();    // empty list
         Train  tr  =   new   Train ( stops ,  list );   // new instance of Train
        assertTrue ( true );    // if line executed then there was no exception
     }
    
    @ Test
     // Test that displayStops() prints current values of madeStops and time
     // Before simulation runs they should be both 0
     public   void  testDisplayStops ()   {
         String  output  =   "Train made 0 stops and it took 0 time units to process all customers" ;
         int  stops  =   5 ;
         ArrayList < Customer >  list  =   new   ArrayList < Customer > ();    // empty list
         Train  tr  =   new   Train ( stops ,  list );   // new instance of Train
        tr . displayStops ();
         String  out  =  outContent . toString (). trim ();
        assertEquals ( output ,  out );
     }
    
    @ Test
     // Test that constructor updates stops and custList attribute correctly
     // As there is no get method for it, we test it indirectly through simulate
     // We create a customer for that stop and if output is as expected, we know attributes were initialized
     public   void  testConstructorStopsAndList ()   {
        
         // expected output
         String  message1  =   "Current Time=5 Current Stop=5" ;
         String  message2  =   "Customer enters train: id=1" ;
         String  message3  =   "Current Time=6 Current Stop=1" ;
         String  message4  =   "Customer exits train: id=1" ;
        
         boolean  found  =   true ;    // flag to check if all outputs there
        
         int  stops  =   5 ;    // set stops to some value and make sure that have customer 
         ArrayList < Customer >  list  =   new   ArrayList < Customer > ();    // empty list
         Customer  cust  =   new   Customer ( 1 , 1 , 5 , 1 );    // create instance of customer
        list . add ( cust );    // add customer to list
        
         Train  tr  =   new   Train ( stops ,  list );   // new instance of Train
        tr . simulate ();
         String  out  =  outContent . toString (). trim ();    // capture output
        
         // if any of the messages are not in output, found flag will be false
         if   ( ! out . contains ( message1 ))    found  =   false ;
         else   if   ( ! out . contains ( message2 ))    found  =   false ;
         else   if   ( ! out . contains ( message3 ))    found  =   false ;   
         else   if   ( ! out . contains ( message4 ))    found  =   false ;
        
        assertTrue ( found );    // assert if any messages are not there or different
     }
    
    @ Test
     // Test that displayStops method uses the attribute values
     // As there is no get method for it, we test it indirectly through simulate
     public   void  testDisplayStopsAfterSimulate ()   {
        
         // expected output
         String  message  =   "Train made 2 stops and it took 6 time units to process all customers" ;

         int  stops  =   5 ;    // set stops to some value and make sure that have customer 
         ArrayList < Customer >  list  =   new   ArrayList < Customer > ();    // empty list
         Customer  cust  =   new   Customer ( 1 , 1 , 5 , 1 );    // create instance of customer
        list . add ( cust );    // add customer to list
        
         Train  tr  =   new   Train ( stops ,  list );   // new instance of Train
        tr . simulate ();
        tr . displayStops ();
         String  out  =  outContent . toString (). trim ();    // capture output
        
        assertTrue ( out . contains ( message ));
     }

}

TestTrainBasics.java

TestTrainBasics.java

import   static  org . junit . Assert . * ;

import  java . lang . reflect . Constructor ;
import  java . lang . reflect . Field ;
import  java . lang . reflect . Method ;

import  org . junit . Test ;

/*
 * Author: Renata Rand McFadden
 * Unit tests for Train class
 * Checks that Train class exists with correct attributes, constructors, and methods
 */
public   class   TestTrainBasics   {

    @ Test
     // Check that there is a class Train
     public   void  testCustomerClassExists ()   {
         try   {
             Class . forName ( "Train" );
         }   catch   ( ClassNotFoundException  e )  
         {
            fail ( "Should have a class called Train" );
         }
     }
    
    @ Test
     // Check that Constructor exists: public Customer(int,int,int,int)
     public   void  testTrainConstructorExists ()
     {
         boolean  found  =   false ;   
         Constructor  list []   =   Train . class . getConstructors ();    // get all constructors
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )    // loop through list of Constructors
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public Train(int,java.util.ArrayList)" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a constructor with stops and custList values for attributes" );
     }
    
    @ Test
     // Check that Train has the required attribute: 
     //     private ArrayList<Customer> Train.custList
     public   void  testAttributeCustList ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Train . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private java.util.ArrayList Train.custList" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a private custList attribute of type ArrayList<Customer>" );
     }
    
    @ Test
     // Check that Train has the required attribute: 
     //     private int Customer.stops
     public   void  testAttributeStops ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Train . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Train.stops" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a private stops attribute of type integer" );
     }
    
    @ Test
     // Check that Train has the required attribute: 
     //     private int Train.madeStops
     public   void  testAttributeMadeStops ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Train . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Train.madeStops" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a private madeStops attribute of type integer" );
     }
    
    @ Test
     // Check that Train has the required attribute: 
     //     private int Train.currTime
     public   void  testAttributeCurrTime ()
     {
         boolean  found  =   false ;   
         Field  list []   =   Train . class . getDeclaredFields ();    // get all attributes
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "private int Train.currTime" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a private currTime attribute of type integer" );
     }
    
    @ Test
     // Check that Train only has the 4 required attributes: 
     public   void  testAttributeOnlyFour ()
     {
         Field  list []   =   Train . class . getDeclaredFields ();    // get all attributes
         if   ( list . length  >   4 )
            fail ( "Train class should only have three attributes" );
     }    

    @ Test
     // Check that Train has the required methods:
     //    public void Train.simulate()  
     public   void  testMethodSimulate ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Train . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public void Train.simulate()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a public method called simulate" );
     }
    
    @ Test
     // Check that Train has the required methods:
     //    public void Train.displayStops()  
     public   void  testDisplayStops ()
     {
         boolean  found  =   false ;   
         Method  list []   =   Train . class . getDeclaredMethods ();
         for ( int  i  =   0 ;  i  <  list . length ;  i ++ )   // loop through list of attributes
         {
             String  value  =   "" + list [ i ];   // convert to string
             if   ( value . contentEquals ( "public void Train.displayStops()" ))
                found  =   true ;
         }
         if   ( ! found )
            fail ( "Train class should have a public method called displayStops" );
     }
    
    @ Test
     // Check that Train only has the required 3 methods 
     public   void  testMethodsOnlySix ()
     {
         Method  list []   =   Train . class . getDeclaredMethods ();    // get all methods
         if   ( list . length  >   3 )
            fail ( "Train class should only have three methods defined" );
     }    

}

Project6-Train-SDS (1).doc

Software Design Specification

for

Simple Train Simulator

Version 3.0

Prepared by Leva Kurginyan;

Modified by Dr Rand Mcfadden

<05/09/2015>

Table of Contents

11. Introduction

1.1 Purpose 1

1.2 Intended Audience and Reading Suggestions 1

1.3 Product Scope 1

1.4 Overview 1

2. Design Considerations 2

2.1 Assumptions and Dependencies 2

2.2 General Constraints 2

2.3 Development Methods 2

3. System Architecture 2

3.1 High level Overview of System Architecture (class diagram) 2

4. Human Interface Design 4

4.1 Interface description. 4

4.2 Screenshots of Interface 4

4.2.1 Prompt for stops and loop if incorrect 4

4.2.2 Prompt for pathname and loop if not exist 5

4.2.3 Check input data and loop if incorrect 5

4.2.4 Display output as simulation runs 5

5. Detailed System Design 6

5.1 Simulator Class 6

5.2 Train class 8

5.3 Customer class 10

Revision History

Name

Date

Reason For Changes

Version

Leva Kurginyan

07/22/14

Instructor’s feedback updated to Elevator Simulation

1.1

Renata Rand Mcfadden

07/24/14

Modified for Train Simulation

2.0

Renata Rand McFadden

05/09/2015

Modified for TDD Project

3.0

1. Introduction

1.1 Purpose

This is the Software Design Specification for the simple Train Simulator. This document will define the design of the simulator, by breaking down the project into components to describe in detail what the purpose of each component is and how it will be implemented. It will contain specific information about the expected input, output, and functionality. Also it will explain system constraints, assumptions, dependencies and interface.

1.2 Intended Audience and Reading Suggestions

This Software Design Specification is intended for:

· Development team who will develop the first version of the system.

· Developers who can review project’s capabilities and more easily understand where their efforts should be targeted to improve or add more features to it.

· Product testers can use this document as a base for their testing strategy. Also it might be used as a tool for verification and validation of the final product.

1.3 Product Scope

Simple Train Simulator system will be a simple train simulation, implemented with object-oriented approach using Java. It will simulate a train traveling to multiple stops (in a loop starting at stop 1 to stop N) with customers entering and exiting the train. The train will not stop if there are no customers waiting to enter or exit the train at that stop.

User of the program will need to input how many stops the train will have and the absolute path of text file with all customer data. While the simulation is running, it will display data to the console with train stops and customers entering and leaving the train. At the end of the simulation, the program will display how many stops it made to service all customers.

1.4 Overview

The remainder of this document includes 4 chapters.

· The second one introduces system constraints and assumptions about the product.

· The third chapter gives high level overview of system architecture.

· The fourth chapter provides the description of the system interface.

· The final fifth chapter provides detailed system design inclooding main data structures, atributes, and metodes used in each class.

2. Design Considerations

2.1 Assumptions and Dependencies

None.

2.2 General Constraints

Implementation environment

Project must be written in Java using Object Orientated approach.

Hardware

None.

2.3 Development Methods

Simple Train Simulator must be implemented using Object Orientated approach.

3. System Architecture

3.1 High level Overview of System Architecture (class diagram)

The three main components of Simple Train Simulator are: Simulator class, Train class and Customer class. Simulator is responsible for prompting and parsing user input data and running simulation. It creates an instance of Train class and N number (depending on data file) of instances of Customer class. It then runs the Train methods for the simulation.

image1

Simulator – prompts user for number of stops and the input file with customer data. Parses the file and created a list of customers using Customer class. Creates an instance of Train and runs its methods for the simulation.

Customer – stores the four values parsed from file (id, arrival, enter, exit) for the customer. Sets up constants and status variable to determine status where CUST_NOT_PROCESSED means the customer has not been processed yet; CUST_ENTERED means_ the customer is on the train; and CUST_EXITED means the customer was processed and left the train.

Train - stores the number of stops train will have and the customer list. It also has an attribute for storing how many stops the train made as it processed the customers. The Simulator will create an instance of Train and set these values using the constructor. The simulate() method runs the strategy printing the appropriate output. The displayStops method prints the message with the number of stops the train made to process all customers and how long it took.

4. Human Interface Design

4.1 Interface description.

1. Simple Train Simulator will have text based user interface with textual output and textual prompts where user needs to type in a response.

2. When program starts, user gets prompted for number of stops the train has on its route: Enter number of stops the train has on its route (must be greater than 1): ”.

3. On invalid input, user will get error message “ Invalid input, try again. " and will be prompted to enter the number of stops again.

4. On correct input user gets prompted for customer data file name: “ Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter: ”.

5. If file does not exist, user will get error message “ File not found, try again. " and will be prompted to input the file path again.

6. If file has non-integer as one of the first four values, user will get error message “ Each line must have four integers. Try again.” and will be prompted to input the file path again.

7. If any of the data in the customer file is not valid, user will get error message “ Data in input file is not correct. Try again.” Then user will be prompted to enter another file path.

8. After user inputs all necessary correct information simulation begins.

9. During simulation information about each step of simulation (current time, current stop, customers entering train and customers leaving train) is printed out for user.

10. When simulation is done information about number of stops that were made and how long it took is printed out. The display will be “ Train made x stops and it took y time units to process all customers ” with x and y the actual values from the simulation

11. Program terminates.

4.2 Screenshots of Interface

4.2.1 Prompt for stops and loop if incorrect

Enter number of stops the train has on its route (must be greater than 1): 0

Invalid input, try again

Enter number of stops the train has on its route (must be greater than 1):

Enter number of stops the train has on its route (must be greater than 1): n

Invalid input, try again

Enter number of stops the train has on its route (must be greater than 1):

4.2.2 Prompt for pathname and loop if not exist

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

blah

File not found, try again.

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

4.2.3 Check input data and loop if incorrect

# id numbers are duplicate in input file (same for other constraints)

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

C:/train/customer-bad-id.txt

Data in input file is not correct. Try again.

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

# non-integer in the input file

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

C:/train/customer-bad-arrival2.txt

Each line must have four integers. Try again.

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

4.2.4 Display output as simulation runs

For input file (C:\train\customer-data.txt) with contents:

10 1 1 5

11 1 2 5

12 3 3 1

13 10 4 6

Output is:

Enter number of stops the train has on its route (must be greater than 1): 7

Enter absolute path for data file or for default (C:/train/customer-data.txt) press Enter:

Current Time=1 Current Stop=1

Customer enters train: id=10

Current Time=2 Current Stop=2

Customer enters train: id=11

Current Time=3 Current Stop=3

Customer enters train: id=12

Current Time=5 Current Stop=5

Customer exits train: id=10

Customer exits train: id=11

Current Time=8 Current Stop=1

Customer exits train: id=12

Current Time=11 Current Stop=4

Customer enters train: id=13

Current Time=13 Current Stop=6

Customer exits train: id=13

Train made 7 stops and it took 13 time units to process all customers

5. Detailed System Design

5.1 Simulator Class

This class is responsible for:

· Prompting user for all necessary inputs

· Reading data file and parsing it

· Checking for invalid input

· Creating and storing instances of Customer class into ArrayList

· Creating an instance of Train class

· Running simulation by calling Train’s simulate method

Attributes None

Methods

Method

Description

main()

Runs the program

void run(int, ArrayList<Customer>)

int getStopsFromUser()

Prompts user for number of stops, checks for invalid data and re-prompts, returns the valid value of stops

File getInputFile()

Prompts user for input file and checks that file exists. Loops prompting until user gives path for existing file.

ArrayList<Customer> checkFile(int stops, File)

Parses and checks for invalid data. If file has anything invalid, it returns null list. If file has valid values, creates instances of Customer and creates an ArrayList of type Customer and returns the list

Uses/Interactions

Creates instance of Train class.

Creates instances of Customer class - as many as necessary based on data file.

Simulator class is not used by any other class

Constraints

· Number of stops for the train must be entered as numeric (integer) value and greater than 1.

· Data file, which is specified by user, must exists and have correct data for each customer.

· Customer data constraints:

· Each customer must have a unique id, greater than 1, and it must be an integer

· The arrival time at the train must be greater than 0 and must be an integer. It represents the time the customer arrives at the train.

· The enter stop value must be greater than 0 and an integer. It has to be less than or equal to the highest stop the train has. It representing the stop number of the train where customer wants to enter the train. Stops start at 1 and go up to the N stops that user specified.

· The exit stop value must be greater than 0 and integer. It has to be less than or equal to the highest stop the train has. It representing the stop number of the train that customer wants to exit the train.

· Customer cannot enter and exit the train at the same stop.

Resources

The only resource that is used by this class is data file specified by user.

Processing

getStopsFromUser(): int

1. Prompts user to enter number of stops.

2. Checks input (must be integer > 1) and gives error message if it is not. Loops until correct value is entered.

3. Returns the obtained value to caller

getInputFile(): File

1. Loop until the path given is for file that exists

a. Prompts user for the input file path

b. If no file is given (user presses enter) then use the default path name (C:/train/customer-data.txt)

c. Use given path to create File instance

d. Checks if file exists.

e. If file does not exist gives an error message and loop until correct path is entered.

2. Return File instance

checkFile(int stops, File file): ArrayList<Customer>

1. Creates empty list (ArrayList<Customer> list)

2. In while loop

a) Reads file line by line

b) Parses the four integer values per line

c) Checks data that it meets the above constraints. If data is incorrect, stops parsing, gives error message, and returns null

d) Creates instance of customer class (using data from single line from data file)

e) Stores instance of customer into list.

f) Exits loop when no more lines to read.

3. Returns list

run(int stops, ArrayList<Customer> custList):

1. Create an instance of Train and pass through constructor stops and custList

2. Call Train’s simulate method

3. Call Train’s displayStops method

main() method:

1. Creates an instance of Simulation class

2. Creates custList of type ArrayList<Customer> and assigns null

3. Calls Simulator’s getStopsFromUser() method and saves the return value in variable (stops)

4. Loops as long as custList is null

a. Calls Simulator’s getInputFile() method. Save the returned File instance

b. Call Simulator’s checkFile() method passing it stops and instance of File. Save returned value in custList

5. Call Simulator’s run method passing it the stops and custList

5.2 Train class

This class is responsible for:

· Picking up customers

· Dropping off customer

· Moving train (one stop at a time)

· Calculating number of stops and the time it took for train to process all customers made and to print out results.

Class Attributes

Attribute

Description

stops : int

Used to store the number of stops train has on its route.

madeStops: int

Used to store number of stops the train made to process all customers.

currTime: int

Used to store the time for the train made to process all customers.

custList : arrayList<Customer>

Used to store list of customers to process in the simulation.

Methods

Method

Description

Train(int, ArrayList<Customer>)

Constructor to pass values of stops and customer list from Simulator and to initialize Train’s attributes

simulate()

Runs the train and processes customers entering and exiting the train. Train starts at stop 1 and travels to stop N. The route is a loop so then the train goes to stop 1 again and it keeps running until there are no more customers to process.

displayStops()

Displays the message of how many stops the train made and how long it took to process all customers

Uses/Interactions

The only class that uses “Train” class is the “Simulator” class. Train uses Customer class as it processes the list

Constraints

Preconditions – all necessary values are passed to instance of Train class by Simulator class (stops, custList).

Processing

· Train() constructor:

· All attributes are initialized

· simulate() method:

· Train starts running at current time = 1 and current stop =1.

· Make loopAgain = true (Boolean to control the loop)

· Loop until no more customers to process

· Loop for each customer in the list

· Check if there is any customers to process (status does not equal Customer CUST_EXITED). If yes then make loopAgain set to true so that when finishes processing this iteration, goes through loop again

· Print message with current time and current stop only if there is customer to enter or exit the train

· If customer not processed yet and his arrival time is less than or equal to current time and his enter stop is same as current stop, have customer enter the train (customer’s status gets set to Customer.CUST_ENTERED). Print message about customer entering train.

· If customer is in train already (status== Customer.CUST_ENTERED) and exit stop is equal to current stop, have customer exit the train (status gets set to Customer.CUST_EXITED). Print message about customer exiting train.

· If a customer entered or exited train, then increment by 1 the madeStop and update currTime

· Increment local variable keeping track of time and local variable to keep track of current stop

· If current stop == last stop (N), assign 1 to current stop for the train to loop

· displayStops() method:

· Print message “Train made X stops and it took Y time units to process all customers” using value of madeStops for X and value of currTime for Y.

5.3 Customer class

This class is responsible for storing and returning (when it is requested) customer information such as customer id, arrival time, enter stop, exit stop, and customer’s status.

Constants

Constant

Description

CUST_NOT_PROCESSED: static final int

Assigned value of 0 and means customer has not been processed yet

CUST_ENTERED: static final int

Assigned value of 1 and means customer entered the train

CUST_EXITED: static final int

Assigned value of 2 and means customer exited the train and is done processing

Attributes

Attribute

Description

id : int

Used to store customer’s ID

arrival : int

Used to store customer’s arrival time at the train

enter : int

Used to store the stop that customer will enter train

exit : int

Used to store the stop that customer will exit train

status : int

Used to track customer’s status using the constants

Methods

Method

Description

Customer(int Custid, int arrivalTime, int enterStop, int exitStop)

Constructor method to set attributes passed from Simulator

It also sets status attribute to CUST_NOT_PROCESSED

void setStatus(int status)

Used to set customer’s status to the value passed by caller.

int getStatus()

Returns customer’s current status

int getId()

Returns customer’s ID

int getArrival()

Returns customer’s arrival time

int getEnter()

Returns entered stop

int getExit() 

Returns exit stop

Uses/Interactions

Customer class is used by Simulator and Train classes.

This class does not use any other classes.

Constraints

All constraints are already described under Simulator class

Processing

· All attributes are initialized by constructor method.

· When getId() method is called it returns value of id attribute.

· When getArrival () method is called it returns value of arrival attribute

· When getEnter () method is called it returns value of enter attribute

· When getExit () method is called it returns value of exit attribute

· When getStatus () method is called it returns value of status attribute

· When setStatus(status) method is called it sets passed parameter value as a value of “status” attribute.

Copyright © 1994-1997 by Bradford D. Appleton. Permission is hereby granted to make and distribute verbatim copies of this document provided the copyright notice and this permission notice are preserved on all copies.(SDS sections)

Modified by Dr Renata Rand McFadden

image2.png

Project6-Instructions.docx

Project 6

Software Implementation

Using Test Driven Development

Mission:

You were hired to implement usingJava a Train system simulation, designed by a developer who suddenly left the team. You are provided with the design specification document (Project6-Train-SDS.doc) and unit test suite (tests.zip). You are to assume that design description is correct for what each class and method is supposed to do and so are the JUnit tests and your Java code is supposed to match them.

Objectives:

You must implement the system using the given design and make sure that all the unit tests pass against your code. Your program must implement the complete design to include all the classes, methods, constructors, constants, and attributes, and the input and output specification exactly. You cannot redesign or change the system.

Steps:

· Create a new project in Eclipse and import the unit tests (tests.zip) and data files into your projects src. Add JUnit library to your Eclipse project

· Note that you will have syntax errors in the tests until you create all the classes

· The unit test suite is divided into the basic and advanced tests for each Java class.

· You should first implement (for each class) the attributes, constants, and empty methods (method signatures) to pass the basic tests.

· Then you should start implementing each method running the appropriate tests against it.

· To run an individual test, highlight the test method name, right click on it, select “Run As” and select “JUnit Test”

· Train’s simulate method has been implemented for you. Copy and paste the code in simulate.txt to your Train class.

· Run the code and unit tests against them until all defects are fixed

· For default file tests under TestSimulatorAdvanced you will need to run them individually with and without that file being on your system (C:/train/customer-data.txt). Check comments for tests which tests require the file and which not

· Once all the unit tests are working, create a sample input file and run the program with it. Capture the screenshot of the output

· Warning: If you use Scanner for reading console and/or file, do not close it because when you try to use again it will not work.

Resources:

Proj6-MSIT660-GradingCriteria.doc – lists the grading criteria

You can use any code examples under My Course Content->Code Examples

Deliverables:

· Your program files - all .java files (one java file per class)

· Sample data file – data.txt

· Output screenshot – paste into Word doc – your-name-Output.docx