Reputation: 97
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();
}
}
Upvotes: 2
Views: 175
Reputation: 8467
its new and not New , Java is a case sensitive language and new and New does not mean the same thing. new : keyword to create new objects
Upvotes: 0
Reputation: 726967
Java keywords are all lowercase. You should use new
instead of New
.
Upvotes: 9
Reputation: 66657
Rectangle rectmeas = New Rectangle();
should be
Rectangle rectmeas = new Rectangle();
When you want to create an object in java, you need to use new
instead of New
. Java is case-sensitive.
Upvotes: 7