2 Simple program using BlueJ We shall now use the BlueJ IDE to develop a simple Java program to say ‘Hello’. Note: latest BlueJ may look slightly different. In BlueJ select: Project – New Project. Create a project ‘Summer project’ in a suitable location - Create – New Class – type HelloWorld for class name - Ok. Double click the HelloWorld class to open the code edit window (or right click – Open Editor). Delete all the example code and type in the HelloWorld code as shown below, but with your own name after author (and not anything in the dashed rectangles which are notes to help you). Note: Java comments do not affect how a program runs but are used to help a programmer Indent code to help readability (does not affect compilation / execution): use Edit - Auto-layout Semi colon ; curly brackets {, } round brackets (, ) and square brackets [, ] must be used correctly and are NOT interchangeable. To see line numbers (in the code editor): Options – preferences – display line numbers. BlueJ reference site: Click compile (you should get ‘Class compiled - no syntax errors’ - otherwise check lines 5 to 11 are correctly typed – Java is case sensitive, and remember curly brackets and semicolon – Java is fussy! Close the editor. Right click the HelloWorld class Select void main(String[] args) Select Ok The terminal window should contain “Hello World!” as output as shown: {Note: It is possible to write Java using a normal text editor, and compile and run java programs using the Java SDK without need for an IDE such as BlueJ by using the command line interface. You are not required to do so, but if you are interested to do this, see or YouTube tutorial 2 running Java: .} youTube reference links for installing BlueJ and a HelloWorld program, zaychenok Java Lesson 1&2: , Now you are ready to start work. Allow at least 12 hours to complete the work that follows.
Java Work – do this before attempting Java exercises (or after you get stuck!) Make sure you have completed sections 1-4 of this booklet. Go to chortle site or use mirror site . Go through chapters 8 – 11 and do as many exercises and quizzes as you need. Set aside at least six hours to work through these chapters and more if you do more than a few of the exercises. After chapters 8 – 9c attempt question 1 below (filling in answers 01 to 03). After chapters 10 – 11 attempt question 2, 3 and 4 below (filling in answers 04 to 11). Useful links to go with chortle reading above and help with exercises to follow below: Basic BlueJ program Use of Scanner Bucky tutorials (use Eclipse IDE instead of BlueJ but otherwise are relevant) Java Programming Tutorial - 6 - Getting User Input (OR on the new boston: etc) Java Programming Tutorial - 7 - Building a Basic Calculator StBrendan (use BlueJ Scanner with integer division and remainder useful for que 2) Code academy – learn Java (units 1 and 2 – free stuff only – also try code in BlueJ) Type your answers to the exercises below in your Electronic Answer Document. You must save this document at regular intervals. Question 1 Create a class Exercise1 with the code below (you can type in or copy and paste): public class Exercise1 { public static void main (String[] args) { double km = 30, miles miles = km * 5 / 8; System.println(km + " kilometres is " + miles + " miles"); }//end main }//end class (a) The program has two compilation errors. Correct these. What you need to do Modify the program so that it so the program compiles and runs (tip: see EAD front sheet for help on pasting screenshots into EAD) (b) (i) replace miles = km * 5 / 8; by miles = 5.0 / 8 * km; compile and run (ii) replace miles = 5.0 / 8 * km; by miles = 5 / 8 * km; compile and run Explain fully the results obtained in running versions b(i) and (ii). To gain full marks you will need to note the relevance of data types (Chortle chp 8, 9B) (2 marks)