Introduction |
This programming assignment is designed to ensure that you know how to write
simple programs that combine expressions (arithmetic, relational, logical,
textual, and state-change operators, as well as input/output methods)
and standard statements (declaration, expression, block, if, loop, break).
It also introduces iterative-enhancement, a divide-and-conquer
approach to writing, testing, and debugging programs; we will cover this
approach in more detail in a lecture soon.
You will write just two programs in this assignment (during the first few
weeks, I want to ensure that you have adequate time to read the lectures
and work their problems; as the lectures get shorter, the programming
assignments get longer).
Programming assignments typically are linked to executable solutions. That is, you can download and run these Executables to help you understand the specification of the problem and observe the programmer/user interaction you are to implement. But, you cannot examine the their underlying Java code. If you need a data file to run the program, it will appear here too; use it for the executable solution and the program you write. Copy the input/output form of the executable programs; use exactly the same prompts and messages. On a PC, you can run the application just by double-clicking the file named double click me.bat. You can run the Application.jar file in Eclipse (on any platform) by making project of the executable folder named darts or rocket (just one of these). Then, disclose the default package, and right click Application.class, and then select Run As and Java Application. Write each program in its own project folder: you should name them accordingly (e.g., darts and rocket); then put both folders in another folder whose name combines your names (when programming in pairs) and the program number (e.g., pattis-stehlik-2). Then zip this folder and dropoff that single zip file. Each pair should submit one project: either partner can submit it.
IMPORTANT: Create new, empty projects for each of these programs.
You must add the line
|
Calculating pi with Darts |
Write a program that performs the following tasks.
To simulate throwing darts, develop an expression that returns a result in the range -1.0 to +1.0 that calls the Math.random method, which returns a result between 0.0 and 1.0, and use this expression when generating the x and y coordinates. Doing so ensures that both coordinates are within the square. Use a boolean expression to determine whether or not the coordinates of the dart are inside or outside the circle that is inscribed in the square (remember some geometry). Design, code, test, and debug this program using iterative-enhancement, as 6 mini-projects. Test each project to ensure that it is correct before proceeding to the next enhancement. This is the same methodology that we will use for larger programs; so, it is a good idea to practice this technique here, where the program is small, even if you can write the entire program all at once. Later, we will discuss this technique in greater depth. Before starting to write your program, run mine executable a few times to familiarize youself with its input and output.
|
Simulating the Flight of a Rocket |
Write a program that performs the following tasks.
th - cd v2 a = ------------- - g mWe recompute this formula for every time interval during the simulation. In it a, the acceleration for that time interval, is computed from
Design, code, test, and debug this program using iterative-enhancement, as 6 mini-projects. Test each project to ensure that it is correct before proceeding to the next enhancement. This is the same methodology that we will use for larger programs; so, it is a good idea to practice this technique here, where the program is small, even if you can write the entire program all at once. Later, we will discuss this technique in greater depth. Before starting to write your program, run mine executable a few times to familiarize youself with its input and output.
Hand in only the final enhancement of the program: the one meeting these complete specifications (note that the program you submit SHOULD NOT print any intermediate results unless the user explicitly requests tracing). Test your debugged/completed program for a thrust of 100 lbs, a time of 10 secs, and a mass of 1 lb and compare it to the results of my excutable; for full credit your results should match exactly (certainly to most of the many digits printed by a double). |