Question: Java using BlueJ Project 3: Fun with Curve Math 1 Objective This project will require indefinite loops to do its work. You will also get

Java using BlueJ

Java using BlueJ Project 3: Fun with Curve Math 1 Objective Thisproject will require indefinite loops to do its work. You will alsoget a chance to display information to, and gather input from, theuser. The project's subject matter ties in nicely with the math that

Project 3: Fun with Curve Math 1 Objective This project will require indefinite loops to do its work. You will also get a chance to display information to, and gather input from, the user. The project's subject matter ties in nicely with the math that you have studied. It will also test your ability to design your approach, develop incrementally, and test. 2 Background We are working with a parabola specified by this equation: f(x) = -(x2) + 25 with x's domain in the range 0 to 5 (inclusive). The partial parabola looks like this: Parabola: f(x) = -(x2)+25 30 25 20 15 10 5 0 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5 For example, when the x coordinate is 4, the y coordinate is -(42) + 25 = -16 + 25 = 9 The slope of the line at a given point is given by: f'(x) = -2x (determined using limits or calculus), so for example when the x coordinate is 2.5, the slope of the line is 2.2.5 = -5. 3 Area Estimation The area under the curve can be estimated by using a series of n rectangles, each of which starts at a calculated value of x, with a width specified by 5 (x's maximum domain divided by how many rectangles we are using) and the rectangle's left-side y determined by the parabola's defining equation. This is called a Left Riemann Sum. Note the number of rectangles might be greater than the x domain, e.g., 15 when x the graph crosses the x axis at 5 as shown below. Were we to visualize the estimation for five rectangles, it would look like this: Parabola: f(x) = -(x2)+25 30 25 20 Area = f(0) * 5 = (-(02)+25)*1 = (0+25)*1= 25 Area = f(1) * 5 = (-(12)+25)*1 = (-1 +25)*1= 24 15 Area f(2) * 5 - (-122)+25)*1 = (-4+25)*1= 21 10 Area = f(3) 5 (-(32)+25)*1 (-9 +25)*1= 16 5 Area = f(4) 5 = 9 0 1 2 3 4 5 0.25 0.5 0.75 1.25 1.5 1.75 2.25 2.5 2.75 3.25 3.5 3.75 4.25 4.5 4.75 The total area is the sum of the areas of all the rectangles, in this case 25 + 24 + 21 + 16 + 9 = 95. The more rectangles one uses, the closer the resulting estimation to the actual area. Note that in this example there are a lot of integers; that will not always be the case, e.g., for n>r. Be careful with this. The actual area as determined by limits or calculus is: (125 - - = 83.33. So, after we calculate the area using rectangles, we can tell how far off the estimate is. In this case it's 14% too big; the overestimation is apparent from the graph, in fact. 125 4 User Interface Display this menu: Parabola Calculations Menu 1. Find y for a given x 2. Find the slope of the tangent line at a given x 3. Calculate area estimate 4. Exit the program Enter your choice: Keep the user within the menu system until they choose to exit, i.e., they can do more than activity while they are there. If the user enters an integer outside the range of valid menu choices or an invalid data type, tell them they have made an error. More details about the menu choices: 1. Ask the user for an x coordinate, then report to them the corresponding y value. 2. Ask the user for an x coordinate, then report to them the slope of the tangent line. 3. Ask the user how many rectangles to use, then report to them the calculated area and how far off the calculation is from the actual. 4. Exits gracefully (not artificially) from the program (i.e., a loop should end, you should not forcibly terminate the program or break out of the loop). 4.1 Gathering User Input Use a Scanner object to get keyboard input from the user. . 5 Code Implementation Create two separate classes, one that deals with the user, and one that does the math computations. Examples of this type of code division can be found in MyMath.java and TestMyMath.java. Follow the Course Style Guide. 5.1 Parabola Calc Class This class should have no user communication'; it is purely a supplier of calculation functions. There should be no main method here. Write static methods for calculations that accept parameters and return results. Provide three public methods, one for each of the specified calculations. Helper functions may be created. Functions must implement precondition tests on parameter values and throw exceptions when appropriate (see section 4.4 in your text). 5.2 Parabola App Class This "main" class should contain all user communication, consisting of console display and user input via the Scanner class. This class is a client of calculation functions from the ParabolaCalc class. This class should have a main method. You may define class constants, but no other class-level variables. Implement generic (not problem-specific) functions to get in-range integers and floating-point values from the user. Pass in the expected minimum and maximum; the functions should ensure the user makes an entry in the specified range and using the right data type (using Scanner look-ahead) and then passes back the user's choice. You'll make of use of such functions in later projects. Create only one Scanner object instance. If you don't understand why, think and ask! It's a common misconception that more are needed. 5.3 General Use procedural decomposition. Further decomposition is allowed if you think it helpful. 6 Extra Credit For extra credit, draw the resulting rectangles on a DrawingPanel (when the user chooses area estimation from the menu). Make sure the aspect ratio looks good (i.e., don't stretch or squish the parabola; it should look correct). 7 Testing Test each function individually (unit testing), then the entire program (integration testing). You don't need this to be in code for this project; but be aware that you must code it in future projects. Don't test only "happy path" inputs; you want to know what happens when bad inputs enter the system, then modify your code to handle them if you know enough to do so. 10% 8 Submitting Your Work Use Blue) to create a .jar file; ask, if we haven't yet covered this in class. Be sure and specify "include a source." Submit the resulting .jar file. If using Intelli), submit zipped project or source code. 9 Grading Matrix Area Percent Basic functionality and menu Menu display 10% Choice processing Looping 15% General coding 10% Validation Range checking/prompting 10% Data type checking/prompting 15% Combined function doing both 10% Preconditions in calculation class 10% Documentation and style 10% Extra Credit: rectangles drawn 3% Total 103%

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!