Question
Pt.1 import java.util.*; /** * Code for Problem 1 of HW2 * @author */ public class ArraySum { /** Gets the sum of the numbers
Pt.1
import java.util.*;
/** * Code for Problem 1 of HW2 * @author */ public class ArraySum {
/** Gets the sum of the numbers in "dataset". @return sum of the numbers */ public int getSum(ArrayList
PT.2
import java.util.Scanner;
/** * Code for P7.12 * @author */ public class SeatingChart { /** Prints the price of seats in a grid like pattern. @param seats a 2D array of prices */ public void printSeats(int[][] seats) { System.out.print(" "); for (int j = 0; j
/** Marks a seat with the price given to 0. If there is no seat with the price, print an error message. @param seats: the array of seat prices @param price: the price to mark to zero */ public void sellSeatByPrice(int[][] seats, int price) { // COMPLETE THIS METHOD // System.out.println("Sorry, no seat found with that price."); }
/** Marks a seat based on a given row and seat number from input. If seat or row numbers are invalid, print error messages. If the seat is already occupied, print error message. @param seats: the array of seat prices @param rownum: row number @param seatnum: seat number */ public void sellSeatByNumber(int[][] seats, int rownum, int seatnum) { // COMPLETE THIS METHOD //System.out.println("Sorry, seat already occupied."); //System.out.println("Sorry, invalid seat number."); //System.out.println("Sorry, invalid row."); }
public static void main(String[] args) { // initial values come from problem description int[][] seats = { { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 }, { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 }, { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 }, { 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 }, { 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 }, { 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 } };
SeatingChart seating = new SeatingChart(); seating.printSeats(seats);
System.out.println("Pick by eat or
rice or rice or rice or rice or rice or rice or rice or rice or to quit: "); Scanner in = new Scanner(System.in); String choice = in.next(); while (!choice.equals("q")) { if (choice.equals("s")) { System.out.println("Enter the row number you want: "); int rownum = in.nextInt(); System.out.println("Enter the seat number you want: "); int seatnum = in.nextInt(); seating.sellSeatByNumber(seats, rownum, seatnum); } else { // pick by price System.out.println("What price do you want to buy?"); int price = in.nextInt(); seating.sellSeatByPrice(seats, price); } seating.printSeats(seats); System.out.println("Pick by
eat or to quit: "); choice = in.next(); } in.close(); } }
eat or to quit: Enter the row number you want: Enter the seat number you want: s1 s2 s3 s4 s5 s6 s7 58 59 s10 r9: 10 10 10 10 10 10 10 10 10 10 r8: 10 10 10 10 10 10 10 10 10 10 r7: 10 10 10 10 10 10 10 10 10 10 r6: 10 10 20 20 20 20 20 20 10 10 r5: 0 10 20 20 20 20 20 20 10 10 r4: 10 10 20 20 20 20 20 20 10 10 r3: 20 20 30 30 40 40 30 30 20 20 r2: 20 30 30 40 50 50 40 30 30 20 r1: 30 40 50 50 50 50 50 50 40 30 Pick by
eat or to quit: What price do you want to buy? 40 s1 s2 s3 s4 55 56 57 58 59 s10 r9: 10 10 10 10 10 10 10 10 10 10 r8: 10 10 10 10 10 10 10 10 10 10 r7: 10 10 10 10 10 10 10 10 10 10 r6: 10 10 20 20 20 20 20 20 10 10 r5: 0 10 20 20 20 20 20 20 10 10 r4: 10 10 20 20 20 20 20 20 10 10 r3: 20 20 30 30 0 40 30 30 20 20 r2: 20 30 30 40 50 50 40 30 30 20 r1: 30 40 50 50 50 50 50 50 40 30 Pick by
eat or to quit: Appendix A: Scanned Textbook Problems - P7.7 A theater seating chatt is implemented as a two-dimensional array of ticket prices, like this 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 20 20 30 30 40 40 30 30 20 20 20 30 30 40 50 50 40 30 30 20 30 40 50 50 50 50 50 50 40 30 Write a program that prompts users to pick either a seat or a price. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price. Appendix B: Example Run of P7.7 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 r9: 10 10 10 10 10 10 10 10 10 10 r8: 10 10 10 10 10 10 10 10 10 10 r7: 10 10 10 10 10 10 10 10 10 10 r6: 10 10 20 20 20 20 20 20 10 10 r5: 10 10 20 20 20 20 20 20 10 10 r4: 10 10 20 20 20 20 20 20 10 10 r3: 20 20 30 30 40 40 30 30 20 20 r2: 20 30 30 40 50 50 40 30 30 20 r1: 30 40 50 50 50 50 50 50 40 30 Pick by
eat or to quit: Enter the row number you want: Enter the seat number you want: s1 s2 s3 s4 s5 s6 s7 58 59 s10 r9: 10 10 10 10 10 10 10 10 10 10 r8: 10 10 10 10 10 10 10 10 10 10 r7: 10 10 10 10 10 10 10 10 10 10 r6: 10 10 20 20 20 20 20 20 10 10 r5: 0 10 20 20 20 20 20 20 10 10 r4: 10 10 20 20 20 20 20 20 10 10 r3: 20 20 30 30 40 40 30 30 20 20 r2: 20 30 30 40 50 50 40 30 30 20 r1: 30 40 50 50 50 50 50 50 40 30 Pick by
eat or to quit: What price do you want to buy? 40 s1 s2 s3 s4 55 56 57 58 59 s10 r9: 10 10 10 10 10 10 10 10 10 10 r8: 10 10 10 10 10 10 10 10 10 10 r7: 10 10 10 10 10 10 10 10 10 10 r6: 10 10 20 20 20 20 20 20 10 10 r5: 0 10 20 20 20 20 20 20 10 10 r4: 10 10 20 20 20 20 20 20 10 10 r3: 20 20 30 30 0 40 30 30 20 20 r2: 20 30 30 40 50 50 40 30 30 20 r1: 30 40 50 50 50 50 50 50 40 30 Pick by
eat or to quit
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