Course Info

#Programming Fundamentals 1

This is an introductory Programming module and assumes no prior knowledge of programming.

In this module, we will introduce you to the Java programming language through the Processing Development Environment (PDE) and then IntelliJ.

First, we will work through non-complex problems that will introduce you to the basic constructs of programming languages i.e. Sequence, Selection and Loops. You will also learn to use variables, different data types, manipulate the data, logical operators and methods. This will be done using processing.org

Then, using IntelliJ, we will progress to more complex problems that will briefly introduce you to object-oriented programming and data structures. You will do a deeper dive into both of these areas in the semester 2 module, Programming Fundamentals 2.

Spot Console V1.0

This console based app will display the xCoord, yCoord and diameter details to the user, along with calculations for the circle radius, area and circumference.

During this step, you may need to view this weeks lecture notes to remind you how to write classes.

We created the SpotConsoleV1.0 project in the previous step, so we will continue working in this project.

When code is given in labs, avoid the temptation to cut and paste it in (unless told explicitly to do so). Typing in code maximises your learning!

Creating Classes

Within the SpotConsoleV1.0 project, right click on the src folder and select New followed by Java Class.

When the dialog appears, enter Spot as the class name. You now should have an empty class like this:

In the Spot class, create three public instance fields:

  • xCoord of type float
  • yCoord of type float
  • diameter of type float

Write a default constructor for this class (that takes in no parameters). This constructor should update fields like so:

  • xCoord = 100
  • yCoord = 200
  • diameter = 40

The code will look like this:

Driver Class

In the Driver class, create one instance field called spot and instantiate it by calling the default Spot constructor.

Then create a new method called drawSpot():

    void drawSpot(){
        System.out.println("xCoord is:   " + spot.xCoord);
        System.out.println("yCoord is:   " + spot.yCoord);
        System.out.println("diameter is: " + spot.diameter);
    }

Add a Driver constructor to call this new method:

    Driver(){
        spot = new Spot();
        drawSpot();
    }    

And finally replace your main method with this code (to call the Driver constructor):

   public static void main(String args[]) {  
	    System.out.println("Spot Console V1.0");  
	    new Driver();  
}

Your class Driver code should look something like this: (you can ignore the Scanner class for the moment 😃 )

Run the App

Run the app by clicking on the green triangle beside the main method in Driver.

Your output should look like this:

Save your work.