【发布时间】:2015-10-27 02:11:49
【问题描述】:
我无法打印出扫描的名字和姓氏(fname1、lname1)。我必须创建 6 个对象,而这两个对象我似乎都无法开始。此外,如果我输入除“yes”或“y”之外的任何内容,它不会循环回到我在 sn-p 上方插入的单选按钮。我该如何解决这个问题?
这是在输出窗口中打印出来的内容:
[,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]]
public class Cabin_Selector
{
public static void main(String[] args)
{
JFrame cabin_selection = new JFrame("Select Your Cabin"); //Prompts the user
cabin_selection.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close the Frame when exiting
Project2_JoshuaLucas selection = new Project2_JoshuaLucas("", "", "", "", "", "", "", 0.00); //Call the constructor for the Project2_JoshuaLucas class
cabin_selection.getContentPane().add(selection); //put the object in the current pane of the jframe
cabin_selection.pack(); //size the frame
cabin_selection.setVisible(true); //make the frame visible
} //end main method
} //end class
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)
while(twopassenger)
{
System.out.println("Please state your FIRST name: ");
fname1=scan_in.nextLine();
System.out.println("Please state your LAST name: ");
lname1=scan_in.nextLine();
System.out.println("Please enter the second passenger's FIRST name: ");
fname2=scan_in.nextLine();
System.out.println("Please enter the second passenger's LAST name: ");
lname2=scan_in.nextLine();
System.out.println("Please enter the city you live in: ");
cob=scan_in.nextLine();
twopassenger=false;
} //Closes while(2passenger)
} //Closes yes | y
else
System.out.println("Please select another cabin");
continues=false;
} //Closes source==cabin1
【问题讨论】:
标签: java constructor calling-convention