Session 19
Source Code
import java.util.*;
public class Week19 {
public static void main(String[] args) {
String myName = ""; // add your name
System.out.println("Week 19" + " - " + myName);
// Menu
System.out.println("Menu");
System.out.println("E1 - Example 1");
System.out.println("Q - Quit");
// setup Scanner
Scanner in = new Scanner(System.in);
System.out.print("Choice: ");
String choice = in.nextLine();
// switch choices
switch (choice) {
case "E1":
System.out.println("Example 1");
example1();
break;
case "E2":
System.out.println("Example 2");
example2();
break;
case "E3":
System.out.println("Example 3");
example3();
break;
case "E4":
System.out.println("Example 4");
example4();
break;
case "E5":
System.out.println("Example 5");
example5();
break;
case "E6":
System.out.println("Example 6");
example6();
break;
case "E7":
System.out.println("Example 7");
example7();
break;
case "Q":
System.out.println("Quitting..!");
break;
}
}
// example1 method
public static void example1() {
// create a 2D array named ticketInfo
// print the number of rows and columns
}
// example2 method
public static void example2() {
// create 2D array named seatingChart
// assign the array elements
// print the elements
}
// example3 method
public static void example3() {
// 2D array with an initializer list
// Store A: Apple price, Banana price
// Store B: Apple price, Banana price
// Print the prices
}
// example4 method
public static void example4() {
// create a 3x4 matrix with values
int[][] matrix = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 }
};
// nested for loop
// Iterates through rows
// Iterates through columns
// enhanced for loop
}
// example5 method
public static void example5() {
// declare 2D array of numbers
int[][] numbers = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
// accumulate the elements
// print the sum
// calculate the average
}
// example6 method
public static void example6() {
// declare 2D array of numbers
int[][] numbers = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// initialize sum, rows and cols
// nested for loops
// Add the element if it is on the first/last row or first/last column
// print the sum
}
// example7 method
public static void example7() {
// declare 2D array of numbers
int[][] data = {
{ 12, 35, 7 },
{ 22, 18, 90 },
{ 42, 67, 55 }
};
// initialize max to the first element
// print the max
}
}
W19Problem1.java
W19Problem2.java
W19Problem3.java
W19Problem4.java
Candy.java
BoxOfCandy.java
Location.java
GridPath.java
GridPathTester.java
TheaterManagement.java
Last updated
Was this helpful?