Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: STEP 1. INTRODUCTION Start by creating a new Java Project in eclipse and adding a new class called Fountain to this project. Ensure that

JAVA: STEP 1. INTRODUCTION

Start by creating a new Java Project in eclipse and adding a new class called Fountain to this project. Ensure that this new project uses Java 8, by setting the Use an execution environment JRE: drop down setting to JavaSE-1.8 within the new Java Project dialog box.

Next download this P2ParticleFountain.jar file (http://cs300-www.cs.wisc.edu/wp/wp-content/uploads/2019/01/P2ParticleFountain.jar) and copy it into your project folder. If this .jar file is not immediately appearing in the Project Explorer, try right-clicking your project folder and selecting Refresh to fix that. To make use of the code within this jar file, youll need to right click on it within the Project Explorer and choose Add to Build Path from the Build Path menu. To ensure that this is working, call Utility.runApplication() from the main method within your Fountain class. When you run this program, a gray window should appear as a result along with an error message in the console which well resolve in the next steps: ERROR: Could not find method named setup that can take arguments [] in class Fountain.

STEP 2. UTILITY FRAMEWORK

At the end of the last step we saw an error related to the fact that our Fountain class was missing a method called setup(). Create a public static method with this name that takes no input arguments and has no return value. This should lead to a slightly different error message being displayed: ERROR: Could not find method named update that can take arguments [] in class Fountain. We can now fix this error in a similar way, by creating a new public static method named update(), which also takes no input arguments and has no return value.

All of the methods within the provided P2ParticleFountain.jar file are documented here (http://cs300-www.cs.wisc.edu/wp/wp-content/uploads/2019/01/p2javadocs/). If you look at the JavaDoc documentation for the Utility.runApplication() method, see how this method is making use of the setup and update methods that we have just created. These methods should not be called directly from your code. They should only be called by the Utility class, as a result of your calling Utility.runApplication(). You can also read through some of the other methods that are available through this Utility class. Note that many of these methods take float rather double values as arguments. Any time that you need to express a float constant in Java, you should use a lower case f to distinguish its type: 1.3 is a double, but 1.3f is a float.

Were going to be utilizing a lot of randomly generated values throughout this assignment, so lets create a private static Random field named randGen within the Fountain class. If you are not familiar with this class, you can read about the nextInt() and nextFloat() methods within the JavaDocs here(https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#Random--) . Initialize this field to a new Random object, and then pass a randomly generated int value to Utility.background() within the setup method. Now every time you run this program, the background will be cleared to a different random color. You do not need to use a specific seed when instantiating this random number generator, although doing so may be helpful debugging your code.

Next try drawing some circles using the Utility.circle() method. In order to change the color of the circles that are drawn, you can call Utility.fill(). Although randomly chosen colors can be fun, lets specific some particular colors that well continue to use going forward. Well use the Utility.color() method to specify the mix of red, green, and blue light that make up the colors that well want to use here. Well use Utility.color(235,213,186) for the background color, and well draw a circle on that background with the color Utility.color(23,141,235).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions