Last active
October 5, 2022 14:11
-
-
Save maf946/b419f1b194ffccdf870899eaf8ce6340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: You cannot run this entire text file at once in Java. Copy each model answer to IntelliJ to review. | |
// QUESTION 1 | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scnr = new Scanner(System.in); | |
double temp; | |
String sampleState; | |
System.out.print("Please enter a temperature :"); | |
temp = scnr.nextDouble(); | |
if (temp <= 32) | |
{ | |
System.out.println("Solid"); | |
} | |
else if (temp >= 212) | |
{ | |
System.out.println("Gas"); | |
} | |
else | |
{ | |
System.out.println("Liquid"); | |
} | |
} | |
} | |
// QUESTION 2 | |
/*(100 > 250 || 110 > 100) && 50 >= 250 = False because the right half of the and is False, and if half of an And is False, the whole is False | |
= (False || 110 > 100) && 50 >= 250 | |
= (False || True) && 50 >= 250 | |
= True && 50 >= 250 | |
= True && False | |
= False | |
*/ | |
// QUESTION 3 | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scnr = new Scanner(System.in); | |
int selection; | |
System.out.print("Please enter an int: "); | |
if(scnr.hasNextInt()) | |
{ | |
selection = scnr.nextInt(); | |
switch(selection) | |
{ | |
case 1: | |
System.out.println("First"); | |
break; | |
case 2: | |
System.out.println("Second"); | |
break; | |
default: | |
System.out.println("Invalid entry"); | |
break; | |
} | |
} | |
else | |
{ | |
System.out.println("An integer value was not entered"); | |
} | |
} | |
} | |
// QUESTION 4 | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scnr = new Scanner(System.in); | |
String dayOfWeek = ""; | |
int weekNum = 0; | |
boolean enteredIntFlag = true; | |
System.out.print("Please enter Monday, Wednesday, or Friday: "); | |
dayOfWeek = scnr.next(); | |
System.out.print("Please enter a number (7, 8, 9, or 10): "); | |
if(scnr.hasNextInt()) | |
{ | |
weekNum = scnr.nextInt(); | |
if((weekNum == 7 || weekNum == 8) && (dayOfWeek.equals("Monday") || dayOfWeek.equals("Wednesday") || dayOfWeek.equals("Friday"))) | |
{ | |
System.out.println("The topic is loops."); | |
} | |
else if((weekNum == 9 || weekNum == 10) && (dayOfWeek.equals("Monday") || dayOfWeek.equals("Wednesday") || dayOfWeek.equals("Friday"))) | |
{ | |
System.out.println("The topic is arrays."); | |
} | |
else | |
{ | |
System.out.println("Invalid Entry"); | |
} | |
} | |
else | |
{ | |
System.out.println("Invalid Entry"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment