Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What this Assignment Is About: Given a UML diagram, learn to design a class. Lea

ID: 3817178 • Letter: W

Question

What this Assignment Is About:

Given a UML diagram, learn to design a class.

Learn how to define, intialize and fill a two dimensional array.

Learn how to traverse and access a two dimensional array.

File provided: Assignment7.java

Coding Guidelines for All Labs/Assignments (You will be graded on this)

Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

Keep identifiers to a reasonably short length.

Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

Use white space to make your program more readable.

Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs.

Assignment description

In this assignment, you will need to write programs that help boat ride companies in Maine to sell boat ride tickets to tourists. Below please find the specifications:

Assume that each siteseeing boat has 8 rows, with 6 seats in each row. To represent the seats, the BoatRideManager class should have a two-dimensional array of String as the underline data structure (see the following UML); we use "O " (big oh with one empty space to its right) to reprent that a seat is available (or empty), and use "# " (hex with one empty space to its right) to represent it is already occupied (or sold). Meanwhile, to simplify the task, we assume that the ticket's price is $35.0 per person, no matter what is the passenger's age!

At the very beginning, a boat is always empty, i.e. all the 48 seats should be set to "O "(see the following), but after the program runs, some seats might be sold out and the seats become "# "

         Seats
      1 2 3 4 5 6
Row 1 O O O O O O
Row 2 O O O O O O
Row 3 O O O O O O
Row 4 O O O O O O
Row 5 O O O O O O
Row 6 O O O O O O
Row 7 O O O O O O
Row 8 O O O O O O

Legend: # = Sold
        O = Available

Each time when a customer try to purchase tickets, they can purchase up to 6 tickets, all in one row, if for example, they want to purchase >= 6 tickets, in two diffterent rows, they will need to do two transactions, i.e. purchase twice in each of the rows accordingly.

The driver program, namely Assignment7.java is a menu-driven programt that provides the user with a menu of boat ticket purchasing options, it also accepts and validates user inputs, and call appropriate class methods to carry out desired tasks. The menu has options to display the seating chart, request boat tickets, print a sales report and exit the program, etc.

1. Step #1: According to the following UML diagram, create a BoatRideManager class, save the souce code as BoatRideManager.java

Instance variables and methods' description

First, the purchaseTickets() method will call above checkAvailability() method to make sure the tickets request is valid. If the request is valid, it then prompt to ask user to enter money amount such as:

" Please input amount paid: $"

1. If the amount is sufficient, it will sell the tickets and do the following:
- Mark these seats taken
- Call printTickets() to print the actual tickets
- Update the seatsSold and totalRevenue
- Display a purchase summary, such as the following one for the user:

Tickets purchased : 5
Payment           : $200.0
Total ticket price: $175.0
Change due        : $25.0

2. In case user entered insufficient amout of money, show the following message on screen:

" Insufficient payment.";
" The sale has been cancelled and your money is being returned. "

2. Step #2: You are given a partially finished driver prgroam called Assignment7.java, which has the main() method to create one new BoatRideManager objects called LuluBoatRide which will be used to check those methods in BoatRideManager.java class (see sample input & output files). //---- is where you need to fill in your own codes according to the instructions. The Assignment7.java will display the following menu to the user:

  Choose an Action
--------------------------
D: Display Seat Map
P: Purchase Boat Ride Tickets
S: Display Sales Report
?: Display the menu again
Q: Quit this program

The program will ask “Please enter a command: ”. A user will type in a character of their menu choice. Note: user might enter both upper case or lower case letters. Please find below for each command's description


And the assignment7.java is below

//**************************************************************************
// FILE: Assignment7.java
// Name: your-name
// Student ID: your-ASU-10-digits-ID
// Description: Driver program used to test and check BoatRideManager.java
// Course: ASU CSE110 Principles of Programming with Java
//***************************************************************************

import java.util.Scanner;

class Assignment7
{
   public static void main(String[] args)
   {
      Scanner console = new Scanner(System.in);

      //Create a BoatRideManager object call 'LuluBoatRide'
      //----
      String choice; // User's menu choice
      int numSeats;  // Number of seats wanted
      int row;   // Desired row
      int startSeat; // Desired starting seat number

      //Used to check whether requested tickets available for sale or not
      boolean ticketRequestOK = true;

      do
      {
    //call the relevant method to display the menu on screen
    //----

         // ask the user to choose a command
         System.out.print(" Please enter a command: ");
         choice = console.next().toUpperCase();
         switch(choice)
         {
            case "D":
            //Display the seat map of LuluBoatRide
            //----
                break;
            case "P": //reserve tickets
            System.out.print(" Number of seats desired (1 - 6): ");
                numSeats = console.nextInt();

               //input validation loop. Need to make sure customer can
               //order up to 6 seats only.i.e. numSeats must be in range [1,6]
               //----
               //----

               System.out.print(" Desired row (1-8): ");
               row = console.nextInt();

               //input validation loop. Need to make sure the row number
               //must be within range [1, 8]
               //----
               //----

               System.out.print("Desired starting seat number in the row (1 - 6): ");
               startSeat = console.nextInt();

               //input validation loop
               while(startSeat < 1 || startSeat >6)
               {
                  System.out.print(" Wrong, start seat number must between 1 to 6");
                  System.out.print(" Re-enter desired start seat number(1 - 6): ");
                  startSeat = console.nextInt();
               }

               //With all above info. check the requested seats availibility,
               //save the result inside variable ticketRequestOK
               ticketRequestOK = //----;

               if (ticketRequestOK)
               {
                  System.out.print(" Do you wish to purchase these tickets (Yes/No)? ");
                  if(console.next().toUpperCase().equals("YES"))
                  {
       //call the relevant method in BoatRideManager to purchase these tickets
       //----
                  }
               }
               break;
            case "S":
               //call the relevant method in BoatRideManager to display a sales report
               //----
               break;
            case "?":
               displayMenu();
               break;
            case "Q":
               break;
            default:
               System.out.print(" Invalid input");
         }// end switch
      } while (!choice.equals("Q"));
   }// end main

   public static void displayMenu()
   {
      System.out.print(" Lulu Boat Ride Online Purchase System ");
      System.out.print("       Choose an Action "
             + "------------------------------ "
             + "D: Display Seats Map "
             + "P: Purchase Boat Ride Ticket "
             + "S: Display Sales Report "
               + "?: Display the menu again "
             + "Q: Quit this program ");
   }
}

BoatRideManager NUM_ROWS: int (final)
ROW_SIZE: int (final)
SEAT_PRICE: double (final)
-seatArray: String[][]
-seatsSold: int
-totalRevenue: double +BoatRideManager()
+displaySeats(): void
+checkAvailability(int, int, int): boolean
+purchaseTickets(int, int, int): void
+printTickets(int, int, int): void
+displaySalesReport(): void TAF4:21 T 100% oo AT&T; public asu.edu ASU CSE 110 Assignment #7 Due date/Time: Friday, April 14, 2017 at 5:30pm What this Assignment is About: Given a UML diagram, learn to design a class. Leam how to define, intialize and fill a two dimensional array. Leam how to traverse and access a two dimensional array. File provided AssignmentZjava Coding Guidelines for All LabsAssignments Oou will be graded on this) Give identifiers semantic meaning and make them easy to read (examples numStudents, gross Pay, etc). Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Use comments properly before or after the ending brace of classes, methods, and blocks to identify to which block it belongs. Assignment description In this assignment, you will need to write programs that help boat ride companies in Maine to sell boat ride tickets to tourists, Below please find the specifications: Assume that each siteseeing boat has 8 rows, with 6 seats in each row. To represent the seats, the BoatRideManager class should have a two-dimensional array of String as the underline data structure (see the following UML); we use "O (big oh with one empty space to its right to reprent that a seat is available (or empty) and use "E (hex with one empty space to its right) to represent itis already occupied (or sold Meanwhile, to simplify the task, we assume that the ticket's price is S35.0 per person, no matter what is the s age At the very beginning, a boat is always empty, i.e. all the 48 seats should be set to "O but after the program runs, some seats might be sold out and the seats become Seats 1 2 3 4 5 6 Row 1 O O O O O O Row 2 O O O O O O Row 3 O O O O O O Row 4 O O O O O O Row 5 O O O O O O

Explanation / Answer


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


/**
*
* @author Sam
*/
public class BoatRideManager {
    private final int NUM_ROWS = 8;
    private final int ROWS_SIZE = 6;
    private final double SEAT_PRICE = 35;
    private final String[][] seatArray;
    private int seatsSold;
    private double totalRevenue;

    public BoatRideManager() {
        seatArray = new String[NUM_ROWS][ROWS_SIZE];
        for (int i = 0; i<NUM_ROWS; i++)
            for(int j = 0; j<ROWS_SIZE; j++)
                seatArray[i][j] = "O";
        seatsSold = 0;
        totalRevenue = 0;
    }
  
    public void displaySeats() {
        System.out.println("      Seats");
        System.out.println("      1 2 3 4 5 6");
        for (int i = 0; i<NUM_ROWS; i++){
            System.out.print("Row "+(i+1)+" ");
            for(int j = 0; j<ROWS_SIZE; j++)
                System.out.print(seatArray[i][j]+" ");
            System.out.println();
        }
        System.out.println("Legend: # = Sold O = Available");
    }


    public boolean checkAvailability(int numSeatsRequested, int requestedRow, int startSeat){
        int lastSeatWnated = startSeat + numSeatsRequested - 1;
        if (lastSeatWnated > 6) {
            System.out.print(" One or more of the seats you have requested do not exist, re-book please. ");
            return false;
        }
        for (int i = startSeat-1; i<lastSeatWnated; i++)
            if (seatArray[requestedRow][i].equals("#")) {
                System.out.println(" One or more of the seats you have requested are already sold. ");
                return false;
            }
        System.out.println(" The seats you have requested are available for purchase.");
        System.out.println(" The total purchase price will be: " + numSeatsRequested + " seats X $35.0 = " + (SEAT_PRICE*numSeatsRequested));
        return true;
    }
  
     public void purchaseTickets(int numSeats, int requestedRow, int startSeat) throws IOException{
         if (!checkAvailability(numSeats, requestedRow, startSeat))
             return;
         System.out.println("Paid amount: ");
         double paid = Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine());
         if (paid < numSeats*SEAT_PRICE) {
             System.out.println(" Insufficient payment.");
             System.out.println(" The sale has been cancelled and your money is being returned. ");
             return;
         }
         int lastSeatWnated = startSeat + numSeats - 1;
         for (int i = startSeat-1; i<lastSeatWnated; i++)
            seatArray[requestedRow][i] = "#";
         printTickets(requestedRow, startSeat, lastSeatWnated);
         seatsSold += numSeats;
         totalRevenue += numSeats*SEAT_PRICE;
         System.out.println("Tickets purchased : "+ numSeats +" " +
            "Payment           : $" + paid + " " +
            "Total ticket price: $" + (numSeats*SEAT_PRICE) + " " +
            "Change due        : $" + (paid - numSeats*SEAT_PRICE));
     }
   
     public void printTickets(int rowNum, int firstSeatNum, int lastSeatNum) {
         System.out.println("****************************** " +
"LuLu                       Lobster Boat Ride ");
         for (int i = firstSeatNum; i<=lastSeatNum; i++)
             System.out.println("Row " + rowNum + " ~ Seat " + i);
         System.out.println("******************************");
     }
   
     public void displaySalesReport() {
         System.out.println("Lulu Lobster Boat Ride Sales Report " +
        "=================================== " +
        "Seats sold: " + seatsSold + " " +
        "Seats available: " + (NUM_ROWS*ROWS_SIZE - seatsSold) + " " +
        "Total revenue to date: $" + totalRevenue);
     }
}

class Assignment7
{
   public static void main(String[] args) throws IOException
   {
      Scanner console = new Scanner(System.in);

      BoatRideManager brm = new BoatRideManager();
      String choice; // User's menu choice
      int numSeats; // Number of seats wanted
      int row;   // Desired row
      int startSeat; // Desired starting seat number

      //Used to check whether requested tickets available for sale or not
      boolean ticketRequestOK = true;

      do
      {
        displayMenu();

         // ask the user to choose a command
         System.out.print(" Please enter a command: ");
         choice = console.next().toUpperCase();
         switch(choice)
         {
            case "D":
             brm.displaySeats();
                break;
            case "P": //reserve tickets
             System.out.print(" Number of seats desired (1 - 6): ");
                numSeats = console.nextInt();

               while(numSeats < 1 || numSeats >6)
               {
                  System.out.print(" Wrong, seat number must between 1 to 6");
                  System.out.print(" Re-enter desired seat number(1 - 6): ");
                  numSeats = console.nextInt();
               }

               System.out.print(" Desired row (1-8): ");
               row = console.nextInt();

               while(row < 1 || row >8)
               {
                  System.out.print(" Wrong, row number must between 1 to 8");
                  System.out.print(" Re-enter desired row number(1 - 8): ");
                  row = console.nextInt();
               }

               System.out.print("Desired starting seat number in the row (1 - 6): ");
               startSeat = console.nextInt();

               //input validation loop
               while(startSeat < 1 || startSeat >6)
               {
                  System.out.print(" Wrong, start seat number must between 1 to 6");
                  System.out.print(" Re-enter desired start seat number(1 - 6): ");
                  startSeat = console.nextInt();
               }

               //With all above info. check the requested seats availibility,
               //save the result inside variable ticketRequestOK
               ticketRequestOK = brm.checkAvailability(numSeats, row, startSeat);

               if (ticketRequestOK)
               {
                  System.out.print(" Do you wish to purchase these tickets (Yes/No)? ");
                  if(console.next().toUpperCase().equals("YES"))
                  {
                      brm.purchaseTickets(numSeats, row, startSeat);
                  }
               }
               break;
            case "S":
               brm.displaySalesReport();
               break;
            case "?":
               displayMenu();
               break;
            case "Q":
               break;
            default:
               System.out.print(" Invalid input");
         }// end switch
      } while (!choice.equals("Q"));
   }// end main

   public static void displayMenu()
   {
      System.out.print(" Lulu Boat Ride Online Purchase System ");
      System.out.print("       Choose an Action "
             + "------------------------------ "
             + "D: Display Seats Map "
             + "P: Purchase Boat Ride Ticket "
             + "S: Display Sales Report "
               + "?: Display the menu again "
             + "Q: Quit this program ");
   }
}

Here you go champ. this code was long!! If you are having trouble understanding the code, please match each line with the doc you have provided. Even after that if you dont understand the code, please let me know in the comment setion below. I shall explain that section of code to you, but I dont think you will need that since the code is very simple.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote