Question

In: Computer Science

1. Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and...

1. Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" if isBalloon and isRed are both true. Print "Not a balloon" otherwise. End with newline.

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();

      /* Your solution goes here */

   }
}

2. Assign isTeenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign isTeenager with false.

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();

      /* Your solution goes here */

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

Solutions

Expert Solution

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(isBalloon && isRed){
            System.out.println("Red balloon");
        }
        else if(isBalloon){
            System.out.println("Balloon");
        }
        else {
            System.out.println("Not a balloon");
        }
    }
}
//////////////////////////////////////////

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();

    if(kidAge>=13 && kidAge<=19){
      isTeenager = true;
    }
    else {
      isTeenager = false;
    }

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

  }
}

Related Solutions

Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future"...
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline C++
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 1)...
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false. 1) Accounting is an information system that identifies, measures, records and 1) communicates relevant information that objectively and correctly represents an organization's economic activities. 2) The main objective of accounting is to help people to invest in new products and 2) businesses. 3) A sole proprietorship is a business owned by one or more persons. 3) 4) Unlimited liability is an advantage for both a...
Write TRUE if the statement is TRUE. If the statement is FALSE, write FALSE and explain...
Write TRUE if the statement is TRUE. If the statement is FALSE, write FALSE and explain why 3. The Commissioner of Internal Revenue may prescribe presumptive gross sales and receipts for a taxpayer when the latter fails to issue receipts and when he believes that the books or other records of the latter do not correctly reflect declarations in the return. 4. Jurisdiction is the power and authority of the court to hear, try, and decide a case. It can...
1. Explain why the following statement is true: "All else the same, firms with relatively stable...
1. Explain why the following statement is true: "All else the same, firms with relatively stable sales are able to carry relatively high debt/asset ratios." and the explain how a firm might shift its capital structure so as to change its weighted average cost of capital (WACC). What would be the impact on the value of the firm?
Please write “true” if the statement is true and “false” is the statement is false in...
Please write “true” if the statement is true and “false” is the statement is false in the space provided: ______ 1. A statistical hypothesis test tests the null hypothesis rather than the researcher’s hypothesis ______ 2. In most research situations, the goal is to reject the researcher’s hypothesis ______ 3. A decision to reject the null hypothesis means that the data do provide evidence of a treatment effect: the independent variable did have an effect on the dependent variable ______4....
True and False True/False Write True or False before the statement. 1. Gypsum is the brand...
True and False True/False Write True or False before the statement. 1. Gypsum is the brand name for sheetrock. 2. Coreboards and liner boards come in 2-foot widths. 3. Adhesives are not used for bonding gypsum board directly to supports. 4. Supplemental fasteners should be used with contact adhesives. 5. Gypsum panels are applied first to ceilings and then to the walls. 6. The floating angle method of drywall application omits fasteners in the corner intersection of the ceilings and...
Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the...
Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the variable:       string s = “Introduction to C++”. 2. Change the letter ‘c’ to ‘C in the following string:    Reprint the string with “C”  given the code and using the string: string greeting = “Introduction to c++” 3. Write the C++ statement or statements that will:    Print the answer for regular division of the real numbers a / b + c and print the answer for integer...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif (x == 2): print "TWO" elif (x == 3): print "THREE" elif (x == 4): print "FOUR" elif (x == 5): print "FIVE" elif (x == 6): print "SIX" else: print "OTHER" C. if (X<Z): print X X = X + 1 D. while (X<Z): print X X = X + 1 Q11. What is the final value of X in D Q12. Is...
Write A if both statements are true. Write B if the first statement is true and...
Write A if both statements are true. Write B if the first statement is true and the second statement is false. Write C if the first statement is false and the second is true. Write D if both statements are false. a. Asset diversification results in the reduction of asset variance, compared with a simple linear combination of the variances, that comes from holding two or more assets held in the portfolio, provided that these asset’s returns are not perfectly,...
Choose true or false for each statement regarding concave mirrors. true false  If an object is placed...
Choose true or false for each statement regarding concave mirrors. true false  If an object is placed 4.1 cm from a concave mirror with f = 4 cm, then its image will be enlarged and real. true false  A concave mirror produces an enlarged real image when the object is placed just beyond its focal point (Region 2). true false  If an object is placed 7.9 cm from a concave mirror with f = 4 cm, then its image will be enlarged and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT