Question: Pt.1 import java.util.*; /** * Code for Problem 1 of HW2 * @author */ public class ArraySum { /** Gets the sum of the numbers

Pt.1Pt.1 import java.util.*; /** * Code for Problem 1 of HW2 *

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 dataset) { // COMPLETE THIS METHOD } /** Gets the sum of the positive numbers in "dataset". @return sum of the positive numbers */ public int getSumPositive(ArrayList dataset) { // COMPLETE THIS METHOD } /** Gets the maximum value in the array list "dataset". @return maximum value of "dataset" */ public int getMaximum(ArrayList dataset) { // COMPLETE THIS METHOD } }

PT.2

@author */ public class ArraySum { /** Gets the sum of the

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 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

rice or to quit: "); choice = in.next(); } in.close(); } }

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

rice 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

rice 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

rice 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

rice 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

rice 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

rice or to quit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!