我正在尝试调用Array中的值来打印(在Java中,我正在使用Eclipse)
代码:
import java.util.Scanner;
public class TravelAgent
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
Scanner keyboard = new Scanner(System.in);
int country_choice;
int country_prices;
int user_selecction;
int country_length;
int countrylength;
int x;
String[] country =
{
"Greece","Spain","France","Russia","Italy","Mexico","Germany","Maldives","Thailand","Portugal"
};
int [] country_prices_1 =
{
300,400,200,500,250,800,450,900,750,350
};
String[] hotels_greece =
{
"Lindos Blu","Saint Andrea","The Excelsior","Elite Suites","Avithos","New Hotel","The Met Hotel",
"TesoroBlu Hotel & Spa","Mykonos Grand Hotel","Achtis Hotel"
};
String[] hotels_spain =
{
"Alma Barcelona", "Seaside Grand Hotel Residencia", "Hotel Primero Perimera", "Valbusenda Resort",
"Hotel Maria Cristina", "Gran Hotel La Perla", "El Palace Hotel",
"Tinas de Pechon", "Dream Hotel Gran Tacande", "Protur Palmeras Playa"
};
String[] hotels_france =
{
"Le Bristol Paris", "Hotel Plaza Athenee","Hotel Fabric","La Maison Favart","Hotel Le Six",
"Hotel Royal Riviera", "Hotel Crillon Le Brave", "Mandarin Oriental", "Le Mareuil", "Hotel d’Europe"
};
String[] hotels_russia =
{
"Lotte Hotel Moscow", "Old Estate Hotel & SPA","Pushka Inn Hotel","The Ritz-Carlton Moscow","Mercure Arbat Moscow",
"Belmond Grand Hotel Europe", "Ararat Park Hyatt Moscow", ".Astoria Hotel", "Helvetia Hotel", "Katerina City Hotel"
};
String[] hotels_italy =
{
"Hotel Monika", "Bellevue Syrene","Hotel Ai Reali","Hotel Belvedere","Hotel Buca di Bacco",
"Petronilla Hotel", "Santa Caterina Hotel", "Color Hotel", "Belmond Grand Hotel Timeo", "Antiche Mura Hotel"
};
String[] hotels_mexico =
{
"Rosewood Mayakoba", "Hotel Jashita","Villa La Estancia","Capella Ixtapa","Banyan Tree Cabo Marques",
"The Beloved Hotel", "Casa Misha", "Esperanza", "Excellence Playa Mujeres", "La Casa Que Canta"
};
String[] hotels_germany =
{
"Swissotel Dresden", "Mandarin Oriental","Park Hyatt Hamburg","Steigenberger Grandhotel Handelshof",
"Hotel Villa Hugel", "Sonnenalp Resort", "Hezelhof Hotel", "Das Stue", "Gutshaus Stolpe", "Hotel Edelweiss"
};
String[] hotels_maldives =
{
"Baros Maldives","Soneva Fushi Resort","Constance Moofushi","Taj Exotica Resort & Spa","Mirihi Island Resort",
"Lily Beach Resort & Spa","Naladhu Resort","Veligandu Island Resort","Cocoa Island Resort","Six Senses Laamu"
};
String[] hotels_thailand =
{
"Dhara Devi Chiang Mai","Oriental Residence","Layana Resort & Spa","Beyond Resort Khaolak","Sunsuri Phuket",
"Rimping Village","Rabbit Resort","The Siam","The Peninsula",".Pimalai Resort & Spa"
};
String[] hotels_portugal =
{
"The Cliff Bay","Conrad Algarve","Bristania Hotel","Olissippo Lapa Palace","Quinta Jardins de Lago","The Yeatman",
"Altis Belem Hotel & Spa","Quinta da Bela Vista","Hotel Santa Justa","Hotel Belavista da Luz"
};
int [] hotel_prices_greece =
{
70,90,100,140,80,75,200,110,160,230
};
int [] hotel_prices_spain =
{
50,70,90,100,120,140,160,180,200,230
};
int [] hotel_prices_france =
{
60,60,70,75,80,90,105,120,140,200
};
int [] hotel_prices_russia =
{
80,90,90,95,100,110,130,150,175,190
};
int [] hotel_prices_italy =
{
80,85,90,100,115,130,140,220,235,240
};
int [] hotel_prices_mexico =
{
200,240,260,275,300,360,375,380,395,450
};
int [] hotel_prices_germany =
{
60,65,70,85,100,120,150,180,220,210
};
int [] hotel_prices_maldives =
{
260,280,300,350,380,400,440,450,550,580
};
int [] hotel_prices_thailand =
{
245,255,270,290,300,350,365,370,390,400
};
int [] hotel_prices_portugal =
{
110,115,120,120,140,150,180,185,250,260
};
System.out.println("please select your holiday destination");
System.out.println("************************************");
System.out.println("* Want to book a holiday? *");
System.out.println("* *");
System.out.println("* You're at the right place *");
System.out.println("* *");
System.out.println("************************************");
System.out.println("* Please choose from the following *");
System.out.println("* 1.Greece *");
System.out.println("* 2.Spain *");
System.out.println("* 3.France *");
System.out.println("* 4.Russia *");
System.out.println("* 5.Italy *");
System.out.println("* 6.Mexico *");
System.out.println("* 7.Germany *");
System.out.println("* 8.Maldives *");
System.out.println("* 9.Thailand *");
System.out.println("* 10.Portugal *");
System.out.println("** Enter Destination from 1-10 **");
country_choice =keyboard.nextInt();
For (int x = 0; x < country.price; x++) {
}
//country_choice = Integer.parseInt(user_selection.nextLine())-1;
country_choice = Integer.parseInt(user_selection.nextLine())-1;
System.out.println("country[x]" + "country_prices[x]" );
//“+ country [country_choice]+ country prices [country_prices]+”.00”);
}
}
答案 0 :(得分:0)
在我们开始之前:
不应为每个国家/地区的酒店和酒店价格设置单独的变量,而应使用数组(AKA&#34;二维数组&#34;),其中数组中的每个条目都是另一个阵列。例如, France 是数字3,这意味着它的索引是2(数组索引从0开始),因此main
将是法国酒店名称的数组(而不是hotels[2]
)。这样,如果您在变量中包含国家/地区编号,则可以轻松访问该国家/地区的酒店列表,而无需为每个国家/地区单独编码。
它是这样的:
hotels_france