Can some please help? I cannot figure out why I am getting this error when I compile this Java file. The error is a tricky one (';' expected). The “;” is expected on line 7 between “New” and “Rectangle” of the test app.
If you need my main app code, I can add that as well.
import java.util.Scanner;
public class RectangleTest
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
Rectangle rectmeas = New Rectangle(); // LINE 7, WHERE THE ERROR IS
int userinput = getOptions();
while ( userinput != 3 )
{
switch ( userinput )
{
case 1:
System.out.print( "Please enter the length: " );
rectmeas.setLen( input.nextDouble() );
break;
case 2:
System.out.print( "Please enter the width: " );
rectmeas.setWid( input.nextDouble() );
break;
}
System.out.println( rectmeas.toString() );
userinput = getOptions();
}
}
private static int getOptions()
{
Scanner input = new Scanner( System.in );
System.out.println( "Press 1 to input the length" );
System.out.println( "Press 2 to input the width" );
System.out.print( "Which one?: " );
return input.nextInt();
}
}
Java keywords are all lowercase. You should use
newinstead ofNew.