1 / 24

Java Programming with BlueJ Objectives

Java Programming with BlueJ Objectives. After this presentation you should be able to : Open a BlueJ project (or start a new project) Create a new class Edit default code Create Java source code for each of the structures: Sequence Selection Repetition. Java Programming with BlueJ

pturpin
Download Presentation

Java Programming with BlueJ Objectives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Programming with BlueJObjectives • After this presentation you should be able to : • Open a BlueJ project (or start a new project) • Create a new class • Edit default code • Create Java source code for each of the structures: • Sequence • Selection • Repetition

  2. Java Programming with BlueJ Opening a new project Click Project New Project Select YOUR C: drive

  3. Java Programming with BlueJ Creating a folder for projects Click New Folder Name Folder: BlueJ Projects Name Project: Structures

  4. Java Programming with BlueJ Your window should look like this

  5. Java Programming with BlueJ Creating a new class Click New Class Name Class: Student Select Class Button Click OK

  6. Java Programming with BlueJ Your window should look like this The diagonal bars indicate a class that has errors or has not been compiled.

  7. Java Programming with BlueJ Editing the code Right click the class Select Open Editor You will see these features provided for you. Private attribute Default constructor A method

  8. Converting pseudo code to Java Sequence Statements Construct a segment of code that will display the text “Hello World” and “I am a student at AACC”. Pseudo Code Java Code print “Hello World” System.out.println(“Hello World”); print “I am a student at AACC” System.out.println(“I am a student at AACC”);

  9. Java Programming with BlueJ Adding your own code – Sequence Structure Convert the sampleMethod to MyMethod shown here To output of this code

  10. Java Programming with BlueJ Compiling the code Click Compile from either window. The diagonal lines in the Student class should disappear. ‘no syntax errors’ should appear in the box below.

  11. Java Programming with BlueJ Instantiating the class Right click the Student Class. Select new Student( ) Accept the default name. Click OK An instance of the Student class appears on the object bench

  12. Java Programming with BlueJ Running the code inherited from Object void MyMethod( ) Inspect Remove Right Click the student1 object Select MyMethod()

  13. Java Programming with BlueJ Your output window should look like this The output from the System.out.println statements appear in a Terminal Window for the Structures project. Review the code that got us here.

  14. Java Programming with BlueJ Editing the constructor and adding an instance variable. Add the attribute grade (an integer). Edit the constructor to include the parameter newGrade and the assignment statement. To the execution of the constructor

  15. Converting pseudo code to Java Selection Statements Write a segment of code that will convert a letter grade to an A or B. Pseudo Code Java Source Code if grade >= 90 then if (grade>= 90) print “A” System.out.println(“A”); else else print “B” System.out.println(“B”); end if

  16. Java Programming with BlueJ Adding another method – selection structure. Add another method called method2. method2 has no parameters and no local variables. method2 contains a multi-way selection structure. Compile the code. Show output from this structure.

  17. Java Programming with BlueJ Running the new code. Right click the Student class. Select new Student() A new window appears because the constructor now expects a parameter. Input an integer value, click OK. Review the code that got us here.

  18. Java Programming with BlueJ Running the new code. Right click the object. Select method2( ) inherited from Object void MyMethod( ) void method2( ) Inspect Remove

  19. Java Programming with BlueJ Your output window should look like this The output from the System.out.println statement appears in a Terminal Window for the Structures project. Review the code that got us here.

  20. Converting pseudo code to Java Repetition Statements Construct a loop that will display the numbers 1 – 10. Pseudo Code Java Code for x = 1 to 10 for (x = 1; x <= 10; x++) print x System.out.println(x); end for

  21. Java Programming with BlueJ Adding another method – repetition structure. Add another method called method3. method3 has no parameters and no local variables. method3 contains a for loop (repetition structure). Compile the code. Show output from this structure.

  22. Java Programming with BlueJRunning the new code. Right click the object. Select method3( ) inherited from Object void MyMethod( ) void method2( ) void method3( ) Inspect Remove

  23. Java Programming with BlueJ Your output window should look like this The output from the System.out.println statements appears in a Terminal Window for the Structures project. Review the code that got us here.

  24. Java Programming with BlueJAssignments Work on assignments given by your instructor.

More Related