mod
parent
c671790341
commit
5d9dbe9c68
|
|
@ -0,0 +1,10 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="SerializableHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SerializableInnerClassHasSerialVersionUIDField" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoreAnonymousInnerClasses" value="false" />
|
||||||
|
<option name="superClassString" value="java.awt.Component" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -3,45 +3,42 @@
|
||||||
|
|
||||||
package org.example;
|
package org.example;
|
||||||
|
|
||||||
import org.example.model.Satellite;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static ArrayList<Satellite> satellites = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// 初始化五个卫星对象
|
// 初始化五个卫星对象
|
||||||
satellites.add(new Satellite("1999-025A", "卫星一号", 7000, true));
|
Satellites sa=new Satellites();
|
||||||
satellites.add(new Satellite("2000-036A", "卫星二号", 8000, false));
|
// 获取卫星集合
|
||||||
satellites.add(new Satellite("2001-047A", "卫星三号", 9000, true));
|
ArrayList<Satellite> satellites = sa.getSatellites();
|
||||||
satellites.add(new Satellite("2002-058A", "卫星四号", 10000, false));
|
// 开启控制台输入
|
||||||
satellites.add(new Satellite("2003-069A", "卫星五号", 11000, true));
|
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
// 创建调用方法对象实例
|
||||||
|
ManageSatellites manage=new ManageSatellites();
|
||||||
|
// 第一次显示菜单
|
||||||
displayMenu();
|
displayMenu();
|
||||||
do {
|
do {
|
||||||
String choose = scanner.next();
|
String choose = scanner.next();
|
||||||
switch (choose) {
|
switch (choose) {
|
||||||
//1-----显示目前活动卫星列表。
|
//1-----显示目前活动卫星列表。
|
||||||
case "1" -> showSatelliteList();
|
case "1" -> manage.showSatelliteList(satellites);
|
||||||
//2-----注册新卫星。
|
//2-----注册新卫星。
|
||||||
case "2" -> addNewSatellite(scanner);
|
case "2" -> manage.addNewSatellite(scanner,satellites);
|
||||||
//3-----删除旧卫星。
|
//3-----删除旧卫星。
|
||||||
case "3" -> delOldSatellite(scanner);
|
case "3" -> manage.delOldSatellite(scanner,satellites);
|
||||||
//4-----激活卫星。
|
//4-----激活卫星。
|
||||||
case "4" -> activeSatellite(scanner);
|
case "4" -> manage.activeSatellite(scanner,satellites);
|
||||||
//5-----封锁(失活)卫星。
|
//5-----封锁(失活)卫星。
|
||||||
case "5" -> blockSatellite(scanner);
|
case "5" -> manage.blockSatellite(scanner,satellites);
|
||||||
//6-----显示失活卫星列表。
|
//6-----显示失活卫星列表。
|
||||||
case "6" -> showBlockSatelliteList();
|
case "6" -> manage.showBlockSatelliteList(satellites);
|
||||||
//7-----按名称模糊查找卫星。
|
//7-----按名称模糊查找卫星。
|
||||||
case "7" -> querySatelliteByNameLike(scanner);
|
case "7" -> manage.querySatelliteByNameLike(scanner,satellites);
|
||||||
//8-----修改卫星信息。
|
//8-----修改卫星信息。
|
||||||
case "8" -> modStatelliteInfo(scanner);
|
case "8" -> manage.modifySatellite(scanner,satellites);
|
||||||
//9-----退出!
|
//9-----退出!
|
||||||
case "9" -> {
|
case "9" -> {
|
||||||
System.out.println("退出");
|
System.out.println("退出");
|
||||||
|
|
@ -49,135 +46,11 @@ public class Main {
|
||||||
}
|
}
|
||||||
default -> System.out.println("没有这个选项");
|
default -> System.out.println("没有这个选项");
|
||||||
}
|
}
|
||||||
|
//循环显示菜单
|
||||||
displayMenu();
|
displayMenu();
|
||||||
} while (scanner.hasNext());
|
} while (scanner.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
//1-----显示目前活动卫星列表。
|
|
||||||
private static void showSatelliteList() {
|
|
||||||
for (Satellite satellite : satellites) {
|
|
||||||
if (satellite.isActivated()) {
|
|
||||||
System.out.println(satellite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//2-----注册新卫星。
|
|
||||||
private static void addNewSatellite(Scanner scanner) {
|
|
||||||
String cosparId = readString(scanner, "请输入卫星的COSPARID: ");
|
|
||||||
String name = readString(scanner, "请输入卫星的名称: ");
|
|
||||||
double r = readDouble(scanner, "请输入卫星的半径: ");
|
|
||||||
boolean activated = readBoolean(scanner, "请输入卫星的状态 (true/false): ");
|
|
||||||
|
|
||||||
Satellite newSatellite = new Satellite(cosparId, name, r, activated);
|
|
||||||
satellites.add(newSatellite);
|
|
||||||
System.out.println("卫星已添加: " + newSatellite);
|
|
||||||
}
|
|
||||||
|
|
||||||
//3-----删除旧卫星。
|
|
||||||
private static void delOldSatellite(Scanner scanner) {
|
|
||||||
String cosparId = readString(scanner, "请输入要删除的卫星COSPARID: ");
|
|
||||||
boolean flag = false;
|
|
||||||
for (Satellite se : satellites) {
|
|
||||||
if (se.getCOSPARID().equals(cosparId)) {
|
|
||||||
satellites.remove(se);
|
|
||||||
System.out.println("卫星已删除: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!flag) {
|
|
||||||
System.out.println("无效的COSPARID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//4-----激活卫星。
|
|
||||||
private static void activeSatellite(Scanner scanner) {
|
|
||||||
String cosparId = readString(scanner, "请输入要激活的卫星COSPARID: ");
|
|
||||||
boolean flag = false;
|
|
||||||
for (Satellite se : satellites) {
|
|
||||||
if (se.getCOSPARID().equals(cosparId)) {
|
|
||||||
if (se.isActivated()) {
|
|
||||||
System.out.println("卫星已处于激活状态,无需重新激活: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
se.setActivated(true);
|
|
||||||
System.out.println("卫星已激活: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!flag) {
|
|
||||||
System.out.println("无效的COSPARID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//5-----封锁(失活)卫星。
|
|
||||||
private static void blockSatellite(Scanner scanner) {
|
|
||||||
String cosparId = readString(scanner, "请输入要封锁的卫星COSPARID: ");
|
|
||||||
boolean flag = false;
|
|
||||||
for (Satellite se : satellites) {
|
|
||||||
if (se.getCOSPARID().equals(cosparId)) {
|
|
||||||
if (!se.isActivated()) {
|
|
||||||
System.out.println("卫星已处于失活状态,无需重新封锁: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
se.setActivated(false);
|
|
||||||
System.out.println("卫星已封锁: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!flag) {
|
|
||||||
System.out.println("无效的COSPARID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//6-----显示失活卫星列表。
|
|
||||||
private static void showBlockSatelliteList() {
|
|
||||||
for (Satellite satellite : satellites) {
|
|
||||||
if (!satellite.isActivated()) {
|
|
||||||
System.out.println(satellite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//7-----按名称模糊查找卫星。
|
|
||||||
private static void querySatelliteByNameLike(Scanner scanner) {
|
|
||||||
String keyword = readString(scanner, "请输入要查找的卫星名称关键字: ");
|
|
||||||
for (Satellite satellite : satellites) {
|
|
||||||
if (satellite.getName().contains(keyword)) {
|
|
||||||
System.out.println(satellite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//8-----修改卫星信息。
|
|
||||||
private static void modStatelliteInfo(Scanner scanner) {
|
|
||||||
String cosparId = readString(scanner, "请输入要修改的卫星COSPARID: ");
|
|
||||||
boolean flag = false;
|
|
||||||
for (Satellite se : satellites) {
|
|
||||||
if (se.getCOSPARID().equals(cosparId)) {
|
|
||||||
String newCosparId = readString(scanner, "请输入卫星的COSPARID: ");
|
|
||||||
se.setCOSPARID(newCosparId);
|
|
||||||
String newName = readString(scanner, "请输入卫星的名称: ");
|
|
||||||
se.setName(newName);
|
|
||||||
double newR = readDouble(scanner, "请输入卫星的半径: ");
|
|
||||||
se.setR(newR);
|
|
||||||
boolean newActivated = readBoolean(scanner, "请输入卫星的状态 (true/false): ");
|
|
||||||
se.setActivated(newActivated);
|
|
||||||
System.out.println("卫星信息已修改: " + se);
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!flag) {
|
|
||||||
System.out.println("无效的COSPARID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//显示菜单
|
//显示菜单
|
||||||
public static void displayMenu() {
|
public static void displayMenu() {
|
||||||
|
|
@ -195,52 +68,5 @@ public class Main {
|
||||||
System.out.print("选择:");
|
System.out.print("选择:");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取字符串输入并校验
|
|
||||||
private static String readString(Scanner scanner, String prompt) {
|
|
||||||
String input;
|
|
||||||
do {
|
|
||||||
System.out.print(prompt);
|
|
||||||
input = scanner.next();
|
|
||||||
if (input.trim().isEmpty()) {
|
|
||||||
System.out.println("输入不能为空,请重新输入。");
|
|
||||||
}
|
|
||||||
} while (input.trim().isEmpty());
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取双精度浮点数输入并校验
|
|
||||||
private static double readDouble(Scanner scanner, String prompt) {
|
|
||||||
double input;
|
|
||||||
while (true) {
|
|
||||||
System.out.print(prompt);
|
|
||||||
if (scanner.hasNextDouble()) {
|
|
||||||
input = scanner.nextDouble();
|
|
||||||
if (input <= 0) {
|
|
||||||
System.out.println("半径必须大于0,请重新输入。");
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("输入无效,请输入一个数字。");
|
|
||||||
scanner.next(); // 清除无效输入
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取布尔值输入并校验
|
|
||||||
private static boolean readBoolean(Scanner scanner, String prompt) {
|
|
||||||
boolean input;
|
|
||||||
while (true) {
|
|
||||||
System.out.print(prompt);
|
|
||||||
if (scanner.hasNextBoolean()) {
|
|
||||||
input = scanner.nextBoolean();
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("输入无效,请输入 true 或 false。");
|
|
||||||
scanner.next(); // 清除无效输入
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,181 @@
|
||||||
|
package org.example;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ManageSatellites {
|
||||||
|
//进一步设计每一个卫星操作方法的细节流程(显示、验证信息)
|
||||||
|
//课堂演示其中一个功能方法
|
||||||
|
|
||||||
|
//1-----显示目前活动卫星列表。
|
||||||
|
public void showSatelliteList(List<Satellite> satellites) {
|
||||||
|
for (Satellite satellite : satellites) {
|
||||||
|
if (satellite.isActivated()) {
|
||||||
|
System.out.println(satellite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//2-----注册新卫星。
|
||||||
|
public void addNewSatellite(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
String cosparId = readString(scanner, "请输入卫星的COSPARID: ");
|
||||||
|
String name = readString(scanner, "请输入卫星的名称: ");
|
||||||
|
double r = readDouble(scanner, "请输入卫星的半径: ");
|
||||||
|
boolean activated = readBoolean(scanner, "请输入卫星的状态 (true/false): ");
|
||||||
|
|
||||||
|
Satellite newSatellite = new Satellite(cosparId, name, r, activated);
|
||||||
|
satellites.add(newSatellite);
|
||||||
|
System.out.println("卫星已添加: " + newSatellite);
|
||||||
|
}
|
||||||
|
|
||||||
|
//3-----删除旧卫星。
|
||||||
|
public void delOldSatellite(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
String cosparId = readString(scanner, "请输入要删除的卫星COSPARID: ");
|
||||||
|
boolean flag = false;
|
||||||
|
for (Satellite se : satellites) {
|
||||||
|
if (se.getCOSPARID().equals(cosparId)) {
|
||||||
|
satellites.remove(se);
|
||||||
|
System.out.println("卫星已删除: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
System.out.println("无效的COSPARID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//4-----激活卫星。
|
||||||
|
public void activeSatellite(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
String cosparId = readString(scanner, "请输入要激活的卫星COSPARID: ");
|
||||||
|
boolean flag = false;
|
||||||
|
for (Satellite se : satellites) {
|
||||||
|
if (se.getCOSPARID().equals(cosparId)) {
|
||||||
|
if (se.isActivated()) {
|
||||||
|
System.out.println("卫星已处于激活状态,无需重新激活: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
se.setActivated(true);
|
||||||
|
System.out.println("卫星已激活: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
System.out.println("无效的COSPARID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//5-----封锁(失活)卫星。
|
||||||
|
public void blockSatellite(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
String cosparId = readString(scanner, "请输入要封锁的卫星COSPARID: ");
|
||||||
|
boolean flag = false;
|
||||||
|
for (Satellite se : satellites) {
|
||||||
|
if (se.getCOSPARID().equals(cosparId)) {
|
||||||
|
if (!se.isActivated()) {
|
||||||
|
System.out.println("卫星已处于失活状态,无需重新封锁: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
se.setActivated(false);
|
||||||
|
System.out.println("卫星已封锁: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
System.out.println("无效的COSPARID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//6-----显示失活卫星列表。
|
||||||
|
public void showBlockSatelliteList(List<Satellite> satellites) {
|
||||||
|
for (Satellite satellite : satellites) {
|
||||||
|
if (!satellite.isActivated()) {
|
||||||
|
System.out.println(satellite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//7-----按名称模糊查找卫星。
|
||||||
|
public void querySatelliteByNameLike(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
String keyword = readString(scanner, "请输入要查找的卫星名称关键字: ");
|
||||||
|
for (Satellite satellite : satellites) {
|
||||||
|
if (satellite.getName().contains(keyword)) {
|
||||||
|
System.out.println(satellite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//8-----修改卫星信息。
|
||||||
|
public void modifySatellite(Scanner scanner, List<Satellite> satellites) {
|
||||||
|
|
||||||
|
String cosparId = readString(scanner, "请输入要修改的卫星COSPARID: ");
|
||||||
|
boolean flag = false;
|
||||||
|
for (Satellite se : satellites) {
|
||||||
|
if (se.getCOSPARID().equals(cosparId)) {
|
||||||
|
String newCosparId = readString(scanner, "请输入卫星的COSPARID: ");
|
||||||
|
se.setCOSPARID(newCosparId);
|
||||||
|
String newName = readString(scanner, "请输入卫星的名称: ");
|
||||||
|
se.setName(newName);
|
||||||
|
double newR = readDouble(scanner, "请输入卫星的半径: ");
|
||||||
|
se.setR(newR);
|
||||||
|
boolean newActivated = readBoolean(scanner, "请输入卫星的状态 (true/false): ");
|
||||||
|
se.setActivated(newActivated);
|
||||||
|
System.out.println("卫星信息已修改: " + se);
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
System.out.println("无效的COSPARID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 读取字符串输入并校验
|
||||||
|
private static String readString(Scanner scanner, String prompt) {
|
||||||
|
String input;
|
||||||
|
do {
|
||||||
|
System.out.print(prompt);
|
||||||
|
input = scanner.next();
|
||||||
|
if (input.trim().isEmpty()) {
|
||||||
|
System.out.println("输入不能为空,请重新输入。");
|
||||||
|
}
|
||||||
|
} while (input.trim().isEmpty());
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取双精度浮点数输入并校验
|
||||||
|
private static double readDouble(Scanner scanner, String prompt) {
|
||||||
|
double input;
|
||||||
|
while (true) {
|
||||||
|
System.out.print(prompt);
|
||||||
|
if (scanner.hasNextDouble()) {
|
||||||
|
input = scanner.nextDouble();
|
||||||
|
if (input <= 0) {
|
||||||
|
System.out.println("半径必须大于0,请重新输入。");
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("输入无效,请输入一个数字。");
|
||||||
|
scanner.next(); // 清除无效输入
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取布尔值输入并校验
|
||||||
|
private static boolean readBoolean(Scanner scanner, String prompt) {
|
||||||
|
boolean input;
|
||||||
|
while (true) {
|
||||||
|
System.out.print(prompt);
|
||||||
|
if (scanner.hasNextBoolean()) {
|
||||||
|
input = scanner.nextBoolean();
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.out.println("输入无效,请输入 true 或 false。");
|
||||||
|
scanner.next(); // 清除无效输入
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
package org.example.model;
|
package org.example;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : [chd]
|
* @author : [chd]
|
||||||
|
|
@ -19,6 +21,7 @@ public class Satellite {
|
||||||
//状态
|
//状态
|
||||||
private boolean activated=false;
|
private boolean activated=false;
|
||||||
|
|
||||||
|
//构造方法
|
||||||
public Satellite(String COSPARID, String name, double r, boolean activated) {
|
public Satellite(String COSPARID, String name, double r, boolean activated) {
|
||||||
this.COSPARID = COSPARID;
|
this.COSPARID = COSPARID;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -26,6 +29,7 @@ public class Satellite {
|
||||||
this.activated = activated;
|
this.activated = activated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//重写tostring方法
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Satellite{" +
|
return "Satellite{" +
|
||||||
|
|
@ -36,6 +40,22 @@ public class Satellite {
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Satellite satellite = (Satellite) o;
|
||||||
|
return Double.compare(r, satellite.r) == 0 &&
|
||||||
|
activated == satellite.activated &&
|
||||||
|
Objects.equals(COSPARID, satellite.COSPARID) &&
|
||||||
|
Objects.equals(name, satellite.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(COSPARID, name, r, activated);
|
||||||
|
}
|
||||||
|
|
||||||
public String getCOSPARID() {
|
public String getCOSPARID() {
|
||||||
return COSPARID;
|
return COSPARID;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package org.example;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Satellites {
|
||||||
|
|
||||||
|
private ArrayList<Satellite> satellites=new ArrayList<Satellite>(10);
|
||||||
|
|
||||||
|
public Satellites() {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化
|
||||||
|
public void init(){
|
||||||
|
satellites.add(new Satellite("1999-025A", "卫星一号", 7000, true));
|
||||||
|
satellites.add(new Satellite("2000-036A", "卫星二号", 8000, false));
|
||||||
|
satellites.add(new Satellite("2001-047A", "卫星三号", 9000, true));
|
||||||
|
satellites.add(new Satellite("2002-058A", "卫星四号", 10000, false));
|
||||||
|
satellites.add(new Satellite("2003-069A", "卫星五号", 11000, true));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSatellites(ArrayList<Satellite> satellites) {
|
||||||
|
this.satellites = satellites;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//获取卫星集合
|
||||||
|
public ArrayList<Satellite> getSatellites() {
|
||||||
|
return satellites;
|
||||||
|
}
|
||||||
|
/*//新增一个卫星
|
||||||
|
public void addSatellite(Satellite satellite) {
|
||||||
|
satellites.add(satellite);
|
||||||
|
}
|
||||||
|
//修改卫星对象
|
||||||
|
public void modifySatellite(String cosparid,Satellite satellite) {
|
||||||
|
this.removeSatelliteByCosparid(cosparid);
|
||||||
|
addSatellite(satellite);
|
||||||
|
}
|
||||||
|
//删除一个卫星
|
||||||
|
public void removeSatelliteByCosparid(String cosparid){
|
||||||
|
int index=-1;
|
||||||
|
for (Satellite satellite : satellites) {
|
||||||
|
if(cosparid.equals(satellite.getCOSPARID())){
|
||||||
|
index=satellites.indexOf(satellite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(index!=-1){
|
||||||
|
System.out.println("未找到对应卫星,请重新操作!");
|
||||||
|
}else{
|
||||||
|
satellites.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//根据名字模糊查询一个卫星
|
||||||
|
public Satellite findSatelliteByName(String name) {
|
||||||
|
for (Satellite satellite : satellites) {
|
||||||
|
if (satellite.getName().contains(name)) {
|
||||||
|
return satellite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue