Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA给定公共类,但没有作为组项目一部分的主方法。。如何编译?_Java_Eclipse_Class_Methods_Main - Fatal编程技术网

JAVA给定公共类,但没有作为组项目一部分的主方法。。如何编译?

JAVA给定公共类,但没有作为组项目一部分的主方法。。如何编译?,java,eclipse,class,methods,main,Java,Eclipse,Class,Methods,Main,参加一个在线的Java简介课程,我的反应迟钝的教授为我们提供了“公共航空公司”来纠正错误、提高效率、添加功能等。只提供了.txt文件。到目前为止,在课堂上,我已经在Eclipse中编写了我自己的所有代码。如何在没有main方法的情况下获取一个提供的.txt文件,并尝试编译它,以便我可以处理分配 谢谢你的意见。 迈克 ''' import java.util.Scanner; 公务舱航空公司 { 布尔席位[];//席位数组 最终整数大小=10;//座位数 最终int第一类=1; 最终国际经济舱=2

参加一个在线的Java简介课程,我的反应迟钝的教授为我们提供了“公共航空公司”来纠正错误、提高效率、添加功能等。只提供了.txt文件。到目前为止,在课堂上,我已经在Eclipse中编写了我自己的所有代码。如何在没有main方法的情况下获取一个提供的.txt文件,并尝试编译它,以便我可以处理分配

谢谢你的意见。 迈克

'''

import java.util.Scanner;
公务舱航空公司
{
布尔席位[];//席位数组
最终整数大小=10;//座位数
最终int第一类=1;
最终国际经济舱=2;
公共航空公司()
{
seats=new boolean[SIZE];//座位数组
}
//打印登机牌
公共作废印制板通行证(内部座位)
{
字符串段=(座位<5)?“头等舱”:“经济舱”;
System.out.printf(“%s.Seat#%d\n”,节,Seat);
}
//打印座位菜单
公共无效打印菜单()
{
System.out.println(“请键入1作为头等舱”);
System.out.println(“请键入2表示经济型”);
系统输出打印(“选择:”);
}
//为客户办理登机手续并为其分配登机牌
公共无效签入()
{      
int firstClass=0;//下一个可用的头等舱座位
int economy=5;//下一个可用的经济舱座位
int section=0;//乘客的座位选择
扫描仪输入=新扫描仪(System.in);
System.out.println(“欢迎来到Java航空”);
而((头等舱<5)| |(经济舱<10))
{
打印菜单();
section=input.nextInt();
if(section==FIRST\u CLASS)//用户选择了FIRST CLASS
{
if(一级<5)
{
座位[firstClass++]=true;
印制板通行证(一等);
}//如果结束,则结束
否则,如果(经济舱<10)//头等舱已满
{
System.out.println(
“头等舱满了,经济舱吗?”;
System.out.print(“1.是,2.否。您的选择:”);
int choice=input.nextInt();
如果(选项==1)
{
座位[经济舱++]=正确;
印制板通行证(经济);
}
其他的
System.out.println(“下一班飞机3小时后起飞”);
}//如果需要,则结束
}//如果结束,则结束
else if(section==ECONOMY\u CLASS)//用户选择了ECONOMY
{
if(经济性<10)
{
座位[经济舱++]=正确;
印制板通行证(经济);
}//如果结束,则结束
否则,如果(头等舱<5)//经济舱已满
{
System.out.println(
“经济舱满了,头等舱吗?”;
System.out.print(“1.是,2.否。您的选择:”);
int choice=input.nextInt();
如果(选项==1)
{
座位[firstClass++]=true;
印制板通行证(一等);
}//如果结束,则结束
其他的
System.out.println(“下一班飞机3小时后起飞”);
}//如果需要,则结束
}//如果需要,则结束
System.out.println();
}//结束时
System.out.println(“飞机现在满了”);
}//结束方法签入
}//末级航空公司

“”“

这是一个有效的java源文件,因此只需将其重命名为
飞机.java
(公共类必须始终位于以其自身命名的源文件中;由于它包含
公共类飞机
,因此源文件必须准确地命名为
飞机.java
,注意大小写


它没有主方法,但这没有问题,您仍然可以编译它。您无法运行它(尝试执行
java Airline
会产生错误:
未找到主方法
)。您可以创建另一个使用
Airline
类的类,或者,您可以向Airline类添加一个main方法。

您可以始终添加main方法并通过方法测试类方法重命名文件
Airline.java
;或者在eclipse中创建一个新的
Airline
类。复制并粘贴到eclipse中。它不需要e> main方法进行编译。您可以添加一个,也可以创建自己的类,实例化一个
Airline
,并调用其
签入方法,即
Airline Airline=new Airline();Airline.checkIn()
好的..我想教授期待着David的技术..谢谢大家的输入Hanks David..我创建了自己的类并调用了checkIn(),这样我就可以运行程序..我让它运行了.从我的初学者角度来看,代码看起来不错.我不确定如何用我有限的技能改进它.再次感谢
import java.util.Scanner;

public class Airline
{

    boolean seats[]; // array of seats
    final int SIZE = 10;  // number of seats
    final int FIRST_CLASS = 1;
    final int ECONOMY_CLASS = 2;

   public Airline()
   {
      seats = new boolean[ SIZE ]; // array of seats
   }

   // prints boarding pass
   public void printBoardingPass( int seat )
   {
      String section = ( seat < 5 ) ? "First Class" : "Economy Class";
      System.out.printf( "%s. Seat #%d\n", section, seat );
   }

   // print seating menu
   public void printMenu()
   {
      System.out.println( "Please type 1 for First Class" );
      System.out.println( "Please type 2 for Economy" );
      System.out.print( "choice: " );
   }

   // checks customers in and assigns them a boarding pass
   public void checkIn()
   {      
      int firstClass = 0; // next available first class seat
      int economy = 5; // next available economy seat      
      int section = 0; // passenger's seating choice

      Scanner input = new Scanner( System.in );

      System.out.println( "Welcome to Java Airways" );

      while ( ( firstClass < 5 ) || ( economy < 10 ) )
      {
         printMenu();
         section = input.nextInt();

         if ( section == FIRST_CLASS ) // user chose first class
         {
            if ( firstClass < 5 )
            {
               seats[ firstClass++ ] = true;
               printBoardingPass( firstClass );
            } // end if 
            else if ( economy < 10 ) // first class is full
            {
               System.out.println(
                  "First Class is full, Economy Class?" );
               System.out.print( "1. Yes, 2. No. Your choice: " );
               int choice = input.nextInt();

               if ( choice == 1 )
               {
                  seats[ economy++ ] = true;
                  printBoardingPass( economy );
               }
               else
                  System.out.println( "Next flight leaves in 3 hours." );
            } // end else if
         } // end if
         else if ( section == ECONOMY_CLASS ) // user chose economy
         {
            if ( economy < 10 ) 
            {
               seats[ economy++ ] = true;
               printBoardingPass( economy );
            } // end if 
            else if ( firstClass < 5 ) // economy class is full
            {
               System.out.println(
                  "Economy Class is full, First Class?" );
               System.out.print( "1. Yes, 2. No. Your choice: " );
               int choice = input.nextInt();

               if ( choice == 1 )
               {
                  seats[ firstClass++ ] = true;
                  printBoardingPass( firstClass );
               } // end if
               else
                  System.out.println( "Next flight leaves in 3 hours." );
            } // end else if

         } // end else if

         System.out.println();

      } // end while

      System.out.println( "The plane is now full." );      

   } // end method checkIn

} // end class Airline