"Book A Ticket Machine"이라고하는 자유 시간 동안 자체 Java 프로그램을 작성하기 시작했습니다. GUI가없는 Java 콘솔 프로그램입니다. FullName, FrequentFlyer ID, Age를 물어보고 지정된 항공사와 항공편 번호를 알려줄 것입니다. 당신이 여행하는 동안 당신의 연료는 감소 할 것이고, 그것이 도착할 때 연료는 채울 것이다 (나는 이것을위한 채우기 방법을 만들 것이다). 범위 밖에서 메서드를 호출 할 때 문제가 있습니다. > 런칭 파일 -JAVA. Java의 다른 범위에서 변수를 사용하여 메서드를 만드는 방법
Flights.java
:현재 나는 두 개의 파일이 있습니다. flightUserDatabase와 연결되었습니다.
flightUserDatabase.java
에서import java.io.Console; public class Flights { public static void main (String[] args) { Console console = System.console(); //Book a Ticket Machine //From Database otherwise Name not found on Database. Put Database in Another Class. Call it flightUserDatabase. /* firstName: DONE lastName: DONE frequentFlyerID: Otherwise Invalid Number parseInt Age: parseInt FUEL MINUS AND FUEL ADD WHEN LAND. */ flightUserDatabase database = new flightUserDatabase(); System.out.println("Enter Creditials: "); database.getDatabase(); String airline = console.readLine("ENTER YOUR AIRLINE: "); String flightNumber = console.readLine("ENTER YOUR FLIGHT NUMBER: "); String gate = "B7"; /* Declare data type String called "gate" */ //Next Version, Generate Random Number System.out.println("This is an automated system. Please Wait..."); System.out.printf("%s %s is Departuring @ Gate:%s \n", airline, flightNumber, gate); /* Use printf from java.io.Console library, then output Gate and Flight Number */ /* Notes: Data Types > String name = "Ohm"; > int age = 42; > double score = 95.5; > char group = 'F'; */ } }
코드 :
-import java.io.Console; //Book a Ticket Machine class flightUserDatabase { Console console = System.console(); public String fullName; public boolean getDatabase() { boolean namesInDatabase; do { fullName = console.readLine("ENTER YOUR FULLNAME: "); namesInDatabase = (fullName.equals("Ohm Passavudh") || fullName.equals("Matt")); if (!namesInDatabase) { console.printf("Sorry, that name is not in our database yet. \n"); } if (namesInDatabase) { console.printf("Welcome, Mr. %s \n", fullName); } } while(!namesInDatabase); return namesInDatabase; } //If Ohm: FFID = 1234569 //If Matt: FFID = 246810 //FFID == FrequentFlyerID /* Get name from inside scope fullName namesInDatabase variable */ public boolean frequentFlyerID() I HAVE PROBLEMS HERE!!! I WANT TO SET Ohm's FFID to 1234569. But how to I determine if the user enters Ohm or Matt. I cannot access the String fullName from the other scope. I hope you understand me. If there is any misunderstanding I can clarify. }
flightUserDatabase.java
이>는 모든 메소드 및 클래스/청사진 모든 사용자 이름, 나이, frequentFlyer 등 Flights.java에서
코드를 포함합니다
코드를 읽을 수 없습니다. 초보자라면 스타일, 가독성 및 분해 방법에 대해 더 많이 생각해보십시오. 사물은 한 가지 일을 잘해야합니다. FlightDatabase가 I/O 작업을 수행하거나 사용자에게 입력을 요구해서는 안됩니다. 승객 용 클래스는 어디에 있습니까? 너 하나 필요해. – duffymo