System.out.println("请选择运输方式:1.卡车 2.火车 3.飞机");
String method = scan.next();
while(!method.matches("\\d+([.]\\d+)?")||!method.matches("[1-3]"))
{
System.out.println("输入有误,请重新输入!");
method = scan.next();
}那int呢?
用什么?System.out.println("请选择操作:1.查询 2.删除 3.新增");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
while(!selection.matches("\\d+([.]\\d+)?")||selection<1||selection>3)
{
System.out.println("输入有误,请重新输入!");
selection = scan.nextInt();
}
switch(selection)
{
case 1:
display();
break;
case 2:
delete();
break;
case 3:
add();
}
String method = scan.next();
while(!method.matches("\\d+([.]\\d+)?")||!method.matches("[1-3]"))
{
System.out.println("输入有误,请重新输入!");
method = scan.next();
}那int呢?
用什么?System.out.println("请选择操作:1.查询 2.删除 3.新增");
Scanner scan = new Scanner(System.in);
int selection = scan.nextInt();
while(!selection.matches("\\d+([.]\\d+)?")||selection<1||selection>3)
{
System.out.println("输入有误,请重新输入!");
selection = scan.nextInt();
}
switch(selection)
{
case 1:
display();
break;
case 2:
delete();
break;
case 3:
add();
}
System.out.println("请选择操作:1.查询 2.删除 3.新增");
Scanner scan = new Scanner(System.in);
String selection = scan.next();
while(!selection.matches("\\d+([.]\\d+)?")||!selection.matches("[1-3]"))
{
System.out.println("输入有误,请重新输入!");
selection = scan.next();
}
if(selection.equals(1))
{
display();
}
else if(selection.equals(2))
{
delete();
}
else
{
add();
}
selection.matches("\\d+([.]\\d+)?")
还有啥意义
System.out.println("请选择操作:1.查询 2.删除 3.新增");
Scanner scan = new Scanner(System.in);
String method = scan.next();
//int selection = scan.nextInt();
while(!selection.matches("\\d+([.]\\d+)?")||selection<1||selection>3)
{
System.out.println("输入有误,请重新输入!");
selection = scan.nextInt();
}
int selection = (int)Float.parseFloat(method);
switch(selection)
{
case 1:
display();
break;
case 2:
delete();
break;
case 3:
add();
}
package community;import java.util.List;
import java.util.Scanner;import user.DbStore;public class CommunityManager
{
public static void main(String args[])
{
System.out.println("请选择操作:1.查询 2.删除 3.新增");
Scanner scan = new Scanner(System.in);
String method = scan.next();
while(!method.matches("\\d+([.]\\d+)?")||!method.matches("[1-3]"))
{
System.out.println("输入有误,请重新输入!");
method = scan.next();
}
int selection = (int)Float.parseFloat(method);
switch(selection)
{
case 1:
display();
break;
case 2:
delete();
break;
case 3:
add();
}
}
public static void display()
{
DbStore abcd = new DbStore();
List<CommunityEntity> list = abcd.getCommList();
Scanner scan = new Scanner(System.in);
System.out.println("请输入区域:");
String area = scan.next();
boolean judge = false; //设置一个标志变量
for(int i=0;i<list.size();i++)
{
if(list.get(i).getCommArea().equals(area))
{
System.out.println(list.get(i));
judge = true;
break;
}
}
if(!judge)
{
System.out.println("输入有误或该区域不存在!");
}
} public static void delete()
{
DbStore abcd = new DbStore();
List<CommunityEntity> list = abcd.getCommList();
Scanner scan = new Scanner(System.in);
System.out.println("请输入要删除的社区编号");
String deletingId = scan.next();
boolean judge = false;
for(int i=0;i<list.size();i++)
{
if(list.get(i).getCommId().equals(deletingId))
{
System.out.println("您要删除的社区编号是:"+deletingId);
list.remove(i);
System.out.println("删除成功!余下的小区信息:");
System.out.println("小区编号"+"\t\t"+"小区名称"+"\t\t"+"小区经理"+"\t\t"+"区域"+"\t\t"+"小区状态"+"\t\t"+"渗透率"+"\t\t"+"覆盖用户数");
System.out.println("----------------------------------------------------------------------------------------------------------");
judge = true;
break;
}
}
if(!judge)
{
System.out.println("该社区不存在!");
}
for(int j=0;j<list.size();j++)
{
System.out.println(list.get(j).getCommId()+"\t\t"+list.get(j).getCommName()+"\t\t"+list.get(j).getCommManager()+"\t\t"+list.get(j).getCommArea()+"\t\t"+list.get(j).getCommStatue()+"\t\t"+list.get(j).getPermeability()+"\t\t"+list.get(j).getUserCount()); }
} public static void add()
{
DbStore abcd = new DbStore();
Scanner scan = new Scanner(System.in);
System.out.println("请输入小区编号:"+"\r\n");
String id = scan.next();
System.out.println("请输入小区名称:"+"\r\n");
String name = scan.next();
System.out.println("请输入小区经理:"+"\r\n");
String manager = scan.next();
System.out.println("请输入所在区域:"+"\r\n");
String area = scan.next();
System.out.println("请输入小区状态:"+"\r\n");
String statue = scan.next();
System.out.println("请输入渗透率:"+"\r\n");
double permeability = scan.nextDouble();
System.out.println("请输入覆盖用户数:"+"\r\n");
int userCount = scan.nextInt();
List<CommunityEntity> list = abcd.getCommList();
CommunityEntity ce = new CommunityEntity();
ce.setCommId(id);
ce.setCommName(name);
ce.setCommManager(manager);
ce.setCommArea(area);
ce.setCommStatue(statue);
ce.setPermeability(permeability);
ce.setUserCount(userCount);
list.add(ce); System.out.println("新增成功!");
System.out.println("该社区信息如下:"+"\n");
System.out.println("小区编号"+"\t\t"+"小区名称"+"\t\t"+"小区经理"+"\t\t"+"区域"+"\t\t"+"小区状态"+"\t\t"+"渗透率"+"\t\t"+"覆盖用户数");
System.out.println("----------------------------------------------------------------------------------------------------------");
System.out.println(ce.getCommId()+"\t\t"+ce.getCommName()+"\t\t"+ce.getCommManager()+"\t\t"+ce.getCommArea()+"\t\t"+ce.getCommStatue()+"\t\t"+ce.getPermeability()+"\t\t"+ce.getUserCount());
}}