补交

15章
2 。 public static void main(String[] args) {
String fruit[] = new String[5];
Scanner input = new Scanner(System.in);
for(int i = 0; i < fruit.length; i++){
System.out.print(“请输入第” + (i+1) + “种水果:”);
fruit[i] = input.next();
}
Arrays.sort(fruit);
System.out.println("\n这些水果在字典中出现的顺序是:");
for(int i = 0; i < fruit.length; i++ ){
System.out.println(fruit[i]);
}
}
}

3 . public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("输入任意一个姓名: “);
String name = input.next();
int length = name.length();
System.out.println(”\n姓氏: " + name.charAt(0));
System.out.println("名字: " + name.substring(1,length));
}
}

  1. public static void main(String[] args) {

     System.out.print("请输入用户的身份证号码: ");
     Scanner input = new Scanner(System.in);
     String id = input.next();
     String year = "";
     String month = "";
     String day = "";
     if(id.length() != 18){   
     	System.out.println("\n身份证号码无效!");
     }else{
     	year = id.substring(6,10);   
     	month = id.substring(10,12); 
     	day = id.substring(12,14);   
     	System.out.println("\n该用户生日是: " + year + "年" + month + "月" + day + "日");
     }
    

    }
    }

5 。public void locateChar(String full, char c) {
System.out.print(c + "出现的位置是: ");
for (int i = 0; i < full.length(); i++) {
if (c == full.charAt(i)) {
System.out.print(i + “\t”);
}
}
}

public void locateString(String full, String s) {
	int index = 0;
	int i = index;
	int length = full.length();
	System.out.print(s + "出现的位置是: ");
	do {
		index = full.indexOf(s, i);
		if (index == -1) {
			break;
		}
		System.out.print(index + "   ");
		i = index + s.length();
	} while (i <= length);
}

----=====
public static void main(String[] args) {
StringExplorer se = new StringExplorer();
Scanner input = new Scanner(System.in);
System.out.println("请输入一段字符: ");
String full = input.next();
System.out.println("请输入要查询的字符串: ");
String s = input.next();
se.locateString(full, s);
}
}

6、public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean con = true;

	while(con){
	   System.out.print("\n请输入会员生日<月/日:00/00>:  ");
	   String day = input.next();
	   if(day.indexOf('/')!=2){
		   System.out.println("生日形式输入错误!");
	   }else{
	       System.out.println("该会员生日是: " + day);	
	       con = false;
	   }
	}
	
	con = true;
	
	while(con){
	   System.out.print("\n请输入会员密码<6~10位>:  ");
	   String psw = input.next();
	   if(psw.length() < 6 || psw.length() > 10){
		    System.out.println("密码形式输入错误!");
	   }else{
		    System.out.println("该会员的密码是: " + psw);	
		    con = false;
	   }
	}
}

}
16章
1 。 public boolean login(String name,String password){
if(name.equals(“jbit”)&&password.equals(“bdqn”)){
return true;
}else
return false;
}

----=====

public static void main(String[] args) {
	
	Scanner input = new Scanner(System.in);
	System.out.println("请输入用户名:");
	String name = input.next();
	System.out.println("请输入密码:");
	String password = input.next();
	
	Login lg=new Login ();
	boolean flag=lg.login(name, password);
	if(flag){
		System.out.println("登录成功!");
	}else{
		System.out.println("用户名或密码错误!");
	}
}

}

  1. public class Student {
    

    private String name; //姓名
    private int age; //年龄
    private String sex; //性别
    private String school; //学校
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public String getSex() {
    return sex;
    }
    public void setSex(String sex) {
    this.sex = sex;
    }
    public String getSchool() {
    return school;
    }
    public void setSchool(String school) {
    this.school = school;
    }

}
-----=====
public void insertStudent(Student stu){
String name=stu.getName();
int age=stu.getAge();
String sex=stu.getSex();
String school=stu.getSchool();
System.out.println("\n将该学生信息成功写入到数据库");
System.out.println(name+" “+age+” “+ sex +” "+school);
}

public static void main(String[] args) {
	Scanner input = new Scanner(System.in);
	System.out.println("请输入学生姓名:");
	String name = input.next();
	System.out.println("请输入学生年龄:");
	int age = input.nextInt();
	System.out.println("请输入学生性别:");
	String sex = input.next();
	System.out.println("请输入学生学校:");
	String school = input.next();
	Student stu = new Student();
	stu.setName(name);
	stu.setAge(age);
	stu.setSchool(school);
	stu.setSex(sex);
	
	StudentDao stuDao =new StudentDao();
	stuDao.insertStudent(stu);
}

}

  1. public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.print("请输入年份: “);
    int year = input.nextInt();
    System.out.print(“请选择产品类型(1. 台式机 2. 笔记本 3. 其他)”);
    int type = input.nextInt();
    int random = (int)(Math.random() * 1000);
    String productNo = year + “0” + type + random;
    System.out.println(”\n该固定资产编号是: " + productNo);
    }
    }

  2. public static void main(String[] args) {
    System.out.print(“请输入一个日期(月/日/年): “);
    Scanner input = new Scanner(System.in);
    String date = input.next();
    int pos1 = date.indexOf(”/”);
    int pos2 = date.lastIndexOf("/");
    int length = date.length();
    String month = date.substring(0, pos1);
    String day = date.substring((pos1 + 1), pos2);
    String year = date.substring((pos2 + 1), length);
    System.out.println("\n\n" + year + “年” + month + “月” + day + “日”);

}

}

17章
package ch17;

import java.util.Scanner;

public class Chihou3 {
String[] dishNames = { “红烧鱼带”, “鱼香肉丝”, “时令蔬菜” };// 菜品名称
double[] prices = new double[] { 38.0, 20.0, 10.0 };// 菜品单价
int[] praiseNums = new int[3];// 点赞
Scanner input = new Scanner(System.in);
// 创建订单对象
Chihou3 chihou2=new Chihou3();
// 初始2个订单
private String[] names;
private String[] dishMegs;
private int[] times;
private String[] addresses;
private double[] sumPrices;
private int[] states;

public void initial() {
	// 初始化第1条订单信息
	chihou2.names[0] = "张琴";
	chihou2.dishMegs[0] = "红烧鱼带 2份";
	chihou2.times[0] = 12;
	chihou2.addresses[0] = "天成路207号";
	chihou2.sumPrices[0] = 76.0;
	chihou2.states[0] = 1;
	// //初始化第1条订单信息
	chihou2.names[1] = "张琴";
	chihou2.dishMegs[1] = "鱼香肉丝 2份";
	chihou2.times[1] = 18;
	chihou2.addresses[1] = "天成路207号";
	chihou2.sumPrices[1] = 20.0;
	chihou2.states[1] = 0;
}

public void startMenu() {
	int num = -1
	boolean isExit = false
	System.out.println("\n欢迎使用  “吃货联盟订餐系统”");
	// 循环: 显示菜单,根据用户选择的数字执行相应功能
	do {
	
		System.out.println("****************");
		System.out.println("1,我要订餐");
		System.out.println("2,查看餐袋");
		System.out.println("3,签收订单");
		System.out.println("4,删除订单");
		System.out.println("5,我要点赞");
		System.out.println("6,退出系统");
		System.out.println("****************");
		System.out.print("请选择");
		int choose = input.nextInt();
	
		switch (choose) {
		case 1:
		
			System.out.println("***我要订餐***");

			break;

		case 2:
			
			System.out.println("***查看餐袋***");

			break;
		case 3:
		
			System.out.println("***查看餐袋***");

			break;
		case 4:
		
			System.out.println("***删除订单***");

			break;
		case 5:
			
			System.out.println("***我要点赞***");

			break;
		case 6:
		
			System.out.println("***退出系统***");

			break;
		default:
			
			isExit = true;
			break;
		}
		if (!isExit) {
			System.out.print("输入0返回:");
			num = input.nextInt();
		} else {
			break;
		}
	} while (num == 0);
	System.out.println("谢谢使用,欢迎下次光临!");
}

boolean add() {

	Boolean isAdd = false;// 记录是否可以订餐

	for (int j = 0; j < chihou2.names.length; j++) {
		if (chihou2.names[j] == null) {// /找到第一个空位置,可以添加订单信息
			isAdd = true;// 置标志位,可以订餐
			System.out.print("请输入订餐人姓名");
			String name = input.next();
		
			System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t"
					+ "点赞数");
			for (int i = 0; i < dishNames.length; i++) {
				String price = prices[i] + "元";
				String priaiseNum = (praiseNums[i]) > 0 ? praiseNums[i]
						+ "赞" : "0";
				System.out.println((i + 1) + "\t" + dishNames[i] + "\t"
						+ price + "\t" + priaiseNum);
			}
			System.out.print("请选择您要点的菜品编号:");
			int chooseDish = input.nextInt();
			System.out.print("请选择您需要的份数");
			int number = input.nextInt();
			String dishMeg = dishNames[chooseDish - 1] + " " + number + "份";
			double sumPrice = prices[chooseDish - 1] * number;
			// 餐费满50元,免送餐费5元
			double deliCharge = 0;
			if (sumPrice < 50)
				deliCharge = 5;
			System.out.println("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
			int time = input.hashCode();
			while (time < 10 || time > 20) {
				System.out.println("您的输入有误,请输入10~20间的整数");
				time = input.hashCode();
			}
			System.out.println("请输入送餐地址:");
			String address = input.next();
		
			System.out.println("订餐成功!");
			System.out.println("您订的是:" + dishMeg);
			System.out.println("送餐时间:" + time + "时");
			System.out.println("餐费:" + sumPrice + "元,送餐费" + deliCharge
					+ "元,总计:" + (sumPrice + deliCharge) + "元。");
		
			chihou2.names[j] = name;
			chihou2.dishMegs[j] = dishMeg;
			chihou2.times[j] = time;
			chihou2.addresses[j] = address;
			chihou2.sumPrices[j] = sumPrice + deliCharge;
			break;
		}
	}
	if (!isAdd) {
		System.out.println("对不起,您的餐袋已满!");
		return false;
	} else
		return true;
}

void display() {
	System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t\t总金额\t订单状态");
	for (int i = 0; i < chihou2.names.length; i++) {
		if (chihou2.names[i] != null) {
			String state = (chihou2.states[i] == 0) ? "已预定" : "已完成";
			String date = chihou2.times[i] + "时";
			String sumPrice = chihou2.sumPrices[i] + "元";
			System.out.println((i + 1) + "\t" + chihou2.names[i] + "\t"
					+ chihou2.dishMegs[i] + "\t" + chihou2.addresses[i]
					+ "\t" + sumPrice + "\t+state");
		}
	}
}

void sign() {
	boolean isSignFind = false;
	System.out.println("请选择要签收的订单序号:");
	int sigeOrderld = input.nextInt();
	for (int i = 0; i < chihou2.names.length; i++) {
		
		if (chihou2.names[i] != null && chihou2.states[i] == 0
				&& sigeOrderld == i + 1) {
			chihou2.states[i] = 1;// 将状态值置为已完成
			System.out.println("订单签收成功");
			isSignFind = true;
		} else if (chihou2.names[i] != null && chihou2.states[i] == 1
				&& sigeOrderld == i + 1) {
			System.out.println("您选择的订单已完成签收,不能再次签收!");
			isSignFind = true;
		}
	}

			if(!isSignFind){
				System.out.println("您选择的订单不存在!");
}

}
void delete(int delld){
boolean isDelFind=false;
System.out.print(“请输入要删除的订单序号:”);
int delId = input.nextInt();
for(int i=0;i<chihou2.names.length;i++){

		if(chihou2.names[i]!=null && chihou2.states[i]==1 && delId==i+1){	
		isDelFind=true;
	
		for(int j=delId-1;j<chihou2.names.length-1;j++){
			chihou2.names[j] = chihou2.names[j+1];
			chihou2.dishMegs[j] = chihou2.dishMegs[j+1];
			chihou2.times[j] = chihou2.times[j+1];
			chihou2.addresses[j] = chihou2.addresses[j+1];
			chihou2.states[j] = chihou2.states[j+1];

}

		int nu=chihou2.names.length-1;
		chihou2.names[nu] = null;
		chihou2.dishMegs[nu] = null;
		chihou2.times[nu] = 0;
		chihou2.addresses[nu] = null;
		chihou2.states[nu] = 0;
		
		System.out.println("删除订单成功!");
		break;
	}else if(chihou2.names[i]!=null && chihou2.states[i]==0 && delld==i+1){
		System.out.println("您选择的订单未签收,不能删除!");
		isDelFind=true;
		break;
	}
}


	if(!isDelFind){
		System.out.println("您要删除的订单不存在!");

}
}
void praise(){

		System.out.println("序号" + "\t" + "菜名" + "\t" + "单价" + "\t" + "点赞数");
		for (int i = 0; i < dishNames.length; i++) {
			String price = prices[i] + "元";
			String praiseNum;
			if (praiseNums[i] > 0 )
				praiseNum=praiseNums[i]+"赞";
			else
				praiseNum="";
			System.out.println((i + 1) + "\t" + dishNames[i] + "\t"	+price+"\t"+ praiseNum);
		}
		int priaiseNum;
		do{
			System.out.println("请选择您要点赞的菜品序号:");
			priaiseNum=input.nextInt();
		}while(priaiseNum<=0||priaiseNum>dishNames.length);
		praiseNums[priaiseNum-1]++;  
		System.out.println("点赞成功!");
	}

}

-==========

package ch17;

public class Chihou2 {
public static void main(String[] args) {
OrderingUtil om = new OrderingUtil();
om.initial();
om.startMenu();
}

	String[] names = new String[4]; // 订餐人名称
	String[] dishMegs = new String[4]; // 所选菜品
	int[] times = new int[4]; // 送餐时间
	String[] addresses = new String[4]; // 送餐地址
	int[] states = new int[4]; // 订单状态: 0:已预定 1:已完成
	double[] sumPrices = new double[4]; // 总金额

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值