Respuesta :
Answer:
The Java code is given below with appropriate variable names and tags for better understanding
Explanation:
import java.util.Scanner;
public class LabProgram{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int highwayNumber;
int primaryNumber;
highwayNumber = scnr.nextInt();
if(highwayNumber<1 || highwayNumber>999)
System.out.println(highwayNumber+" is not a valid interstate highway number.");
else{
if(highwayNumber>=1 && highwayNumber<=99){
System.out.print("The "+highwayNumber+" is primary, going ");
if(highwayNumber%2==1)
System.out.println("north/south.");
else
System.out.println("east/west.");
}
else{
primaryNumber = highwayNumber%100;
System.out.print("The "+highwayNumber+" is auxillary, serving the "+primaryNumber+", going ");
if(primaryNumber%2==1)
System.out.println("north/south.");
else
System.out.println("east/west.");
}
}
}
}
The program is an illustration of conditional statements.
Conditional statements are statements whose execution is dependent on its truth value.
The missing code segment in Java where comments are used to explain each line is as follows:
import java.util.Scanner;
public class Main {
public static void main(String [] args){
Scanner scnr = new Scanner(System.in);
int highwayNumber; int primaryNumber;
highwayNumber = scnr.nextInt();
//This checks if the highwayNumber is not between 1 and 999 (inclusive)
if (highwayNumber <1 || highwayNumber > 999){
//If yes, the highwayNumber is invalid
System.out.print(highwayNumber+" is not a valid interstate highwayNumber number.");
}
//If otherwise
else{
//This checks if highwayNumber is less than 100
if (highwayNumber< 100){
if (highwayNumber%2 == 0){
//Even highwayNumber are primary going east/west
System.out.print("I-"+highwayNumber+" is primary, going east/west.");
}
else{
//Odd highwayNumber are primary going north/south
System.out.print("I-"+highwayNumber+" is primary, going north/south.");
}
}
//Otherwise
else{
if ((highwayNumber%100) % 2 == 0){
//Even highwayNumber are auxiliary going east/west
System.out.print("I-"+highwayNumber+" is auxiliary, going east/west.");
}
else{
//Even highwayNumber are auxiliary going north/south
System.out.print("I-"+highwayNumber+" is auxiliary, going north/south.");
}
}
}
}
}
Read more about similar programs at:
https://brainly.com/question/22078310