3.1

int myAge = 15;
int otherAge = 45; 

System.out.println(myAge < 16);
System.out.println(myAge > otherAge);
System.out.println(myAge <= 15);
System.out.println(myAge >= otherAge);
System.out.println(myAge == 15);
System.out.println(myAge != otherAge);
true
false
true
false
true
true

What’s wrong with this code:

String myName = Alisha;

myName != Anika;
myName == Alisha ;

Strings are not in quotations

why would you leave the expressions on their own

homework question:

It is unclear exactly what I am supposed to do with this questions but I guess the precondition is “the number of digits in num is between one and six, inclusive.”

3.2

public static void main(String[] args) {
    int myAge = 16;
    System.out.println("Current age: " + myAge);
    
    if (!(myAge >= 16)) { //added a not statement, was this what I was supposed to do.
        System.out.println("You can start learning to drive!");
    }

    System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old!");
}
main(null);


Current age: 16
On your next birthday, you will be 17 years old!

3.3

Based on the code if you were less than 16 it would print out that you are not yet old enough for a license.

String myString = "abcde";

if(myString.length() > 4){
    System.out.println("Hello! long string");
}
else {
    System.out.println("Goodbye! short string");
}
Hello! long string

3.4

  1. “you can register to vote”, “you are old enough for a license to drive”
  2. nothing?
int bananas = 22; // I have 30 bananas

if (bananas >= 30){
    System.out.println("THATS A LOT OF BANANAAAAAS!");
} else if (bananas >= 20){
    System.out.println("Ok, Thats some bananas");
} else {
    System.out.println("get more bananas");
}
Ok, Thats some bananas

3.5

explain the purpose of this algorithm, and what each if condition is used for.

The purpose of the alrgorithm is to determine what progrmans each person qualifies for.

what would be output if input is: age 20, annual income 1500, student status: yes

The output would be: “You are eligable for a student discount”

why is it in javascript?

public class Main {
    public static void main(String[] args) {
        int age = 30; // Change this value for testing
        boolean isStudent = true; // Change this value for testing

        String[] results = new String[3];
        // Your compound conditional logic here

        if( (age >= 21) && (isStudent == false)){
            results[0] = " Worker's tax";
        }

        if((isStudent == true)){
            results[1] = "Student discount";
        }

        if((age < 18)){
            results[2] = "Child Discount";
        }

        for(String value : results){
            if (value != null){
                System.out.println(value);
            }
        }
    }
}
Main.main(null);
Student discount

3.6

  • What is !(x == 0) equivalent to?, Apply De Morgan’s Law to find an equivalent expression.

x != 0, ( !x != !0)?

  • Negate the expression (x < -5   x > 10), Use De Morgan’s Law to rewrite this expression in a different form.

(x > -5 && x < 10)

3.7

Yes