Prototypes

A prototype is a basic version of a product.

It may not have all of the necessary functionality of the final product.

However, it gives the client a look and feel of what the final product might be like.

This is a relatively cheap way to determine if full-production should go ahead.

A Modular Approach

Rather than writing a Java program which only has a main function, a program can be broken down into a variety of functions which perform specific tasks.

When a function is needed, it is called!

There are some advantages to this approach:

Improved Code Readability and Maintainability By breaking down the code into smaller, manageable modules, each handling a specific part of the functionality, the code becomes easier to read, understand, and maintain.

Enhanced Reusability Modules can often be reused across different parts of the application or even in other projects, saving time and effort by not rewriting code for similar tasks.

Easier Debugging and Testing Isolating specific functionality into modules simplifies identifying and fixing bugs, as each module can be tested independently, allowing issues to be traced more effectively.

Concurrent Development Modular design allows multiple programmers to work on different modules concurrently (at the same time), speeding up development and enabling collaboration on large projects.

Scalability and Flexibility As requirements evolve, modular programs can be expanded or modified by adding, replacing, or updating individual modules without impacting the entire system.

public static void instructions(String[] sheepNames) {

System.out.println("Today's racers are: ");

//loop through the array of Strings and display each String

for(int i = 0; i<.length; i++) {

System.out.println((i+1) + " : " + sheepNames[]);

}

System .out.println("They will race 1000 meters. You will predict the winner. Let's start!");

}

public static String getPrediction(String[] ) {

String p;

Scanner kbin = new Scanner(System.in);

System.out.print(sheep[0]+", "+sheep[1]+", "+sheep[2]);

System.out.println();

System.out.println("Which sheep will win the race. Enter your prediction");

p = kbin.nextLine();

//return the prediction

p;

}

public static int race(String[] racers) {

int[] distances = new int[3];

distances[0] = 0;

distances[1] = 0;

distances[2] = 0;

//race while each value in distances is less than 1000

while(distance[0]<1000 && distance[1]<1000 distance[2]<1000) {

for(int i = 0; i<distances.length; i++) {

//update each distance by adding a random number to it

distances[i] = + (int)(Math.random()*41)+10;

}

}

//end of race, but who won? Return the index of the winner

if(distance[0]>distance[1] && distance[0]>distance[2]) {

return ;

}else if(distance[1] > distance[0] && distance[1] > distance[2]) {

return ;

}else {

return ;

}

}

public static void displayResult(int index, String playerPrediction, String[] sheepies) {

System.out.println("What a race!");

System.out.println("You predicted "++"! ");

System.out.println("The winner is "++".");

if(playerPrediction.equals()) {

System.out.println("You won! 10 gold coins earned!");

}else {

System.out.println("You lost - better luck next time!");

}

}

Jeep Sheep!

Game designers are designing characters for a new online game they hope is going to go viral:

Jeep Sheep!

Here is the concept:

  • There are 3 sheeps in jeeps.
  • There is 1 human player.
  • The sheep race 1000m.
  • The player predicts the winner.
  • The result is displayed.

While the Graphic Designers are working a visual of the game, the programming team is working on the actual game logic.

It has been decided to use arrays to manage the game data.

Here is some starter code that your colleagues have been working on:

Game logic

The programmers have adopted a to the solution. This is the design of the main function.

public static void main(String[] args) {

String[] racers = {"Max", "Jerry", "Sandy"};

instructions(racers);

String prediction = getPrediction(racers);

int winIndex = race(racers);

displayResult(winIndex, prediction, racers);

}

Task

Complete the tasks in the worksheet.

They will give you an opportunity to analyse the code and develop the program further.

Testing

Make sure you are thoughtful when testing your solution.

If your code has a validation check, test your code with acceptable/valid data and unacceptable/invalid data.