|
|
package uwstout.courses.cs144.labs.lab3;
|
|
|
|
|
|
import java.util.Scanner;
|
|
|
|
|
|
/**
|
|
|
* Gets the ingredients for a 3 ingredient recipe and prints the results.
|
|
|
*
|
|
|
* Gets the ingredients for a 3 ingredient recipe and prints the results. For
|
|
|
* each ingredient, the user needs to specify the name, amount and units.
|
|
|
* Ingredients and units can have spaces in them and the amount is a whole
|
|
|
* number.
|
|
|
*
|
|
|
* @author turners
|
|
|
* @version 2022-09-26
|
|
|
*/
|
|
|
public class Recipe {
|
|
|
|
|
|
/**
|
|
|
* Gets the ingredients for a 3 ingredient recipe and prints the results.
|
|
|
*
|
|
|
* Gets the ingredients for a 3 ingredient recipe and prints the results. For
|
|
|
* each ingredient, the user needs to specify the name, amount and units.
|
|
|
* Ingredients and units can have spaces in them and the amount is a whole
|
|
|
* number.
|
|
|
*
|
|
|
* @param args Command line arguments - not used
|
|
|
*/
|
|
|
public static void main(String[] args) {
|
|
|
Ingredient item1 = null;
|
|
|
Ingredient item2 = null;
|
|
|
Ingredient item3 = null;
|
|
|
String name;
|
|
|
int amount;
|
|
|
String units;
|
|
|
|
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
|
|
System.out.println("Enter the first Ingredient's name: ");
|
|
|
name = scan.nextLine();
|
|
|
System.out.println("Enter the first Ingredient's amount: ");
|
|
|
amount = scan.nextInt();
|
|
|
System.out.println("Enter the first Ingredient's unit: ");
|
|
|
scan.skip("\\s*"); // skips spaces to get the input ready for the units
|
|
|
units = scan.nextLine();
|
|
|
item1 = new Ingredient(name, amount, units);
|
|
|
|
|
|
System.out.println("Enter the second Ingredient's name: ");
|
|
|
name = scan.nextLine();
|
|
|
System.out.println("Enter the second Ingredient's amount: ");
|
|
|
amount = scan.nextInt();
|
|
|
System.out.println("Enter the second Ingredient's unit: ");
|
|
|
scan.skip("\\s*"); // skips spaces to get the input ready for the units
|
|
|
units = scan.nextLine();
|
|
|
item2 = new Ingredient(name, amount, units);
|
|
|
|
|
|
System.out.println("Enter the third Ingredient's name: ");
|
|
|
name = scan.nextLine();
|
|
|
System.out.println("Enter the third Ingredient's amount: ");
|
|
|
amount = scan.nextInt();
|
|
|
System.out.println("Enter the third Ingredient's unit: ");
|
|
|
scan.skip("\\s*"); // skips spaces to get the input ready for the units
|
|
|
units = scan.nextLine();
|
|
|
item3 = new Ingredient(name, amount, units);
|
|
|
|
|
|
System.out.println("Ingredient List\n");
|
|
|
System.out.println(item1.getName() + "\t" + item1.getAmount() + "\t" + item1.getUnits());
|
|
|
System.out.println(item2.getName() + "\t" + item2.getAmount() + "\t" + item2.getUnits());
|
|
|
System.out.println(item3.getName() + "\t" + item3.getAmount() + "\t" + item3.getUnits());
|
|
|
|
|
|
scan.close();
|
|
|
}
|
|
|
}
|