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.

4. Challenge - GymAppV1.0

This exercise will help you become more familiar with the Scanner class as well as working with a two class app.

This console based app will ask the user to enter a GymMembers details. These details will then be printed back to the console.

During this challenge, you may need to view this weeks and last weeks lecture notes to remind you how to write classes. The SpotConsoleV1.0 (particularly for validation) and the ShopV1.0 solution will also be useful here.

  • In IntelliJ, create a new Java Project called GymApp1.0.

  • Within this project, create two new Classes; GymMember and Driver.

GymMember Class - fields

In the GymMember class, create five private instance fields:

  • private String name;
  • private double height;
  • private double weight;
  • private int membershipNumber;
  • private boolean isCurrentGymMember;

The default values for these fields are as follows:

  • name is “unknown”
  • height is 0.0 (note: this is measured in meters)
  • weight is 0.0 (note: this is measured in kgs)
  • membershipNumber is 99999
  • isCurrentGymMember is false

The validation for these fields is as follows:

  • name is maximum 30 chars long
  • height is between 0.5 and 3.0 inclusive
  • weight is 25 and 600 inclusive
  • membershipNumber is between 00001 (inclusive) and 99999 (exclusive)
  • isCurrentGymMember has no validation.

Write a constructor for this class that takes the five instance fields as parameters and updates the object state using these parameters.

Write a getter for each instance field.

Write a setter for each instance field.

Write a toString method that builds and returns a String comprising a user friendly representation of the object state.

Driver Class

In the Driver class, create two private instance fields:

  • input of type Scanner (initialise this field using new Scanner(System.in))
  • gymMember of type GymMember

Write a method called addGymMember()) that asks the user to input the gym member details (name, height, weight, membership number and if they are a current member). Use this data to create a new GymMember object.

Write a method called printGymMember() that prints all the gymMember details to the console.

Hint: use the toString() method from the GymMember class.

Write a main method that calls the Driver() constructor.

Write a Driver() constructor that calls both the addGymMember()) and printGymMember() methods.

Run the App

Run the app; does all work as expected? Are you asked to enter the gym members details? Are all details you entered printed back to the console?