0
私はシネマプロジェクトをコーディングしようとしてきましたが、私はそれを理解できません。私がプログラムを走らせるとき、setAgeに最後に入力された値しか出力されないので、正しい年齢でなくても彼の前の誰もが映画館に入ることができます。私はそれが配列ではない人物のオブジェクトと関係があると信じていますが、私はどのようにこれを解決するかわかりません、任意のアイデア?シネマプロジェクトとオブジェクト配列
import java.util.Scanner;
public class Cinema
{
public static void main(String[] args)
{
QueueWithArray q = new QueueWithArray();
Person person = new Person();
Scanner kybd = new Scanner(System.in);
System.out.print("Join (j), leave (l) or end (e)? ");
String action = kybd.nextLine();
while (!action.equalsIgnoreCase("e"))
{
if (action.equalsIgnoreCase("j"))
{
System.out.print("Enter your name: ");
String name = kybd.nextLine();
person.setName(name);
q.add(name);
System.out.println("What is your age? ");
int age = kybd.nextInt();
person.setAge(age);
kybd.nextLine();
System.out.println(name + " is going to the cinema and is " + age + " years old.");
}
else if (action.equalsIgnoreCase("l"))
{
if (!q.isEmpty())
{
if (person.getAge() >= 15)
{
System.out.println(q.remove() + " has left the queue and entered the cinema");
}
else
{
System.out.println(q.remove() + " has left the queue, but is not old enough to watch the film");
}
}
else
{
System.out.println("Queue empty");
}
}
else
{
System.out.println("Invalid operation");
}
System.out.print("Join (j), leave (l) or end (e)? ");
action = kybd.nextLine();
}
}
}
こんにちは、これは今、私はラインのPerson人=新しい人を(持っていることは良い答えですが、名前年齢);パラメータがあるので受け付けません – Luke
パラメータを受け入れるpersonオブジェクトのコンストラクタを作成する必要があります。だから、パブリックPerson(String name、int age){this.name = name; this.age = age;} –
私はこれをしましたが、現在は、qPersonを試して宣言するときに人が文字列に変更できないというエラーを投げています – Luke