Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5998359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:23:43+00:00 2026-05-23T00:23:43+00:00

public static void check(){ String name; System.out.println(Enter Customer Name to CHECK RESERVATION ticket for

  • 0
public static void check(){
        String name;
        System.out.println("Enter Customer Name to CHECK RESERVATION ticket for this Flight: ");
        Scanner input = new Scanner(System.in);
        name = input.nextLine();
        if (list.contains(name)) { //WHY IS THIS ASKING FOR SEPARATE METHOD?
            System.out.println(name +" has a Reservation on this FLight!");
            menu();
        }

I am trying to take an input and check to see if that input is in the Linked List. I am having problems though getting this to work right.

If I add the new method in my LinkedList.Java class it says it needs to define a variable for link. Below is what I have in entirety if it helps:

import java.util.Scanner;
class airline {
public static LinkedList list = new LinkedList();

    public static void main(String[] args) {

        list.addAirplane("Allen",501);
        list.addAirplane("James",501);
        list.addAirplane("Andrea",501);
        list.addAirplane("Velvett",501);
        list.addAirplane("Paul",501);

        //Method sort the list after year the car was made
        list.sortList();
        menu();


        //Method to print all objects in List
        System.out.println(list.viewAll());

    }


    public static void menu(){
        int menuOpt;

        System.out.println("Airline Menu:");
        System.out.println("1. Reserve a Ticket");
        System.out.println("2. Cancel Reservations");
        System.out.println("3. Check Reservations");
        System.out.println("4. Display Airplanes on Flights");
        Scanner input = new Scanner(System.in);
        menuOpt=input.nextInt();
        System.out.println(menuOpt);


        switch (menuOpt){
        case 1:
            System.out.println("Reserve a Ticket");
            reserveTick();
            break;

        case 2:
            System.out.println("Cancel Reservations");
            cancel();
            break;

        case 3:
            System.out.println("Check Reservations");
            check();
            break;

        case 4:
            System.out.println("Passengers listed by Flights");
            break;

        default:
            System.out.println("INVALID RESPONSE!");
            menu();
            break;
        }
    }

    public static void reserveTick(){
        String name;
        System.out.println("Enter Customer Name to RESERVE ticket for this Flight: ");
        Scanner input = new Scanner(System.in);
        name = input.nextLine();
        list.addAirplane(name,501);
        System.out.println(name + " has been added to Flight Number 501");
        menu();
    }

    public static void cancel(){
        String name;
        System.out.println("Enter Customer Name to CANCEL ticket for this Flight: ");
        Scanner input = new Scanner(System.in);
        name = input.nextLine();

        list.remove(name, 501);
        System.out.println(name + " has been REMOVED from Flight Number 501");
        menu();
    }

    public static void check(){
        String name;
        System.out.println("Enter Customer Name to CHECK RESERVATION ticket for this Flight: ");
        Scanner input = new Scanner(System.in);
        name = input.nextLine();
        if (list.contains(name)) {
            System.out.println(name +" has a Reservation on this FLight!");
            menu();
        }
        else {
            System.out.println(name + " is not on this Flight!");
            menu();
        }
    }
    public static void listpassengers(){
        list.sortList();
    }

}

------------------------------------------------------------------



import java.util.*;
public class LinkedList
{

    private AirplaneNode head = null;

    public void addAirplane(String name , int hk)
    {    
        //If head = null then create the first node
        if(head == null)
        {
            head = new AirplaneNode(name,hk,null);
        }
        else
        {
            //If there are more than 1 node
            head = new AirplaneNode(name,hk,head);            
        }

    }


    public void sortList()
    {

        boolean sorted = false;

        while(!sorted)
        {

            sorted = true;

            for(AirplaneNode cursor = head ; cursor.getNext() != null ; cursor = cursor.getNext())
            {
                if(cursor.getHk() < cursor.getNext().getHk())
                {
                    String n = cursor.getName();
                    int hk = cursor.getHk();

                    cursor.setName(cursor.getNext().getName());
                    cursor.setHk(cursor.getNext().getHk());

                    cursor.getNext().setName(n);
                    cursor.getNext().setHk(hk);

                    sorted = false;        
                }


            }


        }



    }


    public String viewAll()
    {

        StringBuffer str = new StringBuffer();    

        for(AirplaneNode cursor = head ; cursor != null ; cursor = cursor.getNext())
        {

            str.append(cursor+"\n");
        }
        return new String(str);

    }    
}
--------------------------------------------------------------
public class AirplaneNode
{
    private String name;
    private int hk;
    private AirplaneNode next;

    public AirplaneNode(String name,int hk,AirplaneNode head)
    {
        this.name = name;
        this.hk = hk;
        this.next = head;

    }



    public AirplaneNode getNext()
    {
        return next;
    }

    public String getName()
    {
        return name;
    }

    public int getHk()
    {
        return hk;
    }

    public void setName(String in)
    {
        name = in;
    }

    public void setHk(int in)
    {
        hk = in;
    }


    public String toString()
    {
        return name + " " + hk ;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:23:43+00:00Added an answer on May 23, 2026 at 12:23 am

    It seems as if you are creating a own class LinkedList in the top package here:

    import java.util.*;
    public class LinkedList
    {
    

    Since your method check() belongs in the airline class in the same package (and without any import of java.util.LinkedList) it will instead use the class you have created and that class doesn’t implement any contains() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I make a JFrame like this public static void main(String[] args) { new
public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
The following code public class GenericsTest2 { public static void main(String[] args) throws Exception
Here is a quick test program: public static void main( String[] args ) {
The following code does not compile: public class GenericsTest { public static void main(String[]
The method signature of a Java main method is: public static void main(String[] args)
I have the following code: public class Test { public static void Main() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.