subject

I need this answered in JAVA: Primary U. S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90.

Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.

Ex: If the input is:

90
the output is:

I-90 is primary, going east/west.
Ex: If the input is:

290
the output is:

I-290 is auxiliary, serving I-90, going east/west.
Ex: If the input is:

0
or any number not between 1 and 999, the output is:

0 is not a valid interstate highway number.
Ex: If the input is:

200
the output is:

200 is not a valid interstate highway number.

This is what I've got so far- but I'm not really understanding fully...

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)) {
if (highwayNumber <= 99) {
if (highwayNumber %2 == 0) { //recognizes even numbers
System. out. printf("I-%d is primary, going east/west.\n", highwayNumber);
}
else {
System. out. printf("I-%d is primary, going north/south.\n", highwayNumber); //recognizes other than even numbers
}
}
else {

primaryNumber = highwayNumber;

highwayNumber %= 100; //what does this mean?

if (highwayNumber % 2 == 0) { //recognizes even numbers
System. out. printf("I-%d is auxiliary, serving the I-%d, going east/west.\n", primaryNumber, highwayNumber);

}
else {

System. out. printf("I-%d is auxiliary, serving the I-%d, going north/south.\n", primaryNumber, highwayNumber);
}
}

} else {

System. out. printf("%d is not a valid interstate highway number.\n", highwayNumber);

}

}
}
This answer is incomplete, because when I input 200, the out put is:
I-200 is auxiliary, serving the I-0, going east/west.

it should be:
200 is not a valid interstate highway number.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:30
The “rule of 72” is used to approximate the time required for prices to double due to inflation. if the inflation rate is r%, then the rule of 72 estimates that prices will double in 72/r years. for instance, at an inflation rate of 6%, prices double in about 72/6 or 12 years. write a program to test the accuracy of this rule. for each interest rate from 1% to 20%, the program should display the rounded value of 72/r and the actual number of years required for prices to double at an r% inflation rate. (assume prices increase at the end of each year.)
Answers: 1
question
Computers and Technology, 23.06.2019 03:30
How can you repin an image on your pinterest pin board a. click on the "repin" button b. click on the "add pin" button c. click on the "upload a pin" button d. click on the "save pin" button.
Answers: 2
question
Computers and Technology, 23.06.2019 14:00
What is html ? give a small description about html
Answers: 2
question
Computers and Technology, 24.06.2019 06:30
Ineed to know the anwser to all these questions
Answers: 2
You know the right answer?
I need this answered in JAVA: Primary U. S. interstate highways are numbered 1-99. Odd numbers (lik...
Questions
question
Mathematics, 09.04.2020 12:52
question
Mathematics, 09.04.2020 13:11
question
Geography, 09.04.2020 13:12
question
Mathematics, 09.04.2020 13:12
question
Mathematics, 09.04.2020 13:12
question
Mathematics, 09.04.2020 13:13
question
Physics, 09.04.2020 13:14
Questions on the website: 13722367