Question

CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign i3.12.1: String comparison: Detect word. D ACTIVITY Write an if-else statement that prints Goodbye if userString is Quit,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

\color{blue}\underline{1:}

import java.util.Scanner;

public class TeenagerDetector {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        boolean isTeenager;
        int kidAge;

        kidAge = scnr.nextInt();

        isTeenager = kidAge >= 13 && kidAge <= 19;

        if (isTeenager) {
            System.out.println("Teen");
        } else {
            System.out.println("Not teen");
        }
    }
}

\color{blue}\underline{2:}

import java.util.Scanner;

public class RedBalloon {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        boolean isRed;
        boolean isBalloon;

        isRed = scnr.nextBoolean();
        isBalloon = scnr.nextBoolean();

        if (isRed && isBalloon) {
            System.out.println("Red balloon");
        } else if (isBalloon) {
            System.out.println("Balloon");
        } else {
            System.out.println("Not a balloon");
        }
    }
}

\color{blue}\underline{3:}

import java.util.Scanner;

public class DetectWord {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String userString;

        userString = scnr.next();

        if (userString.equals("Quit")) {
            System.out.println("Goodbye");
        } else {
            System.out.println("Hello");
        }
    }
}

\color{blue}\underline{4:}

import java.util.Scanner;

public class OrderStrings {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String firstString;
        String secondString;

        firstString = scnr.next();
        secondString = scnr.next();

        if (firstString.compareTo(secondString) < 0) {
            System.out.println(firstString + " " + secondString);
        } else {
            System.out.println(secondString + " " + firstString);
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Feedback CHALLENGE ACTIVITY 3.8.1: Using boolean Assign is Teenager with true if kidAge is 13 to...

    Feedback CHALLENGE ACTIVITY 3.8.1: Using boolean Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; kidAge - scnr.nextInt(); /* Your solution goes here */ if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 19 20 ) ) Run Feed CHALLENGE ACTIVITY 3.8.2: Boolean in branching statements. - r

  • In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock"....

    In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock". If 1 print "Paper". If 2 print "Scissors'. For any other value, print "Unknown'. End with newline. 2. 4 1 import java.util.Scanner; 3 public class Roshambo public static void main(String [] args) { 5 Scanner scnr - new Scanner(System.in); 6 int nextChoice; 7 8 nextChoice - scnr.nextInt(); 9 10 /" Your solution goes here */ 11 12 13} CHALLENGE ACTIVITY 3.10.2: Switch statement to...

  • CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99,...

    CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99, 0, or 44. 1 import java.util.Scanner; 3 public class Find SpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int specialNum; specialNum - scnr.nextInt(); POSLOVOU if (/* Your solution goes here */) { System.out.println("Special number"); else { System.out.println("Not special number"); Run View your last submission

  • Please help....the only line that can be modified is /* Your solution goes here */. Everything...

    Please help....the only line that can be modified is /* Your solution goes here */. Everything else should remain the same. I submitted hasDigit = Character.isDigit(passCode.charAt(3)); but it's wrong....thank you import java.util.Scanner; public class CheckingPasscodes { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean hasDigit; String passCode; hasDigit = false; passCode = scnr.next(); /* Your solution goes here */ if (hasDigit) { System.out.println("Has a digit."); } else { System.out.println("Has no digit."); } } }

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

  • Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput...

    Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput ( public static void main (String D args) int numTickets; Scanner scnr new Scanner(System.in) scnr.nextint0:I/ Program will be tested with values: 15, 40. numTickets / Your solution goes here/

  • CHALLENGE ACTIVITY 7.16.1: Enter the output of the ArrayList ADT functions. Jump to level 1 Type...

    CHALLENGE ACTIVITY 7.16.1: Enter the output of the ArrayList ADT functions. Jump to level 1 Type the program's output import java.util.ArrayList; import java.util.Scanner; public class IntegerManager ( public static void printSize(ArrayList<Integer> numsList) System.out.println(numsList.size() + "items"); public static void main(String[] args) Scanner scnr = new Scanner(System.in); int currval; ArrayList<Integer> intList = new ArrayList<Integer>(); Input 123-1 printSize (intList); Output currval = scnr.nextInt(); while (currval >= 0) { intList.add(currval); currval = scnr.nextInt(); printSize (intList); intList.clear(); printSize (intList); 1 2 Check Next

  • Write an if-else statement that checks patronAge. If 55 or greater print 'Senior citizen', otherwise print...

    Write an if-else statement that checks patronAge. If 55 or greater print 'Senior citizen', otherwise print 'Not senior citizen' (without quotes). End with newline. 1 import java.util.Scanner; Test pas public class DetectSenior public static void nain (String[] args) { Scanner sehr = new Scanner(System.in); int patronage; patronage - ser.nextInt(); * Your solution goes here */ 12 13 Write an if-else statement with multiple branches. If given Year is 2101 or greater print 'Distant future" (without quotes). Else, if given Year...

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first...

    in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first three elements of array run Times. Follow each statement with a newline. Ex: If runTime = (800,775, 790, 805, 808) print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5 element array. See 'How to Use zyBooks". Also note: If the submitted code tries to access an invalid array...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT