Skip to content

Latest commit

 

History

History
172 lines (144 loc) · 5.78 KB

Java for NetLogo.md

File metadata and controls

172 lines (144 loc) · 5.78 KB

Java with BlueJ

Objectives

to read and understand this repo

to read and understand NetLogo source code (not necessary now)

BlueJ with git

Introduction to Class

What is class

Creating and Inspecting Ojbects

Creating and Using objects within BlueJ Video

[Project 1](../../../BlueJ 4.1.3/BlueJ projects/chapter01/figures/package.bluej) .bluej

Exactly like how we create, manipulate and inspect agents in NetLogo

Methods and Parameters

Inspect object and experiment methods and parameters Video

[Project 1](../../../BlueJ 4.1.3/BlueJ projects/chapter01/figures/package.bluej) .bluej

  • inspect two objects to compare them side by side, exactly like what we did in NetLogo debug

Great feature of BlueJ

  • right click object in red (not Class in diagram) to check and run all their methods at your will
  • through dialogue window to offer inputs (for parameters, can be more than 1) to the methods

Add a function into source code

solving a challenge exercise video

[house project](../../../BlueJ 4.1.3/BlueJ projects/chapter01/house/package.bluej) .bluej

Project Features

  • bring a number of different classes together to create a new class, Picture
  • add a function or action to draw function of Picture class
  • from inspect Picture (combined) object and further inspect its component objects
  • take the first glance at the source code, see the structure of a class
  • learn to modify functions

Try out class, object, methods before reading source code

video

[ticket machine project](../../../BlueJ 4.1.3/BlueJ projects/chapter02/naive-ticket-machine/package.bluej)

Features

  • to examine the use of class, object and methods before reading source code
  • each method is executed through a dialogue with instruction, input, or return values
  • through inspect we check the states or fields of the object

How to read source code

video

[ticket machine project](../../../BlueJ 4.1.3/BlueJ projects/chapter02/naive-ticket-machine/package.bluej)

Features

  • how to use BlueJ editor
  • how to write Class, constructor

How to write a class from scratch

video

[Heater Exercise](../../../BlueJ 4.1.3/BlueJ projects/chapter02/Heater Exercise)

Features

  • start a new project, write README
  • write comments
    • single comment with // with cmd + option + c
    • block of documents with /** + enter
  • write Class, constructor and methods
    • () and {} and ;
  • compile shorcut : cmd + k
  • compile and test the function or class at every small step
    • crucial to avoid hidden errors
  • use of this : this.temperature = temperature;

How One class uses other classes

Fields of class types video

[clock-display](../../../BlueJ 4.1.3/BlueJ projects/chapter03/clock-display)

Features

  • understand meaning of public, private
  • private int limit;
  • public NumberDisplay(int rollOverLimit){}
  • public int getValue(){}
  • public String getDisplayValue(){}
  • if(value < 10) {return "0" + value;} else {return "" + value;}
  • public void setValue(int replacementValue){}
  • if((replacementValue >= 0) && (replacementValue < limit)) {}
  • public void increment(){}
  • private NumberDisplay hours;
  • private String displayString;
  • hours = new NumberDisplay(24);
  • private void updateDisplay(){}
  • hours.setValue(hour);
  • displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue();

How to use Debugger

video

[clock-display](../../../BlueJ 4.1.3/BlueJ projects/chapter03/clock-display)

Features

  • break
  • step, step-into, continue

How to build and use Test class

video

[clock-display](../../../BlueJ 4.1.3/BlueJ projects/chapter03/clock-display)

Features

  • build a class
  • build a test method and gradually add more test cases into it

How to import other class library

video

[music-organizer-v1](../../../BlueJ 4.1.3/BlueJ projects/chapter04/music-organizer-v1)

Features

  • how to import ArrayList class
  • how to create ArrayList object
  • use its methods ArrayList.get , add, remove

4 classes work together

video

[auction](../../../BlueJ 4.1.3/BlueJ projects/chapter04/auction)

Features

  • how to do for loop
  • how to use multiple classes in a new class
  • how to further inspect into other classes and objects
  • test the new created function thoroughly

Comparing alternative for iteration in Java

video

[music-organizer-v1](../../../BlueJ 4.1.3/BlueJ projects/chapter04/music-organizer-v1)

Features