This commit is contained in:
End 2026-03-09 21:55:57 -07:00
parent af5aaf330c
commit a213dc2f88
No known key found for this signature in database
72 changed files with 874 additions and 0 deletions

0
Code Along with verma/CodeAlong2.java Normal file → Executable file
View file

0
Code Along with verma/HelloWorld.java Normal file → Executable file
View file

0
Code Along with verma/Scannertest.java Normal file → Executable file
View file

111
Code Along with verma/check.java Executable file
View file

@ -0,0 +1,111 @@
/* Write a class WordCheck that is supposed to check if words that are valid. A word is considered valid if its within the max and min limit range, and does not contain a certain string.
Constructor that accepts 3 parameters, max and min length of a valid word, and a String that isnt allowed in the words.
Constructor that accepts 1 String parameter that isnt allowed in the word; min and max lengths are defaulted to 5 and 12 in this case.
Method isValid that accepts a String word and returns true if word is valid, false otherwise.
An accessor method getValidCount that returns the number of valid words checked so far.
Accessors and Mutators for max, min, String not allowed
Example of class runs:
WordCheck W1 = new WordCheck(4, 8, $);
W1.isValid(Hi); //returns false as word is too short
W1.isValid(Hello); //returns true as word is valid
W1.isValid(Hibernate); //returns false as word is too long
W1.isValid($Bills); //returns false as word contains $
W1.isValid(Monday); //returns true as word is valid
W1.getValidCount(); //return 2 for two valid words so far
WordCheck W2 = new WordCheck(Meep); //any words with length 5-12 and no occurrence of Meep will be valid for W2
*/
class WordCheck {
// instance var
private int max;
private int min;
private String NA;
private int validCount; // could be set to zero here instead of line 29
// create word checker tracking var that tracks # of word checkers made
public static int wordCheckCount = 0;
// first constructor
public WordCheck(int min, int max, String NA) {
this.max = max;
this.min = min;
this.NA = NA;
// this keyword point to copy of var, used for distingugh between params
this.validCount = 0;
wordCheckCount++;
}
public WordCheck(String NA) {
// one option
// this.min = 5;
// this.max = 12;
// this.NA = NA;
// easier option
this(5, 12, NA);
}
public boolean isValid(String word) {
if (
word.length() >= min &&
word.length() <= max &&
word.indexOf(NA) == -1 /* can also use !word.contains(NA) */
) {
validCount++;
return true;
}
return false;
}
// accessors & mutators, fancy way fo saying getters & setters
public int getMax() {
return this.max;
}
public void setMax(int m) {
this.max = m;
}
public int getMin() {
return this.min;
}
public void setMin(int m) {
if (this.max > m) {
this.min = m;
}
}
public String getNA() {
return this.NA;
}
public void setNA(String no) {
this.NA = no;
}
public int getValidCount() {
return this.validCount;
}
}
public class check {
public static void main(String args[]) {
WordCheck W1 = new WordCheck(4, 8, "$");
System.out.println(W1.isValid("Hi")); //returns false as word is too short
System.out.println(W1.isValid("Hello")); //returns true as word is valid
System.out.println(W1.isValid("Hibernate")); //returns false as word is too long
System.out.println(W1.isValid("$Bills")); //returns false as word contains $
System.out.println(W1.isValid("Monday")); //returns true as word is valid
System.out.println(W1.getValidCount()); //return 2 for two valid words so far
WordCheck W2 = new WordCheck("Meep"); //any words with length 5-12 and no occurrence of Meep will be valid for W2
WordCheck W3 = new WordCheck(2, 12, "$");
System.out.println(W3.isValid("Meow"));
System.out.println(W3.isValid("$3"));
System.out.println(W3.isValid("Cats meow"));
System.out.println(W3.isValid("Dogs bark"));
System.out.println(W3.getValidCount());
WordCheck W4 = new WordCheck("meow");
System.out.println(WordCheck.wordCheckCount);
}
}

View file

@ -0,0 +1,60 @@
import java.lang.Math;
public class code2 {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
// 5 random ints
int a = (int) (Math.random() * (10 - 1 + 1) /* range size */ + 1);
int b = (int) (Math.random() * (10 - 1 + 1) + 1);
int c = (int) (Math.random() * (10 - 1 + 1) + 1);
int d = (int) (Math.random() * (10 - 1 + 1) + 1);
int e = (int) (Math.random() * (10 - 1 + 1) + 1);
System.out.println(a + b + c + d + e);
// create a array of ints
int numlist[] = new int[5]; // declared new list and intialized with size of 5
System.out.println(numlist); // prints memory
int sum = 0;
for (int i = 0; i < numlist.length; i++) {
numlist[i] = (int) (Math.random() * (10) + 1);
System.out.println(numlist[i]); // prints the list
sum += numlist[i]; // adds each var to sum each time loop runs
}
System.out.println(sum);
System.out.println(numlist.length); // lgnth is an attr not method
// arrayss have one attr and no methods
//arrays of strings
// String names[] = new String[]; / array are static data type
// dimesion missing
String names[] = { "alice", "esther", "emma", "lily", "branden" }; //declaration, instationation, initialzation in one step
System.out.println(names[1]);
System.out.println(names[names.length - 1]); //last value/index in list
// properly format names
for (int i = 0; i < names.length; i++) {
System.out.println(
names[i].substring(0, 1).toUpperCase() +
names[i].substring(1).toLowerCase()
);
}
//traverse backqrds and print names that are more than 3 letters long
for (int i = names.length - 1; i >= 0; i--) {
if (names[i].length() > 3) {
System.out.println(names[i]);
}
}
//traverse and print only names with letter "a" in it
for (int i = 0; i < names.length; i++) {
if (names[i].indexOf("a") >= 0) {
System.out.println(names[i]);
}
}
// for each loop is a simple loop just for traversal
// access one element at a time in a temp placeholder
for (String s : names) {
System.out.println(s);
}
}
}

0
README.md Normal file → Executable file
View file

0
U1/Assignment1.java Normal file → Executable file
View file

0
U1/L1/U1_L1_Activity_One .java Normal file → Executable file
View file

0
U1/L1/U1_L1_Activity_Three.java Normal file → Executable file
View file

0
U1/L1/U1_L1_Activity_Two .java Normal file → Executable file
View file

0
U1/L2/U1_L2_Activity_One.java Normal file → Executable file
View file

0
U1/L2/U1_L2_Activity_Three.java Normal file → Executable file
View file

0
U1/L2/U1_L2_Activity_Two.java Normal file → Executable file
View file

0
U1/L3/U1_L3_Activity_One.java Normal file → Executable file
View file

0
U1/L3/U1_L3_Activity_Three.java Normal file → Executable file
View file

0
U1/L3/U1_L3_Activity_Two.java Normal file → Executable file
View file

0
U1/L4/U1_L4_Activity_Four.java Normal file → Executable file
View file

0
U1/L4/U1_L4_Activity_One.java Normal file → Executable file
View file

0
U1/L4/U1_L4_Activity_Three.java Normal file → Executable file
View file

0
U1/L4/U1_L4_Activity_Two.java Normal file → Executable file
View file

0
U1/L5/U1_L5_Activity_One.java Normal file → Executable file
View file

0
U1/L5/U1_L5_Activity_Two.java Normal file → Executable file
View file

0
U1/L6/U1_L6_Activity_One.java Normal file → Executable file
View file

0
U1/L6/U1_L6_Activity_Three.java Normal file → Executable file
View file

0
U1/L6/U1_L6_Activity_Two.java Normal file → Executable file
View file

143
U2/Assignment2.java Executable file
View file

@ -0,0 +1,143 @@
/* Assignment 2 - Control Tower */
/* Class name - must be "Assignment2" in order to run */
import assignment2.Airplane;
import java.util.Scanner;
public class Assignment2 {
public static void main(String[] args) {
Airplane plane1 = new Airplane();
Airplane plane2 = new Airplane("AAA02", 15.8, 128, 30000);
Scanner scan = new Scanner(System.in);
System.out.println(
"Enter the details of the third airplane (call-sign, distance, bearing and altitude):"
);
String callsign = scan.nextLine();
double distance = scan.nextDouble();
int bearing = scan.nextInt();
int altitude = scan.nextInt();
callsign = callsign.toUpperCase();
Airplane plane3 = new Airplane(callsign, distance, bearing, altitude);
System.out.println();
System.out.println("Initial Positions:");
System.out.println("\"Airplane 1\": " + plane1.toString());
System.out.println("\"Airplane 2\": " + plane2.toString());
System.out.println("\"Airplane 3\": " + plane3.toString());
System.out.println();
System.out.println("Initial Distances:");
double dist12 = plane1.distTo(plane2);
double dist13 = plane1.distTo(plane3);
double dist23 = plane2.distTo(plane3);
System.out.println(
"The distance between Airplane 1 and Airplane 2 is " +
Math.round(dist12 * 100.0) / 100.0 +
" miles."
);
System.out.println(
"The distance between Airplane 1 and Airplane 3 is " +
Math.round(dist13 * 100.0) / 100.0 +
" miles."
);
System.out.println(
"The distance between Airplane 2 and Airplane 3 is " +
Math.round(dist23 * 100.0) / 100.0 +
" miles."
);
System.out.println();
System.out.println("Initial Height Differences:");
int heightDiff12 = Math.abs(plane1.getAlt() - plane2.getAlt());
int heightDiff13 = Math.abs(plane1.getAlt() - plane3.getAlt());
int heightDiff23 = Math.abs(plane2.getAlt() - plane3.getAlt());
System.out.println(
"The difference in height between Airplane 1 and Airplane 2 is " +
heightDiff12 +
" feet."
);
System.out.println(
"The difference in height between Airplane 1 and Airplane 3 is " +
heightDiff13 +
" feet."
);
System.out.println(
"The difference in height between Airplane 2 and Airplane 3 is " +
heightDiff23 +
" feet."
);
plane1.gainAlt();
plane1.gainAlt();
plane1.gainAlt();
plane2.loseAlt();
plane2.loseAlt();
plane3.loseAlt();
plane3.loseAlt();
plane3.loseAlt();
plane3.loseAlt();
plane1.move(dist23, 65);
plane2.move(8.0, 135);
plane3.move(5.0, 55);
System.out.println();
System.out.println("New Positions: ");
System.out.println("\"Airplane 1\": " + plane1.toString());
System.out.println("\"Airplane 2\": " + plane2.toString());
System.out.println("\"Airplane 3\": " + plane3.toString());
System.out.println();
System.out.println("New Distances:");
dist12 = plane1.distTo(plane2);
dist13 = plane1.distTo(plane3);
dist23 = plane2.distTo(plane3);
System.out.println(
"The distance between Airplane 1 and Airplane 2 is " +
Math.round(dist12 * 100.0) / 100.0 +
" miles."
);
System.out.println(
"The distance between Airplane 1 and Airplane 3 is " +
Math.round(dist13 * 100.0) / 100.0 +
" miles."
);
System.out.println(
"The distance between Airplane 2 and Airplane 3 is " +
Math.round(dist23 * 100.0) / 100.0 +
" miles."
);
System.out.println();
System.out.println("New Height Differences:");
heightDiff12 = Math.abs(plane1.getAlt() - plane2.getAlt());
heightDiff13 = Math.abs(plane1.getAlt() - plane3.getAlt());
heightDiff23 = Math.abs(plane2.getAlt() - plane3.getAlt());
System.out.println(
"The difference in height between Airplane 1 and Airplane 2 is " +
heightDiff12 +
" feet."
);
System.out.println(
"The difference in height between Airplane 1 and Airplane 3 is " +
heightDiff13 +
" feet."
);
System.out.println(
"The difference in height between Airplane 2 and Airplane 3 is " +
heightDiff23 +
" feet."
);
}
}

0
U2/L1/U2_L1_Activity_One.java Normal file → Executable file
View file

0
U2/L1/U2_L1_Activity_Two.java Normal file → Executable file
View file

0
U2/L2/U2_L2_Activity_One.java Normal file → Executable file
View file

0
U2/L2/U2_L2_Activity_Three.java Normal file → Executable file
View file

0
U2/L2/U2_L2_Activity_Two.java Normal file → Executable file
View file

0
U2/L3/U2_L3_Activity_Four.java Normal file → Executable file
View file

0
U2/L3/U2_L3_Activity_One.java Normal file → Executable file
View file

0
U2/L3/U2_L3_Activity_Three.java Normal file → Executable file
View file

0
U2/L3/U2_L3_Activity_Two.java Normal file → Executable file
View file

0
U2/L4/U2_L4_Activity_One.java Normal file → Executable file
View file

0
U2/L4/U2_L4_Activity_Two.java Normal file → Executable file
View file

0
U2/L5/U2_L5_Activity_One.java Normal file → Executable file
View file

0
U2/L5/U2_L5_Activity_Three.java Normal file → Executable file
View file

0
U2/L5/U2_L5_Activity_Two.java Normal file → Executable file
View file

0
U2/L6/U2_L6_Activity_One.java Normal file → Executable file
View file

0
U2/L6/U2_L6_Activity_Two.java Normal file → Executable file
View file

0
U2/L7/U2_L7_Activitiy_One.java Normal file → Executable file
View file

0
U2/L7/U2_L7_Activity_Three.java Normal file → Executable file
View file

0
U2/L7/U2_L7_Activity_Two.java Normal file → Executable file
View file

18
U2/L8/U2_L8_Activity_One.java Executable file
View file

@ -0,0 +1,18 @@
/* Lesson 8 Coding Activity Question 1 */
import java.util.Scanner;
import testing.Math;
public class U2_L8_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a positive integer:");
int rn = scan.nextInt();
System.out.println((int) (Math.random() * (rn + 1)) + 2);
System.out.println((int) (Math.random() * (rn + 1)) + 2);
System.out.println((int) (Math.random() * (rn + 1)) + 2);
scan.close();
}
}

14
U2/L8/U2_L8_Activity_Three.java Executable file
View file

@ -0,0 +1,14 @@
/* Lesson 8 Coding Activity Question 3 */
import java.util.Scanner;
public class U2_L8_Activity_Three {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter two doubles:");
Double d1 = scan.nextDouble();
Double d2 = scan.nextDouble();
System.out.println("Difference: " + Math.abs(Math.round(d1 - d2)));
}
}

20
U2/L8/U2_L8_Activity_Two.java Executable file
View file

@ -0,0 +1,20 @@
/* Lesson 8 Coding Activity Question 2 */
import java.util.Scanner;
public class U2_L8_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the first x-coordinate:");
Double x1 = scan.nextDouble();
System.out.println("Enter the second x-coordinate:");
Double x2 = scan.nextDouble();
System.out.println("Enter the first y-coordinate:");
Double y1 = scan.nextDouble();
System.out.println("Enter the second y-coordinate:");
Double y2 = scan.nextDouble();
Double slope = (y2 - y1) / (x2 - x1);
System.out.println("Slope: " + slope);
}
}

52
U3/Assignment3.java Normal file
View file

@ -0,0 +1,52 @@
import java.util.Scanner;
public class Assignment3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Welcome. What is your name?");
String name = scan.nextLine();
System.out.println(
"Hello " + name + ". Are you ready to crack the code?"
);
String ready = scan.nextLine();
if (ready.equalsIgnoreCase("yes")) {
System.out.println("\nPHASE 1");
System.out.println("Enter a string:");
String s = scan.nextLine();
if (s.length() == 3) {
System.out.println("Correct!");
System.out.println("\nPHASE 2");
System.out.println("Enter a number:");
int n1 = scan.nextInt();
if (n1 == 19 || (n1 >= 35 && n1 < 78)) {
System.out.println("Correct!");
System.out.println("\nPHASE 3");
System.out.println("Enter a number:");
int n2 = scan.nextInt();
if (n2 > 0 && (n2 % 2 == 0 || n2 % 10 == 1)) {
System.out.println("Correct!");
System.out.println("You have cracked the code!");
} else {
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
} else {
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
} else {
System.out.println("Sorry, that was incorrect!");
System.out.println("Better luck next time!");
}
}
}
}

19
U3/L1/U3_L1_Activity_Four.java Executable file
View file

@ -0,0 +1,19 @@
/* Lesson 1 Coding Activity Question 4 */
import java.util.Scanner;
public class U3_L1_Activity_Four {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter an integer:");
int x = scan.nextInt();
if (x % 2 == 0 && x % 3 == 0) {
System.out.println("Divisible by 2!\n Divisible by 3!");
} else if (x % 2 == 0) {
System.out.println("Divisible by 2!");
} else if (x % 3 == 0) {
System.out.println("Divisible by 3!");
}
}
}

15
U3/L1/U3_L1_Activity_One.java Executable file
View file

@ -0,0 +1,15 @@
/* Lesson 1 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L1_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter a double:");
double x = scan.nextDouble();
if (x == 12.345) {
System.out.println("YES");
}
}
}

16
U3/L1/U3_L1_Activity_Three.java Executable file
View file

@ -0,0 +1,16 @@
/* Lesson 1 Coding Activity Question 3 */
import java.util.Scanner;
public class U3_L1_Activity_Three {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter two integers:");
int x = scan.nextInt();
int x1 = scan.nextInt();
if (x * 2 == x1) {
System.out.println("YES");
}
}
}

15
U3/L1/U3_L1_Activity_Two.java Executable file
View file

@ -0,0 +1,15 @@
/* Lesson 1 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L1_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter an integer:");
int x = scan.nextInt();
if (x == 48) {
System.out.println("YES");
}
}
}

View file

@ -0,0 +1,21 @@
/* Lesson 2 Coding Activity Question 4 */
import java.util.Scanner;
public class U3_L2_Activity_Four {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two test scores:");
double a = sc.nextDouble();
double b = sc.nextDouble();
if (a < 0 || a > 100) {
System.out.println("Not Valid");
}
if (b < 0 || b > 100) {
System.out.println("Not Valid");
}
}
}

View file

@ -0,0 +1,24 @@
/* Lesson 2 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L2_Activity_One
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter five numbers:");
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double d = sc.nextDouble();
double e = sc.nextDouble();
double average = (a + b + c + d + e) / 5.0;
if (average >= 89.95) {
System.out.println("ABOVE AVERAGE");
}
}
}

View file

@ -0,0 +1,17 @@
/* Lesson 2 Coding Activity Question 3 */
import java.util.Scanner;
public class U3_L2_Activity_Three {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("What is the temperature?");
double temp = sc.nextDouble();
if (temp < 97 || temp > 99) {
System.out.println("NOT NORMAL");
}
}
}

View file

@ -0,0 +1,17 @@
/* Lesson 2 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L2_Activity_Two
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Please enter two numbers:");
double a = sc.nextDouble();
double b = sc.nextDouble();
System.out.println("Smallest is: " + Math.min(a, b));
}
}

View file

@ -0,0 +1,19 @@
/* Lesson 3 Coding Activity Question 4 */
import java.util.Scanner;
public class U3_L3_Activity_Four {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("What is the temperature?");
double temp = sc.nextDouble();
if (temp >= 97 && temp <= 99) {
System.out.println("Temperature is OK");
} else {
System.out.println("NOT NORMAL");
}
}
}

View file

@ -0,0 +1,19 @@
/* Lesson 3 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L3_Activity_One {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter an integer");
int n = sc.nextInt();
if (n % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}

View file

@ -0,0 +1,26 @@
/* Lesson 3 Coding Activity Question 3 */
import java.util.Scanner;
public class U3_L3_Activity_Three {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter two integers:");
System.out.print("> ");
int a = sc.nextInt();
System.out.print("> ");
int b = sc.nextInt();
System.out.println(a + " + " + b + " = ?");
System.out.print("> ");
int answer = sc.nextInt();
if (answer == a + b) {
System.out.println("Correct!");
} else {
System.out.println("Wrong");
}
}
}

View file

@ -0,0 +1,27 @@
/* Lesson 3 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L3_Activity_Two {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a letter grade:");
String grade = sc.nextLine();
if (grade.equals("A")) {
System.out.println("[90-100]");
} else if (grade.equals("B")) {
System.out.println("[80-90)");
} else if (grade.equals("C")) {
System.out.println("[70-80)");
} else if (grade.equals("D")) {
System.out.println("[60-70)");
} else if (grade.equals("F")) {
System.out.println("[0-60)");
} else {
System.out.println("Invalid letter grade");
}
}
}

View file

@ -0,0 +1,19 @@
/* Lesson 4 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L4_Activity_One {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int n = sc.nextInt();
if (n < 65 || n > 100) {
System.out.println("True");
} else {
System.out.println("False");
}
}
}

View file

@ -0,0 +1,28 @@
/* Lesson 4 Coding Activity Question 3 */
import java.util.Scanner;
public class U3_L4_Activity_Three {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the latitude:");
double lat = sc.nextDouble();
System.out.println("Please enter the longitude:");
double lon = sc.nextDouble();
boolean latValid = lat >= -90 && lat <= 90;
boolean lonValid = lon >= -180 && lon <= 180;
if (!latValid) {
System.out.println("latitude is incorrect");
}
if (!lonValid) {
System.out.println("longitude is incorrect");
}
if (latValid && lonValid) {
System.out.println("The location: " + lat + ", " + lon);
}
}
}

View file

@ -0,0 +1,20 @@
/* Lesson 4 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L4_Activity_Two {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers:");
int a = sc.nextInt();
int b = sc.nextInt();
if (a >= 0 && b >= 0 && a % 2 == 0 && b % 2 == 0) {
System.out.println("Both are positive and even.");
} else {
System.out.println("At least one is negative or odd.");
}
}
}

View file

@ -0,0 +1,14 @@
/* Lesson 5 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L5_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter 2 integers:");
int x = scan.nextInt();
Double y = scan.nextDouble();
if (x / y > 1 && x / y <= 8) System.out.println("Ratio OK");
}
}

View file

@ -0,0 +1,18 @@
/* Lesson 5 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L5_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter two numbers:");
double a = scan.nextDouble();
int b = scan.nextInt();
if (a % b != 0) {
System.out.println(b + " is not a factor of " + a);
} else {
System.out.println(b + " is a factor of " + a);
}
}
}

View file

@ -0,0 +1,18 @@
/* Lesson 6 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L6_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a number in the fifties");
int num = scan.nextInt();
if (num < 50 || num > 59) {
System.out.println("That's not in the fifties!");
num = 55;
}
System.out.println("Your number is " + num);
}
}

View file

@ -0,0 +1,16 @@
/* Lesson 6 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L6_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
int y = scan.nextInt();
if (y <= 9 || (x > 2 && x * y > 10)) {
System.out.println("pass");
}
}
}

View file

@ -0,0 +1,17 @@
/* Lesson 7 Coding Activity Question 1 */
import java.util.Scanner;
public class U3_L7_Activity_One {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter password:");
String password = scan.nextLine();
if (password.equals("bulbasaur")) {
System.out.println("Access granted!");
} else {
System.out.println("Access denied!");
}
}
}

View file

@ -0,0 +1,29 @@
/* Lesson 7 Coding Activity Question 3 */
import java.util.Scanner;
import shapes.*;
public class U3_L7_Activity_Three {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(
"Enter the side length of the first regular polygon:"
);
double len1 = scan.nextDouble();
RegularPolygon poly1 = new RegularPolygon(len1);
System.out.println("Enter the number of sides of the second polygon:");
int sides2 = scan.nextInt();
System.out.println("Enter the side length of the second polygon:");
double len2 = scan.nextDouble();
RegularPolygon poly2 = new RegularPolygon(sides2, len2);
if (poly1.equals(poly2)) {
System.out.println("Congruent Regular Polygons!");
} else {
System.out.println("Different Regular Polygons");
}
}
}

View file

@ -0,0 +1,28 @@
/* Lesson 7 Coding Activity Question 2 */
import java.util.Scanner;
public class U3_L7_Activity_Two {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter 2 strings:");
String a = scan.nextLine();
String b = scan.nextLine();
if (a.equals(b)) {
System.out.println("Equal!");
} else if (a.equalsIgnoreCase(b)) {
System.out.println("Different case");
} else if (
a.length() == b.length() &&
a
.substring(0, a.length() - 1)
.equals(b.substring(0, b.length() - 1))
) {
System.out.println("Close enough");
} else {
System.out.println("Try again");
}
}
}

14
U5/U5_L1_Activity_One.java Executable file
View file

@ -0,0 +1,14 @@
/* Lesson 1 Coding Activity Question 1 */
import java.util.Scanner;
public class U5_L1_Activity_One {
/* Add the method myMethod 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 myMethod() {
System.out.println("I'm a void method!");
}
}