Java / Other Minor Java Work / EF_IceCreamFlavours.java
EF_IceCreamFlavours.java
Raw
/**
 * Program Name: EF_IceCreamFlavours.java
 * Purpose: This program randomly generates 1-20 ice cream flavours and styles based on how many the user needs.
 * Coder: Essam Fahmy
 * Date: Apr 1, 2022
 */

import java.util.Scanner;

public class EF_IceCreamFlavours
{

	public static void main(String[] args)
	{
		//Creating Scanner
		
		Scanner input = new Scanner(System.in);
		
		//Outputting Title
		
		System.out.println("This is Essam's Ice Cream Flavours Program");
		
		//Declaring and Initializing String Arrays Required
		
		String[] flavoursArray = {"Amaretto", "Annisette", "Apple cider", "Bacon", "Blueberry", "Blackberry", "Bubblegum", "Butterscotch", "Caramel", "Cheddar Cheese", "Cherry", "Chocolate"};
		String[] stylesArray = {"Bark", "Chiffon", "Chunk", "Cream", "Crunch", "Explosion", "Fudge Ripple", "Sundae"};
		
		//Declaring Variables Required
		
		String flavour;
		String style;
		int numOfStyles = 0;
		
		//Gaining User Input for Amount of Flavour-Styles
		
		System.out.print("How many flavour-styles would you like to see? ");
		numOfStyles = input.nextInt();
		
		//Validating User Input 
		
		while (numOfStyles > 20 || numOfStyles < 1)
		{
			System.out.println("Invalid input. Number of flavour-styles must be between 1 and 20.");
			System.out.print("How many flavour-styles would you like to see? ");
			numOfStyles = input.nextInt();
		}
		
		//Closing Scanner
		
		input.close();
		
		//Declaring String Array with Length set to user input
		
		String[] flavourStylesArray = new String[numOfStyles];
		
		System.out.println();
		System.out.print("Your " + numOfStyles + " randomly generated ice cream flavour-styles are:\n");
		
		//Generating Two Random Numbers and Using Them With Both Arrays to Output Random flavour-styles as Needed by User
		
		for (int i = 0; i < numOfStyles; i++)
		{
			int firstRandomValue = (int)(Math.random() * (11 - 0 + 1) + 0);
			int secondRandomValue = (int)(Math.random() * (7 - 0 + 1) + 0);
			
			flavour = flavoursArray[firstRandomValue];
			style = stylesArray[secondRandomValue];
			
			flavourStylesArray[i] = flavour + " " + style;
			
			System.out.println((i + 1) + ". " + flavourStylesArray[i]);
		}
	}
	//end main
}
//end class