Question

In: Computer Science

This code is giving me an Assignment2.java:31: error: class, interface, or enum expected } ^ 1...

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())));}}
}
}

Solutions

Expert Solution

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())));}}


Related Solutions

C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A =...
C Programming Debug -> error: expected expression before 'score' typedef enum LetterGrade {     A = 4,     B = 3,     C = 2,     D = 1,     F = 0 } score; score getLetterGradeFromAverage(const double avg) {     if (avg >= 90)         return score::A;         // error here     else if (avg >= 80)         return score::B;        // error here     else if (avg >= 70)         return score::C;       // error here     else if (avg >=...
4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
It shows me that 1 error exists in this code but I didn't know how to...
It shows me that 1 error exists in this code but I didn't know how to fix this error so if you can help I will appreciate it. Language C++. Code: #include <iostream> #include <string> #include <iterator> #include <fstream> #include <sstream> #include <cstdlib> #include <set> using namespace std; class Book { private: string BookId; string BookISBN; string Publisher; int PublisherYear; double Price; int Quantity; string Author; public: string SetBookId(); string SetBookISBN(); string SetPublisher(); int SetPublisherYear(); double SetPrice(); int SetQuantity(); string...
I keep getting this error "LetterDemo.cs(21,14): error CS1519: Unexpected symbol `string' in class, struct, or interface...
I keep getting this error "LetterDemo.cs(21,14): error CS1519: Unexpected symbol `string' in class, struct, or interface member declaration" Can someone please help me. Here is my code: using static System.Console; class LetterDemo {    static void Main()    {      Letter letter1 = new Letter();      CertifiedLetter letter2 = new CertifiedLetter();      letter1.Name = "Electric Company";      letter1.Date = "02/14/18";      letter2.Name = "Howe and Morris, LLC";      letter2.Date = "04/01/2019";      letter2.TrackingNumber = "i2YD45";      WriteLine(letter1.ToString());      WriteLine(letter2.ToString() +       " Tracking number: " + letter2.TrackingNumber);    } } class Letter {...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    *...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    * Gets the current number of entries in this set.    *    * @return The integer number of entries currently in the set.    */    public int getSize();    /**    * Sees whether this set is empty.    *    * @return True if the set is empty, or false if not.    */    public boolean isEmpty();    /**    *...
Bus ticket reservation project in java using class ,inheritance,interface
Bus ticket reservation project in java using class ,inheritance,interface
write a java code to represent a sales class as follows: 1- The Sales class contains...
write a java code to represent a sales class as follows: 1- The Sales class contains the names of sellers (strings) and the sales/seller/day (matrix of integers). Assume the number of sellers is set dynamically by the constructor and that the sellers work 6 days/week. Example: names/days 0 1 2 3 4 5 Ali 30 5 89 71 90 9 Ahmad 15 81 51 69 78 25 Omar 85 96 7 87 41 54 The class should contain the following...
write code in java and comment. thanks. the program is about interface . Implement the basics...
write code in java and comment. thanks. the program is about interface . Implement the basics of Fitness and types of Fitness: Aerobic. Implement specific Fitness types such as Swimming, Cycling, Fitness Task: public interface Fitness (10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract...
Problem with code. The fixed code would be greatly appreciated! Error messages: PlayerMoveDungeon2.java:21: error: cannot find...
Problem with code. The fixed code would be greatly appreciated! Error messages: PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:22: error: cannot find symbol...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with...
In Java: Job class The Job implements the Comparable interface A Job object is instantiated with three int variables, indicating the arrivalTime, the timeForTheJob, and the priority. When the Job is created it is given the next sequential ID starting from 1. (You should use a static variable to keep track of where you are in ID assignment.) There are also int variables for startTime, waitTime (in queue) and endTime for the Job. The following methods are required: getID, set...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT