You don't have to put them in the BlueJįolder, just remember where you download them to on your computer. The icon you created when you downloaded and installed BlueJ or by In this example I will assume they have been downloaded to the desktop. The file called fs with a text editor.This file is located in the lib directory in You can alter some of the defaults for BlueJ my modifying Navigating to the BlueJ directory and double clicking on the bluej.bat icon. You can also modifying the template that starts when creating new programs and classes. When BlueJ is up and running you should see a window that looks something like this: The template is stored in the lib -> english -> templates -> newclass folder. To create a new program you first need to create a new project. It canĪfter giving the new project and name and clicking Create The name of the project does not have to be the sameĪs the name of the java file you will later add to the project.Ĭlick on the Project menu and select New Project.įrom this window type in the name of the new project in the text field File name.
#Statistics l.a. 19.1 bluej program java code
There aren't any classes, which are the basic building blocks of programs in Java, or code associated with the project yet. You can double click on it to addĬomments about the project as a whole or write notes to yourself on things Icon that looks like a piece of paper is just a simple text file that actsĪs the projects readme file. If you need to add any pre-existing classes to the project now is a good time to do that. On the first assignment you need to download and add then add the DrawingPanel.java class to your project. Menu and then select Add Class from File.Ī new window pops up that allows you to navigate to the correct directory and select the file you To add the existing file to the project click on the Edit #Statistics bluej program l.a. Navigate to the directory that contains the file or files you want to add. If you want to add a single file, click on it and then click on the Add button. If you want to add 2 or more files from the same directory hold down the CTRL key and click on all the files you want to add, then click on the Add button. Now the new file / class has been added to the file. It shows up with diagonal lines because it has not been compiled yet. To compile a class that is part of a program you can either click the Compile button on the left side of the window or right click on the icon of the class and select the Compile option from the pop up menu. If the class does not have any syntax errors it will now be shown without any diagonal lines on its icon. To add a new class to the project click on the New Class button.Ī menu pops up asking for the name of the class. On assignment 1 the name must be Circle.Įnsure the Class radio button is selected, type in Circle for the Class Name and click the okay button. To edit the code in a class double click on its icon. This opens an editor window which is very like a simple word processor. Select and delete the default code in the class. Save the program by clicking on the Class menu and selecting Save.
You can attempt to compile the program by clicking the Compileīutton. After compiling the program and getting it to If an error occurs the line the error is on is Any errors will show up in the text area at the bottom of theĮdit window. Work close the editing window w and go back to the project window. To run the program right click on the icon that has the main Program / class icon no longer has diagonal lines across it. This causes the main method of theĪnother menu pops up that asks what parameters or (You could also compile classes here.) Select the This brings up a menu that allows you to carry out IN assignment one, this is the Circle class. In thisĬlass we won't normally pass any information to method main so just click Information you want to pass to the method, in this case main. * Declaring array of n elements, the value Scanner scanner = new Scanner(System.in) In this example, we are using Scanner to get the value of n and all the numbers from user. Output: The average is: 52.418 Example 2: Calculate average of numbers entered by user * if you give %.4f then the output would have 4 digits * This is used for displaying the formatted output * arr.length returns the number of elements To understand these programs you should have the knowledge of following Java Programming concepts:Ģ) For loop Example 1: Program to find the average of numbers using array public class JavaExample The second programs takes the value of n (number of elements) and the numbers provided by user and finds the average of them using array.
First Program finds the average of specified array elements. We will see two programs to find the average of numbers using array.