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.

3. Exercise - Scanner

This exercise will help you become more familiar with the Scanner class.

What are you being asked to do?

Write a single class app that uses Scanner to ask the user to type in the value of an angle: Input

If the angle is less than 90, print out acute angle, e.g.: Acute Angle Output

If it is exactly 90, print out right angle, e.g.: Right Angle Output

If it is more than 90 but less than 180, print out obtuse angle, e.g.:, Obtuse Angle Output

If it is exactly 180, print out straight angle, e.g.: Straight Angle Output

If it is otherwise, print out reflex angle, e.g.: Right Angle Output

How do I code that?

In IntelliJ, create a new Java Project called AngleProject.

Create a class called Angle.

Import the Scanner class; recall that this must be the first line in your file.

Add a main method to the class and in this method:

  • Create an object of the Scanner class.

  • Ask the user to enter an angle and store it (you can determine the variable type from the screen shots above).

  • Call the processAngle method (defined below) passing, as the parameter, the angle value that you just read in.

processAngle() method

Create a private method, with a void return type and call it processAngle. It should accept one parameter of type int.

This method interrogates the parameter value and prints the type of angle it is to the screen (according to the screen shots above).

Run the App

Run the app; does all work as expected?