In: Computer Science
This code is giving me an Assignment2.java:31: error: class, interface, or enum expected } ^ 1 error and I don't know how to fix it.
/*code bellow*/
import java.util.Scanner;
import edhesive.assignment2.Airplane;
import java.lang.Math.*;
public class Assignment2{
public static void main(String[] args){
Airplane first=new Airplane("AAA01",1,0,0);
Scanner scan=new Scanner(System.in);
System.out.println("Enter the details of the second airplane
(call-sign, distance, bearing and altitude):");
String cs=scan.nextLine();
double dist=scan.nextDouble();
int dir=scan.nextInt();
int alt=scan.nextInt();
Airplane second=new Airplane(cs.toUpperCase(),dist,dir,alt);
System.out.println("\nInitial Positions:");
System.out.println("\"Airplane 1\": "+first+"\n\"Airplane 2\":
"+second);
System.out.println("The distance between the planes is
"+(first.distTo(second))+" miles.");
System.out.printf("The difference in height between the planes is
%d feet.", (Math.abs(first.getAlt()-second.getAlt())));
System.out.println("\n\nNew Positions:");
first.gainAlt();
first.gainAlt();
first.gainAlt();
first.gainAlt();
second.loseAlt();
second.loseAlt();
first.move(10.5,50);
second.move(8.0,125);
System.out.println("\"Airplane 1\": "+first+"\n\"Airplane 2\":
"+second);
System.out.println("The distance between the planes is
"+(first.distTo(second))+" miles.");
System.out.printf("The difference in height between the planes is
%d feet.", (Math.abs(first.getAlt()-second.getAlt())));}}
}
}
Solution:-
We are getting this error because by mistake you put extra two curly brace '}' in code in order to resolve this error you need to Remove these curly braces.
Proper code is Given Below:
============================
/*code bellow*/
import java.util.Scanner;
import edhesive.assignment2.Airplane;
import java.lang.Math.*;
public class Assignment2{
public static void main(String[] args){
Airplane first=new Airplane("AAA01",1,0,0);
Scanner scan=new Scanner(System.in);
System.out.println("Enter the details of the second airplane
(call-sign, distance, bearing and altitude):");
String cs=scan.nextLine();
double dist=scan.nextDouble();
int dir=scan.nextInt();
int alt=scan.nextInt();
Airplane second=new Airplane(cs.toUpperCase(),dist,dir,alt);
System.out.println("\nInitial Positions:");
System.out.println("\"Airplane 1\": "+first+"\n\"Airplane 2\":
"+second);
System.out.println("The distance between the planes is
"+(first.distTo(second))+" miles.");
System.out.printf("The difference in height between the planes is
%d feet.", (Math.abs(first.getAlt()-second.getAlt())));
System.out.println("\n\nNew Positions:");
first.gainAlt();
first.gainAlt();
first.gainAlt();
first.gainAlt();
second.loseAlt();
second.loseAlt();
first.move(10.5,50);
second.move(8.0,125);
System.out.println("\"Airplane 1\": "+first+"\n\"Airplane 2\":
"+second);
System.out.println("The distance between the planes is
"+(first.distTo(second))+" miles.");
System.out.printf("The difference in height between the planes is
%d feet.", (Math.abs(first.getAlt()-second.getAlt())));}}