1

I have been working on a project for school and have a question regarding my code. I am creating a flight management program and created a class called "Flight" the idea being that this class would be made for a route and would store my "Passenger objects" However upon running the program it presents the following error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: culminatingf.Flight

I have made the following attempts to resolve the issue:

  1. Check if all are in the same package

  2. Ensure packages are labelled properly

  3. Check for obvious errors

  4. Change the code in main so it says:

    ArrayList Switzerland = new ArrayList<>();

None of these seemed to work and I am already attempting a project that is a bit out of my knowledge. Any Ideas what the issue could be?

Main class below - as a side note if the formatting of my question is incorrect please let me know!

package culminatingf;
import java.util.*;
import java.io.*;

import static java.lang.System.out; // shorten output statement

public class CulminatingF {

static public Scanner scanS = new Scanner(System.in); // Global Str Scanner
static public Scanner scanN = new Scanner(System.in); // Global Num Scanner  

public static void main(String[] args) {
    
    // this is where the error is, If i comment these out it goes away.
    Flight Switzerland;
   
    out.print("\n   MENU - please select by #"
               + "\n\n1) Edit Passenger Info"
               + "\n2) Add passenger"
               + "\n3) Remove passenger"
               + "\n4) View Profit Record"
               + "\n5) Exit --> ");
    int choice = scanN.nextInt();
    
}

Flight class below

package culminatingF;
import java.util.ArrayList;

public class Flight {

private ArrayList<Passenger> passList = new ArrayList<>();

// arg-construcctor
public Flight (ArrayList<Passenger> pl) {
    passList = pl;
}

public void setPassList(ArrayList<Passenger> pl) {
    passList = pl;
}

public ArrayList<Passenger> getPassList() {
    return passList;
}
        

}

My passenger class

/*
  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor. */ package culminatingf;

public class Passenger {

//field
private String name;
private String email;
private String destination;
private String cardInfo;
private String phoneNum;
private int seat;


//arg constructor
public Passenger(String n, String e, String d, String c, String p, int s) 
{
    name = n;
    email = e;
    destination = d;
    cardInfo = c;
    phoneNum = p;
    seat = s;
    
}

//Accessors
public String getName() {
    return name;
}

public String getEmail() {
    return email;
}

public String cardInfo() {
    return cardInfo;
}

public String getphoneNum() {
    return phoneNum;
}

public String getDestination() {
    return destination;
}

public int getSeat() {
    return seat;
}

//Mutator
public void setName(String n) {
    name = n;
}

public void setEmail(String e) {
    email = e;
}

public void setDestination (String d) {
    destination = d;
}

public void setCardInfo(String c) {
    cardInfo = c;
}

public void setPhoneNum(String p) {
    phoneNum = p;
}

public void setSeat(int s) {
    seat = s;
}

/**
 * Method Name: toString
 * Description: creates a String representing object state  
 * @return state of the object
 */
@Override
public String toString() {
    System.out.println();
    return "\nName: " + name 
            + "\nEmail: " + email 
            + "\nCard: " + cardInfo 
            + "\nNumber: " + phoneNum;
}

/**
 * Method Name: calcPrice
 * Method Description: Calculates the price of this orders bill
 * @return - order cost
 */
public int profits() {
    int price = 0;
    
    //change price for each flavour
    switch(destination) {
        case "switzerland":
            price = 1200;
            break;
        case "banff":
            price = 520;
            break;
        case "iceland":
            price = 1000;
            break;
    }
    return price;
}    

}

0 Answers0