tutu的系统

Posted vickytjh

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tutu的系统相关的知识,希望对你有一定的参考价值。

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.File;
import java.util.SplittableRandom;

public class tuSystem {

//常量
private static final int INT_TYPE = 1;
private static final int STRING_TYPE = 2;
private static final int DATE_TYPE = 3;
private static final int DOUBLE_TYPE = 4;
private static final String SPLIT = "#";


public static void main(String[] args) {
// tuSystem tu = new tuSystem();
// tu.start();
tuSystem.start();
}

static File file;
static PrintStream ps;

//输出内容
public static void printString(String string){
System.out.print(string);
try{
if(file == null){
file = new File("d://log.txt");
if(!file.exists()){
file.createNewFile();
}
}
if (ps == null){
ps = new PrintStream(new FileOutputStream(file, true));
}
ps.append(string);
}catch (Exception e){
System.out.print(e.getMessage());
}
}


//获取输入数据验证
public static Object getInputValue(int type) {
while (true) {
Scanner scanner = new Scanner(System.in);
Object obj = scanner.next();
if (obj.toString().equals(SPLIT)) {
System.out.print("请重新输入:");
continue;
}
try{
switch (type) {
case INT_TYPE:
obj = Integer.parseInt(obj.toString());
break;
case STRING_TYPE:
obj = obj.toString();
break;
case DATE_TYPE:
obj = Date.valueOf(obj.toString());
break;
case DOUBLE_TYPE:
obj = Double.parseDouble(obj.toString());
break;
}
return obj;
}catch(Exception e){
System.out.println("请重新输入");
}
}
}

//获取输入数据验证
public static Object getInputValue(int type, Object[] range) {
Object obj = getInputValue(type);
for (int i = 0; i < range.length; i++)
{
if ((range[i] + "").equals(obj.toString())) {
return obj;
}
}
System.out.println("请重新输入");
obj = getInputValue(type,range);
return obj;
}

//是否继续
public static boolean isContinue(){
System.out.print("是否继续(Y/N)?");
String isContinue = getInputValue(STRING_TYPE).toString();
if(!"Y".equals(isContinue.toUpperCase())){
return false;
}
return true;
}

//启动菜单
public static void start() {
String title = "----欢迎来到图图的家----";
System.out.println(title);
myMenu();
}

//菜单
public static void myMenu() {
String menu = "1.计算器 \n" +
"2.水仙花 \n" +
"3.菱形图案 \n" +
"4.人员管理 \n" +
"9.退出 \n" +
"请选择数字:";
System.out.print(menu);
Object[] menuList = {1,2,3,4,9};
int selectNum = Integer.parseInt(getInputValue(INT_TYPE,menuList).toString());
switch (selectNum) {
case 1:
calculator();
break;
case 2:
shuiXianHua();
break;
case 3:
diamondOutput();
break;
case 4:
people();
break;
case 9:
System.out.print("系统退出啦!!!!");
System.exit(0); //System.exit(0)是正常退出程序,而System.exit(1)或者说非0表示非正常退出程序。
break;
}
}


//计算器
public static void calculator() {
System.out.println("欢迎使用tutu的计算器");
String record = "";

while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个数字");
double num1 = scanner.nextDouble();

System.out.println("请输入运算符");
String op = scanner.next();

System.out.println("请输入第二个数字");
double num2 = scanner.nextDouble();

double result = 0.0;
switch (op) {
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
}
System.out.printf("您输入的%.2f%s%.2f=%.2f", num1, op, num2, result);
System.out.print("\n是否继续(Y/N)");
String isContinue = scanner.next();
if (!"Y".equals(isContinue.toUpperCase())) {
break;
}
}
myMenu();
}

//水仙花
public static void shuiXianHua() {
for (int num = 100; num < 1000; num++) {
String snum = String.valueOf(num);
Double n1 = Double.parseDouble(snum.substring(0, 1));
Double n2 = Double.parseDouble(snum.substring(1, 2));
Double n3 = Double.parseDouble(snum.substring(2, 3));
if (((n1 * n1 * n1) + (n2 * n2 * n2) + (n3 * n3 * n3)) == Integer.parseInt(snum)) {
System.out.println(snum + " 是水仙花数 \n");
}
}
myMenu();
}

//菱形图案
public static void diamondOutput() {

}

//人员管理
public static void people() {
System.out.println("欢迎使用人员管理系统");
String[] baseList = {"姓名", "年龄", "生日", "地址"};
Object[] genderList = {"男", "女"};

ArrayList peopleList = new ArrayList();

StringBuffer people;
while (true) {
people = new StringBuffer();
for (String base : baseList) {
System.out.print("请输入" + base + ":");
if (base.equals("性别")) {
people.append(getInputValue(STRING_TYPE,genderList).toString());
}else if (base.equals("出生日期")){
people.append(getInputValue(DATE_TYPE).toString());
}else {
people.append(getInputValue(STRING_TYPE).toString());
}
people.append(SPLIT);
}
peopleList.add(people);
if(!isContinue()){
break;
}

}


}
}

以上是关于tutu的系统的主要内容,如果未能解决你的问题,请参考以下文章

P=tutu

为啥尽管源代码没有变化,但从一个系统到另一个系统的片段数量却有很大差异?

C#程序员经常用到的10个实用代码片段 - 操作系统

VS2015 代码片段整理

Android 逆向Linux 文件权限 ( Linux 权限简介 | 系统权限 | 用户权限 | 匿名用户权限 | 读 | 写 | 执行 | 更改组 | 更改用户 | 粘滞 )(代码片段

Xcode 4.6 的备份代码片段