This commit is contained in:
End 2026-03-25 09:44:12 -07:00
parent cbe9180219
commit 1b8e3634bb
No known key found for this signature in database
23 changed files with 1128 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/* Lesson 2 Coding Activity Question 4 */
import java.util.Scanner;
public class U5_L2_Activity_Four {
public static void coinConverter(int pennies) {
int dollars = pennies / 100;
pennies = pennies % 100;
int quarters = pennies / 25;
pennies = pennies % 25;
int dimes = pennies / 10;
pennies = pennies % 10;
int nickels = pennies / 5;
pennies = pennies % 5;
System.out.println("Dollar Bills: " + dollars);
System.out.println("Quarters: " + quarters);
System.out.println("Dimes: " + dimes);
System.out.println("Nickels: " + nickels);
System.out.println("Pennies: " + pennies);
}
/* Add the method coinConverter() here */
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,23 @@
/* Lesson 2 Coding Activity Question 2 */
import java.util.Scanner;
public class U5_L2_Activity_Two {
/* Add the method reverser here */
public static void reverser(String s) {
for (int i = s.length() - 1; i >= 0; i--) {
System.out.print(s.charAt(i));
}
System.out.println();
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,37 @@
/* Lesson 2 Coding Activity Question 1 */
import java.util.Scanner;
public class U5_L2_Activity_One {
public static void timeOfDay(int hour) {
switch (hour) {
case 0:
System.out.println("midnight");
break;
case 12:
System.out.println("noon");
break;
case 18:
System.out.println("dusk");
break;
default:
if (hour < 12) {
System.out.println("morning");
} else if (hour < 18) {
System.out.println("afternoon");
} else {
System.out.println("evening");
}
}
}
/* Add the method timeOfDay() here */
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,20 @@
/* Lesson 2 Coding Activity Question 3 */
import java.util.Scanner;
public class U5_L2_Activity_Three {
/* Add the method printDouble() here */
public static void printDouble(double num, int n) {
for (int i = 0; i < n; i++) {
System.out.println(num);
}
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,20 @@
/* Lesson 3 Coding Activity Question 1 */
import java.util.Scanner;
import shapes.*;
public class U5_L3_Activity_One {
/* Add the method makeEqTriangle here */
public static void makeEqTriangle(RegularPolygon p) {
p.setNumSides(3);
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before submitting your code
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,21 @@
/* Lesson 3 Coding Activity Question 3 */
import java.util.Scanner;
import shapes.*;
public class U5_L3_Activity_Three {
public static void updateNumSides(RegularPolygon polygon, int sides) {
polygon.setNumSides(sides);
}
/* Add the method updateNumSides here */
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before submitting your code
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,24 @@
/* Lesson 3 Coding Activity Question 2 */
import java.util.Scanner;
import shapes.*;
import testing.Math;
public class U5_L3_Activity_Two {
/* Add the method randomize here */
public static void randomize(Rectangle r) {
int length = (int) (Math.random() * 6) * 2 + 10;
int width = (int) (Math.random() * 4) * 2 + 7;
r.setLength(length);
r.setWidth(width);
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before submitting your code
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,24 @@
/* Lesson 4 Coding Activity Question 4 */
import java.util.Scanner;
public class U5_L4_Activity_Four {
public static int substringCount(String str, String sub) {
int count = 0;
int index = 0;
while ((index = str.indexOf(sub, index)) != -1) {
count++;
index++;
}
return count;
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,19 @@
/* Lesson 4 Coding Activity Question 1 */
import java.util.Scanner;
import shapes.*;
public class U5_L4_Activity_One {
public static int totalSides(RegularPolygon poly1, RegularPolygon poly2) {
return poly1.getNumSides() + poly2.getNumSides();
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before submitting your code
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,19 @@
/* Lesson 4 Coding Activity Question 3 */
import java.util.Scanner;
import shapes.*;
public class U5_L4_Activity_Three {
public static double circDiff(Circle c1, Circle c2) {
return Math.abs(c1.getCircumference() - c2.getCircumference());
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before submitting your code
/*
public static void main(String[] args){
}
*/
}

View file

@ -0,0 +1,18 @@
/* Lesson 4 Coding Activity Question 2 */
import java.util.Scanner;
public class U5_L4_Activity_Two {
public static double distance(int x1, int y1, int x2, int y2) {
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
// You can uncomment and add to the main method to test your code
// You will need to remove/comment out this method before checking your code for a score
/*
public static void main(String[] args){
}
*/
}

63
U5/L5/Oven.java Normal file
View file

@ -0,0 +1,63 @@
public class Oven {
// Represents the maximum possible temperature of an oven
private int maxTemp;
// Represents the current temperature of an oven
private int currentTemp;
// Constructs an oven with the given max temp and starting temp. The maximum
// temperature of an oven must be greater than 0, but no more than 500.
// The starting temperature should be less than or equal to the maximum t
// temperature, but no less than 0.
public Oven(int maxTemperature, int startTemperature) {
if (maxTemperature > 500 || maxTemperature < 0) {
maxTemp = 500;
} else {
maxTemp = maxTemperature;
}
if (startTemperature > maxTemp) {
currentTemp = maxTemp;
} else if (startTemperature < 0) {
currentTemp = 0;
} else {
currentTemp = startTemperature;
}
}
// Returns the maximum temperature of an oven
public int getMaxTemp() {
return maxTemp;
}
// Returns the current temperature of an oven
public int getCurrentTemp() {
return currentTemp;
}
// Turns an oven off by setting the current temperature to 0.
public void turnOff() {
if (currentTemp > 0) {
currentTemp = 0;
}
}
// Returns whether the current temperature of an oven is greater than 0. Should
// return false if the current temperature is 0.
public boolean isOn() {
return currentTemp > 0;
}
// Sets the current temperature of an oven to the given value. Remember,
// the current temperature should not exceed the max temp.
public void preheat(int temp) {
if (temp <= 0) {
return;
} else if (temp > maxTemp) {
currentTemp = maxTemp;
} else {
currentTemp = temp;
}
}
}

View file

@ -0,0 +1,28 @@
public class Person {
private String firstName;
private String lastName;
private int age;
private String ssn;
public Person(String firstName, String lastName, int age, String ssn) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.ssn = ssn;
}
@Override
public String toString() {
return (
"SSN: " +
ssn +
"\n\tName: " +
firstName +
" " +
lastName +
"\n\tAge: " +
age
);
}
}

49
U5/L5/runner_Oven.java Normal file
View file

@ -0,0 +1,49 @@
import java.util.Scanner;
public class runner_Oven {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Maximum oven temperature:");
int maxTemp = scan.nextInt();
System.out.println("Starting temperature of the oven:");
int startTemp = scan.nextInt();
Oven oven = new Oven(maxTemp, startTemp);
String instruction = "";
while (!instruction.equals("q")) {
System.out.println(
"New oven with a maximum temperature of " +
oven.getMaxTemp() +
" and a starting temperature of " +
oven.getCurrentTemp() +
" degrees."
);
System.out.println(
"To preheat the oven enter \"p\", to turn the oven off enter" +
" \"o\", to restart enter \"r\", to quit enter \"q\""
);
instruction = scan.next();
if (instruction.equals("p")) {
System.out.println(
"Enter the temperature to preheat the oven to:"
);
int temp = scan.nextInt();
oven.preheat(temp);
System.out.println(
"Current temperature of the oven is now " +
oven.getCurrentTemp() +
" degrees\n"
);
} else if (instruction.equals("o")) {
System.out.println("Turning the oven off.\n");
oven.turnOff();
}
}
}
}

46
U5/L6/Plane.java Normal file
View file

@ -0,0 +1,46 @@
public class Plane {
private int location;
public Plane() {
location = 0;
}
public Plane(int loc) {
if (loc >= -2000 && loc <= 2000) {
location = loc;
} else {
location = 0;
}
}
public void upward() {
if (location + 100 > 2000) {
location = 2000;
} else {
location += 100;
}
}
public void downward() {
if (location - 100 < -2000) {
location = -2000;
} else {
location -= 100;
}
}
public int getLocation() {
return location;
}
public String toString() {
int spaces = (location + 2000) / 100;
String result = "";
for (int i = 0; i < spaces; i++) {
result += " ";
}
result += "@";
return result;
}
}

30
U5/L6/runner_Plane.java Normal file
View file

@ -0,0 +1,30 @@
import java.util.Scanner;
public class runner_Plane {
public static void main(String str[]) {
Scanner scan = new Scanner(System.in);
Plane p = new Plane();
String instruction = "";
while (!instruction.equals("q")) {
System.out.println(p);
System.out.println("Location: " + p.getLocation());
System.out.println(
"Type \"u\" to move upwards, \"d\" to move downwards, \"n\" for new Plane, \"q\" to quit."
);
instruction = scan.nextLine();
if (instruction.equals("u")) {
p.upward();
} else if (instruction.equals("d")) {
p.downward();
} else if (instruction.equals("n")) {
System.out.println("Starting location for a new Plane?");
int start = scan.nextInt();
p = new Plane(start);
scan.nextLine();
} else if (!instruction.equals("q")) {
System.out.println("Instruction not recognized.");
}
}
}
}

56
U5/L7/Rectangle.java Normal file
View file

@ -0,0 +1,56 @@
public class Rectangle {
private double base;
private double height;
public Rectangle() {
base = 1;
height = 1;
}
public Rectangle(double base, double height) {
this.base = (base > 0) ? base : 1;
this.height = (height > 0) ? height : 1;
}
public double getBase() {
return base;
}
public double getHeight() {
return height;
}
public void setBase(double base) {
if (base > 0) {
this.base = base;
}
}
public void setHeight(double height) {
if (height > 0) {
this.height = height;
}
}
public double getArea() {
return base * height;
}
public double getPerimeter() {
return 2 * base + 2 * height;
}
public double getDiagonal() {
return Math.sqrt(base * base + height * height);
}
public boolean equals(Rectangle other) {
return this.base == other.base && this.height == other.height;
}
@Override
public String toString() {
return "Rectangle[base=" + base + ",height=" + height + "]";
}
}

View file

@ -0,0 +1,54 @@
import java.util.Scanner;
public class runner_Rectangle {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Rectangle r = new Rectangle();
String instruction = "";
while (!instruction.equals("q")) {
System.out.println(
"Type the name of the method to test. Type c to construct a new rectangle, q to quit."
);
instruction = scan.nextLine();
if (instruction.equals("getArea")) {
System.out.println(r.getArea());
} else if (instruction.equals("getBase")) {
System.out.println(r.getBase());
} else if (instruction.equals("getHeight")) {
System.out.println(r.getHeight());
} else if (instruction.equals("getPerimeter")) {
System.out.println(r.getPerimeter());
} else if (instruction.equals("toString")) {
System.out.println(r);
} else if (instruction.equals("getDiagonal")) {
System.out.println(r.getDiagonal());
} else if (instruction.equals("setBase")) {
System.out.println("Enter parameter value:");
double arg = scan.nextDouble();
r.setBase(arg);
scan.nextLine();
} else if (instruction.equals("setHeight")) {
System.out.println("Enter parameter value:");
double arg = scan.nextDouble();
r.setHeight(arg);
scan.nextLine();
} else if (instruction.equals("equals")) {
System.out.println("Enter base and height:");
double bs = scan.nextDouble();
double ht = scan.nextDouble();
Rectangle rOther = new Rectangle(bs, ht);
System.out.println(r.equals(rOther));
scan.nextLine();
} else if (instruction.equals("c")) {
System.out.println("Enter base and height:");
double bs = scan.nextDouble();
double ht = scan.nextDouble();
r = new Rectangle(bs, ht);
scan.nextLine();
} else if (!instruction.equals("q")) {
System.out.println("Not recognized.");
}
}
}
}

150
U5/Player.java Normal file
View file

@ -0,0 +1,150 @@
public class Player {
private static int numPlayers = 0;
private int x;
private int y;
private int z;
private int direction;
private int hp;
private String name;
public Player() {
numPlayers++;
this.name = "P" + numPlayers;
this.x = 0;
this.y = 0;
this.z = 0;
this.hp = 20;
this.direction = 1;
}
public Player(String name, int x, int y, int z) {
numPlayers++;
this.name = name;
this.x = x;
this.y = y;
this.z = z;
this.hp = 20;
this.direction = 1;
}
public Player(String name, int x, int y, int z, int health, int direction) {
numPlayers++;
this.name = name;
this.x = x;
this.y = y;
this.z = z;
this.hp = (health < 0) ? 0 : health;
this.direction = (direction < 1 || direction > 6) ? 1 : direction;
}
public static int getNumPlayers() {
return numPlayers;
}
public String getName() {
return name;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public int getHp() {
return hp;
}
public int getDirection() {
return direction;
}
public String toString() {
return (
"Name: " +
name +
"\n" +
"Health: " +
hp +
"\n" +
"Coordinates: X " +
x +
" Y " +
y +
" Z " +
z +
"\n" +
"Direction: " +
direction
);
}
public void setHp(int hp) {
this.hp = (hp < 0) ? 0 : hp;
}
public void setDirection(int direction) {
if (direction >= 1 && direction <= 6) {
this.direction = direction;
}
}
public void move(int direction, int units) {
switch (direction) {
case 1:
x += units;
break;
case 2:
x -= units;
break;
case 3:
y += units;
break;
case 4:
y -= units;
break;
case 5:
z += units;
break;
case 6:
z -= units;
break;
}
}
public void teleport(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public void teleport(Player player) {
this.x = player.getX();
this.y = player.getY();
this.z = player.getZ();
}
public void attack(Player player, int damage) {
player.setHp(player.getHp() - damage);
this.hp += damage / 2;
}
public double getDistance(int x, int y, int z) {
int dx = this.x - x;
int dy = this.y - y;
int dz = this.z - z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
public double getDistance(Player player) {
return getDistance(player.getX(), player.getY(), player.getZ());
}
}

56
U5/U8/Car.java Normal file
View file

@ -0,0 +1,56 @@
public class Car {
private static int nextID = 1;
private int carID;
private String make;
private String model;
private int year;
private double mpg;
public Car() {
make = "None";
model = "None";
year = 2000;
mpg = 0;
carID = nextID;
nextID++;
}
public Car(String make, String model, int year, double mpg) {
this.make = make;
this.model = model;
if (year > 2022) {
this.year = 2022;
} else if (year < 1885) {
this.year = 2000;
} else {
this.year = year;
}
if (mpg < 0) {
this.mpg = 0;
} else {
this.mpg = mpg;
}
carID = nextID;
nextID++;
}
public String toString() {
return (
"ID: " +
carID +
"\nMake: " +
make +
"\nModel: " +
model +
"\nYear: " +
year +
"\nMPG: " +
mpg
);
}
}

36
U5/U8/runner_Car.java Normal file
View file

@ -0,0 +1,36 @@
import java.util.Scanner;
public class runner_Car {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String i = "";
while (!i.equals("q")) {
System.out.println(
"Input the make of the car, \"default\" to create a default car or \"q\" to quit:"
);
i = scan.nextLine();
System.out.println();
if (i.equals("q")) {
System.out.println("Exiting. Bye!");
} else if (i.equals("default")) {
Car car = new Car();
System.out.print(car);
} else {
System.out.println("Model of the car:");
String model = scan.nextLine();
System.out.println("Year of the car:");
int year = scan.nextInt();
scan.nextLine();
System.out.println("Miles per gallon of the car:");
double mpg = scan.nextDouble();
scan.nextLine();
System.out.println();
System.out.println(new Car(i, model, year, mpg));
}
System.out.println();
}
}
}

299
U5/runner_Player.java Normal file
View file

@ -0,0 +1,299 @@
import java.lang.Math;
import java.util.Scanner;
public class runner_Player {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Player p1 = null;
System.out.println("Welcome!");
System.out.println(
"This program helps you test your Player class and its methods."
);
System.out.println("A default Player object will be created for you,");
System.out.println(
"or you can use the 'c' option to use another Constructor.\n"
);
String instruction = "";
while (!instruction.equals("q")) {
System.out.println(
"Type the name of the method you want to test, or Type c to construct a new Player. Type q to quit."
);
instruction = scan.nextLine().trim();
if (instruction.equals("c")) {
System.out.println("Which constructor would you like to use?");
System.out.println(
"1 - Player(String name, int x, int y, int z)"
);
System.out.println(
"2 - Player(String name, int x, int y, int z, int hp, int direction"
);
int choice = scan.nextInt();
scan.nextLine();
if (choice != 1 && choice != 2) {
System.out.println("Invalid choice");
break;
} else {
System.out.println("Player name:");
String name = scan.nextLine().trim();
System.out.println("Starting x-coordinate:");
int x = scan.nextInt();
System.out.println("Starting y-coordinate:");
int y = scan.nextInt();
System.out.println("Starting z-coordinate:");
int z = scan.nextInt();
if (choice == 1) {
p1 = new Player(name, x, y, z);
System.out.println("New player created!");
System.out.println(p1);
} else {
System.out.println("Starting health points:");
int hp = scan.nextInt();
System.out.println("Starting direction");
int dir = scan.nextInt();
p1 = new Player(name, x, y, z, hp, dir);
System.out.println("New player created!");
System.out.println(p1);
}
scan.nextLine();
}
instruction = scan.nextLine().trim();
} else if (p1 == null) {
p1 = new Player();
}
if (instruction.equals("getNumPlayers")) {
System.out.println(
"There are " +
Player.getNumPlayers() +
" existing Player objects"
);
} else if (instruction.equals("getX")) {
System.out.println(
"The x-coordinate of " + p1.getName() + " is X " + p1.getX()
);
} else if (instruction.equals("getY")) {
System.out.println(
"The y-coordinate of " + p1.getName() + " is Y " + p1.getY()
);
} else if (instruction.equals("getZ")) {
System.out.println(
"The z-coordinate of " + p1.getName() + " is Z " + p1.getZ()
);
} else if (instruction.equals("getHp")) {
System.out.println(
p1.getName() + " has " + p1.getHp() + " health points"
);
} else if (instruction.equals("getDirection")) {
System.out.println(
p1.getName() + " is facing " + p1.getDirection()
);
} else if (instruction.equals("toString")) {
System.out.println(p1);
} else if (instruction.equals("getName")) {
System.out.println("The players name is " + p1.getName());
} else if (instruction.equals("move")) {
System.out.println("Enter the direction (1-6) to move in:");
int direction = scan.nextInt();
System.out.println("Enter the number of units to move");
int units = scan.nextInt();
scan.nextLine();
p1.move(direction, units);
System.out.println(
p1.getName() +
" is now at coordinates X " +
p1.getX() +
" Y " +
p1.getY() +
" Z " +
p1.getZ()
);
} else if (instruction.equals("setHp")) {
System.out.println(
"Enter the new health of " + p1.getName() + ":"
);
int hp = scan.nextInt();
scan.nextLine();
p1.setHp(hp);
System.out.println(
p1.getName() + " now has " + p1.getHp() + " health points"
);
} else if (instruction.equals("setDirection")) {
System.out.println(
"Enter the new direction that " +
p1.getName() +
" is facing:"
);
int dr = scan.nextInt();
scan.nextLine();
String dir;
p1.setDirection(dr);
dr = p1.getDirection();
if (dr == 1) {
dir = "North";
} else if (dr == 2) {
dir = "South";
} else if (dr == 3) {
dir = "Up";
} else if (dr == 4) {
dir = "Down";
} else if (dr == 5) {
dir = "East";
} else if (dr == 6) {
dir = "West";
} else {
dir = "an invalid direction";
}
System.out.println(p1.getName() + " is now facing " + dir);
} else if (instruction.equals("attack")) {
Player p2 = new Player();
System.out.println(
p1.getName() + " is attacking " + p2.getName()
);
System.out.println(
"Damage " +
p1.getName() +
" should deal to " +
p2.getName() +
":"
);
int damage = scan.nextInt();
scan.nextLine();
p1.attack(p2, damage);
System.out.println(p2.getName() + " now has " + p2.getHp());
System.out.println(p1.getName() + " now has " + p1.getHp());
} else if (instruction.equals("teleport")) {
System.out.println("Method 1 or 2?");
System.out.println("1 - teleport(int x, int y, int z)");
System.out.println("2 - teleport(Player p)");
int choice = scan.nextInt();
scan.nextLine();
if (choice == 1) {
System.out.println("X-coordinate to teleport to:");
int x = scan.nextInt();
System.out.println("Y-coordinate to teleport to:");
int y = scan.nextInt();
System.out.println("Z-coordinate to teleport to:");
int z = scan.nextInt();
scan.nextLine();
p1.teleport(x, y, z);
System.out.println(
p1.getName() +
" teleported to X " +
p1.getX() +
" Y " +
p1.getY() +
" Z " +
p1.getZ()
);
} else if (choice == 2) {
int x = (int) (Math.random() * 11);
int y = (int) (Math.random() * 11);
int z = (int) (Math.random() * 11);
Player p2 = new Player(
"P" + (Player.getNumPlayers() + 1),
x,
y,
z
);
System.out.println(
p2.getName() +
" is at X " +
p2.getX() +
" Y " +
p2.getY() +
" Z " +
p2.getZ()
);
System.out.println(
"Teleporting " + p1.getName() + " to " + p2.getName()
);
p1.teleport(p2);
System.out.println(
p1.getName() +
" now at X " +
p1.getX() +
" Y " +
p1.getY() +
" Z " +
p1.getZ()
);
if (
p1.getX() == p2.getX() &&
p1.getY() == p2.getY() &&
p1.getZ() == p2.getZ()
) {
System.out.println(
"The Players are at the same location"
);
} else {
System.out.println(
"The Players are in different locations"
);
}
} else {
System.out.println("Invalid choice");
}
} else if (instruction.equals("getDistance")) {
System.out.println("Method 1 or 2?");
System.out.println("1 - distance(int x, int y, int z)");
System.out.println("2 - distance(Player p)");
int choice = scan.nextInt();
scan.nextLine();
if (choice == 1) {
System.out.println("X-coordinate:");
int x = scan.nextInt();
System.out.println("Y-coordinate:");
int y = scan.nextInt();
System.out.println("Z-coordinate:");
int z = scan.nextInt();
scan.nextLine();
System.out.printf(
"%s is %f units from X %d Y %d Z %d",
p1.getName(),
p1.getDistance(x, y, z),
x,
y,
z
);
} else if (choice == 2) {
Player p2 = new Player(
"P" + (Player.getNumPlayers() + 1),
10,
-5,
87
);
System.out.printf(
"The distance between %s and %s is %f",
p1.getName(),
p2.getName(),
p1.getDistance(p2)
);
} else {
System.out.println("Invalid choice");
}
} else if (instruction.equals("q")) {
System.out.println("Exiting. Bye!");
} else {
System.out.println("Invalid instruction");
}
System.out.println();
}
}
}