Test-based programming Ask: “What should this software do?” Write a test first “Does this software do X correctly?” Fill in the code, and keep working until the test runs successfully
Designing a ‘Simple’ Computational Program Static Beam Deflection Exaggerated beam deflection
Desired Output Prediction of shape of beam deformed under static load More specific:
Necessary Inputs
Necessary Mathematics Math is what will connect the inputs and outputs
Mathematical Steps Translate inputs into mathematical terms (boundary conditions, loads) Solve the differential equation (numerically) Parse the numerical output to get user- desired output
Generality Hardest part of starting numerical code is finding the right level of generalization to start coding with too general means it takes too long to get going too specific can mean substantial investment in risky re-engineering later Rule of thumb: structure for the most common range of cases first, and get it running Re-engineering may never happen (false cost) may be easier after your experience (inflated cost) will have test cases (makes re-writing more reliable)
Generality in Beam Problem Beam Structure/Supports Mathematical Solving Technique
Implement first for cantilevered beams Initial conditions are Beam Structure/Supports
Loads are difficult to input as functions hard to input as a list of points with forces harder to integrate numerically with point forces For a first run, we’ll assume q(x) is uniform (constant) Range of Loads
Designing the software Need user input, mathematical formulation, solving, and expressing user output Will code in object oriented format, with beam being an object
Designing the software II
Necessary Functions
Where to test Remember, it’s good practice to think of the test before the code!
Where to test Remember, it’s good practice to think of the test before the code!
What are the tests? Input/Output for beam Integration Module
Test code vs. Functional Code
Implementation in Java
Getting Started with Java Download the Java Development Kit (JDK) (not the run-time environment, which just lets you run programs, not write them) Follow the tutorials to get a “Hello, world” program running Read up on the fundamentals of object-oriented programming Keep in mind: Once you get into programming, you don’t need to understand every line of someone else’s code imitation (also known as cut and paste) is the sincerest form of flattery. If appropriate, simply cite the source.
For next class Get Java running on a machine you can use Get a working program running Get the scaffold for a ‘beam’ class, which has inputs for the cantilevered case No internals need to be written yet Read the JUnit descriptions (as much as makes sense to you) Come with questions!
Resources Beam deflection Java Tutorials JUnit