import java.util.Scanner;
import static java.lang.System.out;
public class DaysOfTheWeek {
public static void main(String[] args) {
var keyboard = new Scanner(System.in);
int day;
out.print("Which day of the week is it? (1-7) ");
day = keyboard.nextInt();
switch (day) {
case 1 -> out.println("Sunday");
case 2 -> out.println("Monday");
case 3 -> out.println("Tuesday");
case 4 -> out.println("Wednesday");
case 5 -> out.println("Thursday");
case 6 -> out.println("Friday");
case 7 -> out.println("Saturday");
default -> out.print("That's not the number of a day of the week.");
}
keyboard.close();
}
}
import java.util.Scanner;
import static java.lang.System.out;
public class TimeToEat {
public static void main(String[] args) {
var keyboard = new Scanner(System.in);
int hour;
out.print("What hour of the day is it? (0-23) ");
hour = keyboard.nextInt();
switch (hour) {
case 6, 7, 8 -> out.println("Breakfast is served.");
case 11, 12 -> out.println("Time for lunch.");
case 17, 18, 19 -> out.println("It's dinnertime.");
default ->
out.println("Sorry, you'll have to wait, or go get a snack.");
}
keyboard.close();
}
}
import java.util.Scanner;
import static java.lang.System.out;
public class TimeToEatUS {
public static void main(String[] args) {
var keyboard = new Scanner(System.in);
int hour;
char morningOrEvening;
out.print("What hour of the day is it? (11 a.m., 12 p.m.) ");
hour = keyboard.nextInt();
morningOrEvening = keyboard.next().charAt(0);
if (morningOrEvening == 'a') {
switch (hour) {
case 6, 7, 8 -> out.println("Breakfast is served.");
case 11 -> out.println("Time for lunch.");
default -> out.println("Sorry, you'll have to wait, or go get a snack.");
}
} else if (morningOrEvening == 'p') {
switch (hour) {
case 12 -> out.println("Time for lunch.");
case 5, 6, 7 -> out.println("It's dinnertime.");
default -> out.println("Sorry, you'll have to wait, or go get a snack.");
}
} else {
out.println("Please type a number followed by a blank space");
out.println(" followed by a.m. or p.m.");
}
keyboard.close();
}
}
import java.util.Scanner;
import static java.lang.System.out;
public class ColorByNumbers {
public static void main(String[] args) {
var keyboard = new Scanner(System.in);
int number;
out.print("Enter a number from 0 to 7: ");
number = keyboard.nextInt();
switch (number) {
case 0 -> out.println("black");
case 1 -> out.println("blue");
case 2 -> out.println("green");
case 3 -> out.println("cyan");
case 4 -> out.println("red");
case 5 -> out.println("magenta");
case 6 -> out.println("yellow");
case 7 -> out.println("white");
default -> out.print("That's not one of the numbers from 0 and 7.");
}
keyboard.close();
}
}
import java.util.Scanner;
import static java.lang.System.out;
public class DaysOfTheWeekExpression {
public static void main(String[] args) {
var keyboard = new Scanner(System.in);
int day;
out.print("Which day of the week is it? (1-7) ");
day = keyboard.nextInt();
String message = switch (day) {
case 1 -> "Sunday";
case 2 -> "Monday";
case 3 -> "Tuesday";
case 4 -> "Wednesday";
case 5 -> "Thursday";
case 6 -> "Friday";
case 7 -> "Saturday";
default -> "That's not the number of a day of the week.";
};
out.println(message);
keyboard.close();
}
}
import java.util.Scanner;
import static java.lang.System.out;
public class TimeToEatExpression {
public static void main(String[] arge) {
var keyboard = new Scanner(System.in);
int hour;
out.print("What hour of the day is it? (0-23) ");
hour = keyboard.nextInt();
String message = switch (hour) {
case 6, 7, 8 -> "Breakfast is served.";
case 11, 12 -> "Time for lunch.";
case 17, 18, 19 -> "It's dinnertime.";
default -> "Sorry, you'll have to wait, or go get a snack.";
};
out.println(message);
keyboard.close();
}
}
import java.util.Scanner;
public class SmileyFace {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
char reply;
System.out.print("Would you like to see a smiley face? ");
reply = keyboard.findWithinHorizon(".", 0).charAt(0);
System.out.println(reply == 'Y' ? ":-)" : ":-(");
keyboard.close();
}
}
import java.util.Random;
import java.util.Scanner;
public class GuessingGame {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Random myRandom = new Random();
int randomNumber;
int guess;
randomNumber = myRandom.nextInt(10) + 1;
System.out.print("Guess a number from 1 to 10: ");
guess = keyboard.nextInt();
System.out.println(guess == randomNumber ? "You win!" : "You lose.");
keyboard.close();
}
}
import java.util.Scanner;
public class ConvertingLengths {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int meters;
char blankSpace, convertTo;
System.out.print("Enter the number of meters followed by a blank space and then a letter (c or m): ");
meters = keyboard.nextInt();
blankSpace = keyboard.findWithinHorizon(".", 0).charAt(0);
convertTo = keyboard.findWithinHorizon(".", 0).charAt(0);
System.out.print(convertTo == 'c' ? meters * 100 : "");
System.out.print(convertTo == 'm' ? meters * 1000 : "");
System.out.print(convertTo == 'c' ? " centimeters" : "");
System.out.print(convertTo == 'm' ? " millimeters" : "");
System.out.print(convertTo != 'c' && convertTo != 'm' ? meters : "");
System.out.print(convertTo != 'c' && convertTo != 'm' ? " meters" : "");
keyboard.close();
}
}