Package Title: Lab Questions Course Title: Big Java



Download 0.57 Mb.
Page4/4
Date29.06.2021
Size0.57 Mb.
#147166
1   2   3   4
15.1) Java has three logical operators, &&, ||, and !. Using these operators, express the following:

x and y are both positive or neither of them is positive.

15.2) Using Java’s three logical operators, &&, ||, and !, formulate the following conditions on the date given by the variables day and month of type int.

a) The date is in the second quarter of the year.

b) The date is the last day of the month. (Assume February always has 28 days.)

c) The date is before April 15.

16) According to the following program, what color results when using the following inputs?

a) Y N Y

b) Y Y N

c) N N N
public class ColorMixer

{

public static void main(String[] args)



{

String mixture = "";

boolean red = false;

boolean green = false;

boolean blue = false;
Scanner in = new Scanner(System.in);

System.out.print("Include red in mixture? (Y/N) ");

String input = in.next();

if (input.toUpperCase().equals("Y"))

{

red = true;



}
System.out.print("Include green in mixture? (Y/N) ");

input = in.next();

if (input.toUpperCase().equals("Y"))

{

green = true;



}
System.out.print("Include blue in mixture? (Y/N) ");

input = in.next();

if (input.toUpperCase().equals("Y"))

{

blue = true;



}
if (!red && !blue && !green)

{

mixture = "BLACK";



}

else if (!red && !blue)

{

mixture = "GREEN";



}

else if (red)

{

if (green || blue)



{

if (green && blue)

{

mixture = "BLACK";



}

else if (green)

{

mixture = "YELLOW";



}

else


{

mixture = "PURPLE";

}

}


else

{

mixture = "BLACK";



}

}


else

{


if (!green)

{

mixture = "BLUE";



}

else


{

mixture = "WHITE";

}

}
System.out.println("Your mixture is " + mixture);



}

}



© John Wiley & Sons, Inc. All rights reserved.



Download 0.57 Mb.

Share with your friends:
1   2   3   4




The database is protected by copyright ©essaydocs.org 2023
send message

    Main page