露營地服務管理系統的Java代碼:。

露營地服務管理系統的Java代碼:

import java.util.ArrayList;import java.util.Scanner;public class CampingServiceManagementSystem { static ArrayList

campsites = new ArrayList

(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean exit = false; while(!exit) { System.out.println(“Welcome to the Camping Service Management System.”); System.out.println(“Please select one of the following options:\n”); System.out.println(“1. Add a campsite”); System.out.println(“2. Remove a campsite”); System.out.println(“3. View all campsites”); System.out.println(“4. Exit\n”); int choice = sc.nextInt(); switch(choice) { case 1: addCampsite(); break; case 2: removeCampsite(); break; case 3: viewAllCampsites(); break; case 4: exit = true; break; default: System.out.println(“Invalid option. Please try again.\n”); } } sc.close(); } public static void addCampsite() { Scanner sc = new Scanner(System.in); System.out.println(“Please enter the campsite name:”); String name = sc.nextLine(); System.out.println(“Please enter the campsite location:”); String location = sc.nextLine(); Campsite campsite = new Campsite(name,location); campsites.add(campsite); System.out.println(“Campsite added successfully.\n”); } public static void removeCampsite() { Scanner sc = new Scanner(System.in); System.out.println(“Please enter the campsite index to remove:”); int index = sc.nextInt(); if(index < campsites.size() && index >= 0) { campsites.remove(index); System.out.println(“Campsite removed successfully.\n”); } else { System.out.println(“Invalid index. Please try again.\n”); } } public static void viewAllCampsites() { if(campsites.size() == 0) { System.out.println(“There are no campsites in the system.\n”); } else { for(int i = 0; i < campsites.size(); i++) { System.out.println(“Campsite ” + i + “:”); System.out.println(campsites.get(i).getName() + ” – ” + campsites.get(i).getLocation() + “\n”); } } }}class Campsite { private String name; private String location; public Campsite(String n,String l) { name = n; location = l; } public String getName() { return name; } public String getLocation() { return location; }}

這個系統包含三個功能:

添加露營地刪除露營地查看所有露營地

當用戶選擇添加露營地時,程序會要求用戶輸入露營地的名稱和位置,並將新的露營地添加到系統中。

當用戶選擇刪除露營地時,程序會要求用戶輸入要刪除的露營地的索引,並從系統中刪除露營地。

當用戶選擇查看所有露營地時,程序會輸出系統中所有露營地的名稱和位置。

如果系統中沒有露營地,程序會輸出相應的提示。

露營地服務管理系統的Java代碼:。

以上代碼僅供參考,具體根據實際需求進行修改和擴展。