在我的代码中扫描后到达此部分时,我收到此错误:
Project2_JoshuaLucas [,0,0,0x0,invalid,layout = java.awt.FlowLayout,alignmentX = 0.0,alignmentY = 0.0,border =,flags = 9,maximumSize =,minimumSize =,preferredSize = java.awt.Dimension [width = 350,height = 200]]
Project2_JoshuaLucas selection = new Project2_JoshuaLucas("", "", "", "", "", "", "", 0.00);
Object source = event.getSource();
if (source == cabin1)
{
cabin1.setBackground(Color.darkGray);
cabin2.setBackground(Color.gray);
cabin3.setBackground(Color.gray);
cabin4.setBackground(Color.gray);
cabin5.setBackground(Color.gray);
cabin6.setBackground(Color.gray);
cabin7.setBackground(Color.gray);
cabin8.setBackground(Color.gray);
cabin9.setBackground(Color.gray);
cabin10.setBackground(Color.gray);
suite1.setBackground(Color.red);
suite2.setBackground(Color.red);
System.out.println("Your choice is Cabin 11-1, would you like to designate this as your room?");
info1 = scan_in.nextLine();
info1 = info1.toLowerCase();
if ( info1.equals ("yes") || info1.equals ("y"))
{
continues=true;
System.out.println("Please enter the number of people in your cabin (*Maximum number of people is 2*)");
cabin_people = scan_in.nextInt();
scan_in.nextLine();
while(continues)
{
switch (cabin_people)
{
case 1:
System.out.println("There is one passenger within the cabin. (You will pay an EXTRA 45% because of the empty passenger slot)");
continues=false;
onepassenger=true;
break;
case 2:
System.out.println("There are two passenger within this cabin.");
continues=false;
twopassenger=true;
break;
default:
System.out.println("Please try again. Remember, the maximum amount of passengers allowed is 2.");
System.out.println("How many passengers are staying within this cabin?");
cabin_people=scan_in.nextInt();
scan_in.nextLine();
continues=true;
}//Closes the Switch
}//Closes the while(continues) loop
while(onepassenger)
{
System.out.println("Please state your FIRST name: ");
fname1=scan_in.nextLine();
System.out.println();
System.out.println("Please state your LAST name: ");
lname1=scan_in.nextLine();
onepassenger=false;
Project2_JoshuaLucas passenger1 = new Project2_JoshuaLucas (fname1, lname1, "", "", "", "", "", 0.00);
System.out.println(passenger1);
} //Closes while(1passenger)
我怎样才能解决这个问题?
最佳答案
您的toString()方法将打印对象数据中的所有内容。
关于java - 调用构造函数时收到错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33357962/