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

JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface...
JAVA code Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface below for details. EditableDigraph below: import java.util.NoSuchElementException; /** * Implements an editable graph with sparse vertex support. * * */ public interface EditableDiGraph {    /** * Adds an edge between two vertices, v and w. If vertices do not exist, * adds them first. * * @param v source vertex * @param w destination vertex */ void addEdge(int v, int w); /** *...
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 >=...
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...
4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
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 {...
Write a Java code to represent a 1. Date class. As date class is composed of...
Write a Java code to represent a 1. Date class. As date class is composed of three attributes, namely month, year and day; so the class contains three Data Members, and one method called displayDate() which will print these data members. Test the Date class using main class named DateDemo. Create two objects of date class. Initialize the data fields in Date class using the objects, invoke the method displyaDate(). Date month : String year: int day : int displayDate():...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT