I am doing this flower shop program and I need to store the orders in some kind of dynamic array, but i’m not allowed to use the following arrays: ArrayList, vector, HashMap, etc I thought that I had sorted it by creating an array called orders but on my IDE its keeps on saying that orders can not be resolved to a variable… here is the code that I have so far I have highlighted the issues with the //
`import java.util.Scanner;
public class MenuTest2B {
<code>public final String[] FLOWERS = { "Choose your flower:", "Roses", "Lilys", "Carnations", "Daffodils", "Gerberas", "Chrysanthemums", "Assorted" };
public final double[] FLOWER_PRICES = {0,1.2, 1.3, 1.0, 1.0, 1.1, 1.1, 0.8 };
// create colours + price arrays
public final String[] COLOURS = { "Choose your colour:", "White", "Red", "Pink", "Yellow", "Blue", "Mixed" };
public final double[] COLOUR_PRICES = {0,1.3, 1.2, 1.1, 1.1, 1.2, 1.0 };
// create size + price arrays
public final String[] SIZES = { "Choose your size:", "Small", "Medium", "Large" };
public final double[] SIZE_PRICES = {0,5.5, 7.5, 9.5 };
public final String[] menu = { "Main Menu", "1. Order a bouquet and get the price.", "2. Display statistics", "3. Exit" };
scanner = new Scanner( System.in );
choice = getUserChoice();
// use scanner to display menu options for flowers colours and size
orderDetailsAndPriceCalculation();
System.out.println( "You are exiting the program... Goodbye" );
System.out.println( "Invalid input. Please select a valid option." );
public void orderDetailsAndPriceCalculation() {
// adds values for chosen ammounts for orders and puts them into the scanner
System.out.println( "" );
int flowerChoice = getUserChoice();
if( flowerChoice == -1 ) {
int colourChoice = getUserChoice();
if( colourChoice == -1 ) {
int sizeChoice = getUserChoice();
// calculates the input order details (Flower+Colour)*Size
double totalPrice = ( FLOWER_PRICES[ flowerChoice -1]
+ COLOUR_PRICES[ colourChoice -1] )
* SIZE_PRICES[ sizeChoice -1];
System.out.println( "Bouquet Price: £" + totalPrice );
// Stores the new orders details in the 2d orders array
orders[orderCount][0] = flowerChoice; // this is where the issue is
orders[orderCount][1] = colourChoice; // this is where the issue is
orders[orderCount][2] = sizeChoice; // this is where the issue is
orders[orderCount][3] = totalPrice; // this is where the issue is
orderCount++; // this is where the issue is
public void summaryStatistics() {
System.out.println( "Summary statistics provided" );
private void displayMenu( String obj[] ) {
for( int i = 0; i < obj.length; i ++ ) {
System.out.println( obj[ i ] );
System.out.println( i + ". " + obj[ i ] );
return scanner.nextInt();
public static void main( String[] args ) {
MenuTest2B mt2 = new MenuTest2B();
<code>public final String[] FLOWERS = { "Choose your flower:", "Roses", "Lilys", "Carnations", "Daffodils", "Gerberas", "Chrysanthemums", "Assorted" };
public final double[] FLOWER_PRICES = {0,1.2, 1.3, 1.0, 1.0, 1.1, 1.1, 0.8 };
// create colours + price arrays
public final String[] COLOURS = { "Choose your colour:", "White", "Red", "Pink", "Yellow", "Blue", "Mixed" };
public final double[] COLOUR_PRICES = {0,1.3, 1.2, 1.1, 1.1, 1.2, 1.0 };
// create size + price arrays
public final String[] SIZES = { "Choose your size:", "Small", "Medium", "Large" };
public final double[] SIZE_PRICES = {0,5.5, 7.5, 9.5 };
private Scanner scanner;
public final String[] menu = { "Main Menu", "1. Order a bouquet and get the price.", "2. Display statistics", "3. Exit" };
public void exec() {
scanner = new Scanner( System.in );
int choice;
do
{
displayMenu( menu );
choice = getUserChoice();
switch( choice ) {
case 1:
// use scanner to display menu options for flowers colours and size
orderDetailsAndPriceCalculation();
break;
case 2:
summaryStatistics();
break;
case 3:
System.out.println( "You are exiting the program... Goodbye" );
scanner.close();
break;
default:
System.out.println( "Invalid input. Please select a valid option." );
}
}
while( choice != 3 );
}
public void orderDetailsAndPriceCalculation() {
// adds values for chosen ammounts for orders and puts them into the scanner
System.out.println( "" );
displayMenu( FLOWERS );
int flowerChoice = getUserChoice();
if( flowerChoice == -1 ) {
return;
}
displayMenu( COLOURS );
int colourChoice = getUserChoice();
if( colourChoice == -1 ) {
return;
}
displayMenu( SIZES );
int sizeChoice = getUserChoice();
if( sizeChoice == -1 ) {
return;
}
// calculates the input order details (Flower+Colour)*Size
double totalPrice = ( FLOWER_PRICES[ flowerChoice -1]
+ COLOUR_PRICES[ colourChoice -1] )
* SIZE_PRICES[ sizeChoice -1];
// PRINT TOTAL AMOUNT
System.out.println( "Bouquet Price: £" + totalPrice );
// Stores the new orders details in the 2d orders array
orders[orderCount][0] = flowerChoice; // this is where the issue is
orders[orderCount][1] = colourChoice; // this is where the issue is
orders[orderCount][2] = sizeChoice; // this is where the issue is
orders[orderCount][3] = totalPrice; // this is where the issue is
orderCount++; // this is where the issue is
}
public void summaryStatistics() {
System.out.println( "Summary statistics provided" );
}
private void displayMenu( String obj[] ) {
for( int i = 0; i < obj.length; i ++ ) {
if( i == 0 ) {
System.out.println( obj[ i ] );
}
else {
System.out.println( i + ". " + obj[ i ] );
}
}
}
int getUserChoice() {
try {
return scanner.nextInt();
}
catch( Exception e ) {
return -1;
}
}
public static void main( String[] args ) {
MenuTest2B mt2 = new MenuTest2B();
mt2.exec();
}
</code>
public final String[] FLOWERS = { "Choose your flower:", "Roses", "Lilys", "Carnations", "Daffodils", "Gerberas", "Chrysanthemums", "Assorted" };
public final double[] FLOWER_PRICES = {0,1.2, 1.3, 1.0, 1.0, 1.1, 1.1, 0.8 };
// create colours + price arrays
public final String[] COLOURS = { "Choose your colour:", "White", "Red", "Pink", "Yellow", "Blue", "Mixed" };
public final double[] COLOUR_PRICES = {0,1.3, 1.2, 1.1, 1.1, 1.2, 1.0 };
// create size + price arrays
public final String[] SIZES = { "Choose your size:", "Small", "Medium", "Large" };
public final double[] SIZE_PRICES = {0,5.5, 7.5, 9.5 };
private Scanner scanner;
public final String[] menu = { "Main Menu", "1. Order a bouquet and get the price.", "2. Display statistics", "3. Exit" };
public void exec() {
scanner = new Scanner( System.in );
int choice;
do
{
displayMenu( menu );
choice = getUserChoice();
switch( choice ) {
case 1:
// use scanner to display menu options for flowers colours and size
orderDetailsAndPriceCalculation();
break;
case 2:
summaryStatistics();
break;
case 3:
System.out.println( "You are exiting the program... Goodbye" );
scanner.close();
break;
default:
System.out.println( "Invalid input. Please select a valid option." );
}
}
while( choice != 3 );
}
public void orderDetailsAndPriceCalculation() {
// adds values for chosen ammounts for orders and puts them into the scanner
System.out.println( "" );
displayMenu( FLOWERS );
int flowerChoice = getUserChoice();
if( flowerChoice == -1 ) {
return;
}
displayMenu( COLOURS );
int colourChoice = getUserChoice();
if( colourChoice == -1 ) {
return;
}
displayMenu( SIZES );
int sizeChoice = getUserChoice();
if( sizeChoice == -1 ) {
return;
}
// calculates the input order details (Flower+Colour)*Size
double totalPrice = ( FLOWER_PRICES[ flowerChoice -1]
+ COLOUR_PRICES[ colourChoice -1] )
* SIZE_PRICES[ sizeChoice -1];
// PRINT TOTAL AMOUNT
System.out.println( "Bouquet Price: £" + totalPrice );
// Stores the new orders details in the 2d orders array
orders[orderCount][0] = flowerChoice; // this is where the issue is
orders[orderCount][1] = colourChoice; // this is where the issue is
orders[orderCount][2] = sizeChoice; // this is where the issue is
orders[orderCount][3] = totalPrice; // this is where the issue is
orderCount++; // this is where the issue is
}
public void summaryStatistics() {
System.out.println( "Summary statistics provided" );
}
private void displayMenu( String obj[] ) {
for( int i = 0; i < obj.length; i ++ ) {
if( i == 0 ) {
System.out.println( obj[ i ] );
}
else {
System.out.println( i + ". " + obj[ i ] );
}
}
}
int getUserChoice() {
try {
return scanner.nextInt();
}
catch( Exception e ) {
return -1;
}
}
public static void main( String[] args ) {
MenuTest2B mt2 = new MenuTest2B();
mt2.exec();
}
}
`
I did try adding a int and a string but that achieved nothing to be honest what I need is for the order choices to be stored somehow so that when menu 2 is selected it will display the statistics I have that part already done and just need to add it to the code once the orders are saved somehow.