Record your participation in Piazza clicker question Lesson10 Q1
The variables fuelAmount and fuelCapacity hold the actual amount of fuel and the size of the fuel tank of a vehicle. If less than 10 percent is remaining in the tank, a status light should show a red color; otherwise it shows a green color. Write a code segment to simulate this process by printing out either "red" or "green" depending on the amount of fuel in the tank.
Write this on a piece of paper or in a text editor. It will not compile. You can assume the variables are defined and have been given a value is some fashion. You just complete the if statement
int fuelAmount = ... int fuelCapacity = ... if (...) { ... }
Record your participation in Piazza clicker question Lesson10 Q2
This code works but does not follow best practices. What is wrong with this code to adjust the floor number in an elevator without a floor 13?
if (floor > 13) { actualFloor = floor - 1; System.out.println("Actual floor: " + actualFloor); } else { actualFloor = floor; System.out.println("Actual floor: " + actualFloor); }
Record your participation in Piazza clicker question Lesson10 Q3
Supply a condition in this if statement to test whether the user entered an (uppercase) Y. Select all that will work.
System.out.println("Enter Y to quit."); String input = in.next(); if (. . .) { System.out.println("Goodbye."); }
Select all that apply
Record your participation in Piazza clicker question Lesson10 Q4
What is the error in this statement? Assume scoreA and scoreB are integers
if (scoreA = scoreB) { System.out.println("Tie"); }
Record your participation in Piazza clicker question Lesson10 Q5
On a piece of paper or in a text file, write an if statement with three branches that sets the int variable sign in the manner explained below. Assume x is an int and has been defined.
Just write the if statement to set sign:
boolean
boolean found = false; boolean done = false; boolean valid = true;
Record your participation in Piazza clicker question Lesson10 Q6
failed
is a boolean variable. We do not know its value. What is the value of !!failed?
Record your participation in Piazza clicker question Lesson10 Q7
Which statement could be used to determine if both num1 and num2 are positive. Click all that apply
Record your participation in Piazza clicker question Lesson10 Q8
Which statement could be used to determine if either (or both) num1 or num2 is positive. Click all that apply
Record your participation in Piazza clicker question Lesson10 Q9
Write a program that asks the user for their favorite color and then asks for another color(as Strings). If one is red and one is blue, print "That's PURPLE" Otherwise print "not purple" The words can be upper or lower case. Notice that a color my be two words
Test with these values
color1 | color2 | output |
---|---|---|
red | blue | That's PURPLE |
blue | red | That's PURPLE |
BluE | RED | That's PURPLE |
blue green | red | not purple |
white | red | not purple |
Here is the skeleton IO project
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("What is your favorite color? "); String color1 = in.nextLine().toLowerCase(); System.out.print("What is your second favorite color? "); String color2 = in.nextLine().toLowerCase(); if ((color1.equals("red") && color2.equals("blue")) || (color1.equals("blue") && color2.equals("red")) { System.out.println("That's PURPLE"); } else { System.out.println("not purple"); } } }
Record your participation in Piazza clicker question Lesson10 Q10
Write a program to ask a user for the city where he/she was born. If the city is San Fransisco, print "You are not far from home." Otherwise, print "Where is that?"
Test with these values:
city | output |
---|---|
San Fransisco | You are not far from home. |
San Antonio | Where is that? |
New York | Where is that? |
Here is the skeleton IO project
Record your participation in Piazza clicker question Lesson10 Q11
Run the following test program and supply inputs 2 and three at the prompts. What does it print? Why?
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter an integer: "); int m = in.nextInt(); System.out.print("Enter another integer: "); int n = in.nextInt(); System.out.println(m + " " + n); } }
Record your participation in Piazza clicker question Lesson10 Q12
The Java Ice Cream store sells, what else, ice cream cones. They sell either one scoop or two in either a plain cone or a waffle cone. There is a table of the costs below
waffle | plain | |
---|---|---|
1 scoop | 2.50 | 1.75 |
2 scoops | 2.75 | 2.25 |
Let's complete the getCost
method of the IcecreamCone class (ice_cream_starter.zip)
/** * Describes an ice cone */ public class IceCreamCone { public static final double ONE_SCOOP_PLAIN_CONE = 1.75; public static final double ONE_SCOOP_WAFFLE_CONE = 2.50; public static final double TWO_SCOOP_PLAIN_CONE = 2.25; public static final double TWO_SCOOP_WAFFLE_CONE = 2.75; public static final int PLAIN_CONE = 1; public static final int WAFFLE_CONE = 2; private int scoops; private int type; public IceCreamCone( int numberOfScoops, int coneType) { this.scoops = numberOfScoops; this.type = coneType; } /** * Gets the cost of this IceCreamCone * @return the cost of this ice cream cone */ public double getCost() { return 0; } }