Question
in java language: please any body who can help me. i post this project on the second time. Write a program that provides a menu
in java language: please any body who can help me. i post this project on the second time.
Write a program that provides a menu that allows a user to create, destroy, and inflate balloon objects in an array that holds five balloon objects. Make all balloon attributes private variables and provide getters, setters and constructors where needed. Support these menu options:
1. Create a balloon with a color and size if there is room in the array.
a. Validate room is available using a method isArrayFull(). b. Validate the size from this list (6, 8, 10, 12) using a method isValidSize() c.Validate the color from this list (red, blue, green, yellow) using a method isValidColor()
2. List all balloons: size, color, inflated using a toString() method 3. Inflate a balloon if it exists and if it is not currently inflated. Provide a method isValidBalloon() and isBalloonInflated() for validation. 4. Destroy a balloon if it exists. Validate it exists by using the method isValidBalloon() 5. Print the number of balloons that exist 6. Quit
i made this project but my destroy and inflate. Validate room is available using a method isArrayFull(). does not work. is their anybody who can help me .
import java.util.Scanner;
public class Main { public static void main(String[] args) { System.out.println("=========================================== " + "| Welcome to Balloon Project | " + "| How can I help you | " + "| Please look out our Balloon menu. | " + "| 1.Create | " + "| 2.Destroy | " + "| 3.Inflate | " + "| 4.Show Balloon | " +"| (Q)uit | " + "============================================| "); Balloon[] balloon = new Balloon[5]; int choice; // Do- while loop do { // Print Menu String[] menu = {"[1]Create a Balloon ", "[2]Destroy the Balloon ", "[3]Inflate the Balloon", "[4]Show the Balloon", " [Q]uit"}; Scanner input = new Scanner(System.in); // Prompt the user to enter the integer for (String each : menu) System.out.println(each); System.out.print(" Enter an integer from the menu "); choice = input.next().toUpperCase().charAt(0); //Create a balloon switch (choice) { case'1' : System.out.print("How many balloon do you want to create? "); int Create = input.nextInt(); balloon = new Balloon[Create]; for (int k = 0; k < balloon.length; k++) { System.out.print("Balloon " + (k + 1)+ " " ); int size; String color; do { //Ask the user for a size System.out.print("Enter a size (6, 8, 10, 12): "); size = input.nextInt(); Balloon.getSize(size); // Validate the size System.out.println(Balloon.IsValidSize(size)); } while (Balloon.IsValidSize(size).equals("Invalid size")); do { //Ask the user for a color System.out.print("Enter a color (red, blue, green, yellow): "); color = input.next(); Balloon.getColor(color); // Validate the color System.out.println(Balloon.IsValidColor(color)); } while (Balloon.IsValidColor(color).equals("Invalid color")); balloon[k] = new Balloon(size, color); } for (Balloon each : balloon) { System.out.println(each); } System.out.println("We made " + Balloon.getQuantity() + " balloons"); break; // Destroy a balloon case '2': // Print all balloons for (Balloon each : balloon) System.out.println(each); System.out.print("Which balloon do you want to destroy? "); // int record = input.nextInt(); int record; String color; do { //Ask the user for a size System.out.print("Enter a size (6, 8, 10, 12): "); record = input.nextInt(); Balloon.getSize(record); // Validate the size System.out.println(Balloon.IsValidSize(record)); } while (Balloon.IsValidSize(record).equals("Invalid size")); do { //Ask the user for a color System.out.print("Enter a color (red, blue, green, yellow): "); color = input.next(); Balloon.getColor(color); // Validate the color System.out.println(Balloon.IsValidColor(color)); } while (Balloon.IsValidColor(color).equals("Invalid color")); // Validate if Balloon exists if (Balloon.IsValidBalloon(balloon[record])) // Destroy a balloon System.out.println("Balloon doesn't exist"); else { Balloon.destroy(record , balloon); } // Print all balloons including destroyed ones for (Balloon each :balloon) { System.out.println(each); } break; // Inflated a balloon case '3': // Print all balloons for (Balloon each : balloon) { System.out.println(each); } System.out.print("Which balloon do you want to inflate ? "); record = input.nextInt(); // Validate if Balloon exists if (Balloon.IsValidBalloon(balloon[record ])) { if (Balloon.IsBalloonInflated(record , balloon)) Balloon.inflate(record , balloon); else System.out.println("Balloon is inflated"); } else System.out.println("Balloon doesn't exist"); // Print all balloons including inflated ones for (Balloon each : balloon) { System.out.println(each); } break; case '4': // Print all balloons for (Balloon each : balloon) { System.out.println(each.toString()); } System.out.println("Number of balloons "+balloon.length); break; // Quiting case 'Q': System.out.println("Quiting"); break; // Invalid number default: System.out.println("Choice must be a value between 0 and 4."); } } while (choice != 'Q'); System.out.println("We already have " + Balloon.getQuantity() + " balloon(s)"); } } class Balloon { private int size; private String color; boolean inflated; private static int quantity = 0; // Constructor receives size and color Balloon(int s, String c) { size = s; color = c; quantity++; } // Return the size public static int getSize(int s) { Balloon.IsValidSize(s); return s; } // Return the color public static String getColor(String c) { Balloon.IsValidColor(c); return c; } // Return quantity static int getQuantity() { return quantity; } //Validate the size static String IsValidSize(int s) { if (s == 6 || s == 8 || s == 10 || s == 12) return " "; else return "Invalid size.Please Try again"; } //Validate the color static String IsValidColor(String c) { if (c.equalsIgnoreCase("red") || c.equalsIgnoreCase("blue") || c.equalsIgnoreCase("green") || c.equalsIgnoreCase("yellow")) return " "; else return "Invalid color. please Try again. "; } // Balloon exists public static boolean IsValidBalloon(Balloon arg) { return arg != null; } // Destroy a balloon public static void destroy(int d, Balloon[] arg) { quantity--; arg[d] = null; } // Is Balloon inflated public static boolean IsBalloonInflated (int i, Balloon[] arg) { return arg[i].inflated ; } // Inflate a balloon public static void inflate(int i, Balloon[] arg) { arg[i].inflated = true; } @Override public String toString() { return "Balloon{" + "size=" + size + ", color='" + color + '\'' + ", inflated=" + inflated + '}'; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started