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, the 405 services the 5, and the 290 services the 90.
Write (define) a public static method named printHighwayInfo, that takes as its only argument a highway number (the arguments will be an int). When this method is called, it should print out a String indicating if the highway is a primary or auxiliary, and if the highway goes east/west or north/south (see examples below). This method should have a return void return type.
Examples: 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.
printHighwayInfo(90) will print The 90 is primary, going east/west. printHighwayInfo(290) will print The 290 is auxiliary, serving the 90, going east/west. printHighwayInfo(185) will print The 185 is auxiliary, serving the 85, going north/south. You may wish to write some additional code to test your method
Hints:
You can use the modulus operator (%) to compute the reminder of an integer division operation.
For example: 290 % 100 will evaluate to 90, because the remainder after dividing 290 by 100 is 90.
As another example: 185 % 2 is 1, because 2 goes into 185, 92 times with 1 left over. Also, note that for any integer x, x % 2 will always evaluate to 1 when x is odd, and it will always evaluate to 0 when x is even.
** this is my first week using java. we've been learning python to this point and I'm having the hardest time with it. I'm getting tons of errors and I don't know why. my class notes and lectures are not helpful like at all.
import java.util.Scanner;
public class Main {
static Scanner scnr = new Scanner(System.in);
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int highwayNumber;
int primaryNumber;
{
public static int printHighwayInfo(int a);
}
if (printHighwayInfo >= 1 && highwayNumber <= 999) {
if (printHighwayInfo <= 99) {
if (printHighwayInfo % 2 == 0) {
System.out.println(printHighwayInfo + " is a primary highway, going east/west");
} else {
System.out.println(printHighwayInfo + " is a primary highway, going north/south");
}
} else {
primaryNumber = highwayNumber;
highwayNumber %= 100;
System.out.println(printHighwayInfo + " is an auxiliary highway, serving primary highway " + highwayNumber);
}
} else {
System.out.println(printHighwayInfo + " is not a valid interstate highway number.");
}
}
}
{
System.out.println(printHighwayInfo(90));
System.out.println(printHighwayInfo(290));
System.out.println(printHighwayInfo(185));
}
}
//these are the errors I'm getting back
HighwayInfo.java:5: error: class, interface, or enum expected
public static void main(String[] args) {
^
HighwayInfo.java:7: error: class, interface, or enum expected
int highwayNumber;
^
HighwayInfo.java:8: error: class, interface, or enum expected
int primaryNumber;
^
HighwayInfo.java:9: error: class, interface, or enum expected
{
^
HighwayInfo.java:10: error: class, interface, or enum expected
public static int printHighwayInfo(int a);
^
HighwayInfo.java:11: error: class, interface, or enum expected
}
^
HighwayInfo.java:16: error: class, interface, or enum expected
} else {
^
HighwayInfo.java:18: error: class, interface, or enum expected
}
^
HighwayInfo.java:21: error: class, interface, or enum expected
highwayNumber %= 100;
^
HighwayInfo.java:22: error: class, interface, or enum expected
System.out.println(printHighwayInfo + " is an auxiliary highway, serving primary highway " + highwayNumber);
^
HighwayInfo.java:23: error: class, interface, or enum expected
}
^
HighwayInfo.java:26: error: class, interface, or enum expected
}
^
HighwayInfo.java:31: error: class, interface, or enum expected
System.out.println(printHighwayInfo(290));
^
HighwayInfo.java:32: error: class, interface, or enum expected
System.out.println(printHighwayInfo(185));
^
HighwayInfo.java:33: error: class, interface, or enum expected
}
^
15 errors