这个不太懂的,真得是应该看一下这个文章

这个不太懂的,真得是应该看一下这个文章,第1张

这个不太懂的,真得是应该看一下这个文章

提示:

文章目录
  • 前言
  • 一、知识点
  • 二、使用步骤
    • 1.引入库创建对象属性和接受参数的方法
    • 2.读入数据编写管理类的方法
    • 3.测试类
  • 三、总结




前言

提示:java书中的网上订餐系统。
例如:随着现在的网络越来越发达,点外卖也越来越受欢迎,所以今天就敲一个简单的网上订餐系统


提示:以下是本篇文章正文内容,下面案例可供参考



一、知识点:

           1.变量  2.数据类型 3.循环结构 4.选择结构  5.数组 6.类和对象



二、使用步骤

1.创建对象属性和接受参数的方法

代码如下:

public class MydinnerSystem {
	
	// 菜品名称
	String[] dinnerName = new String[100];
//菜品价格
	int[] dinnerPrice = new int[100];
//签收订单
	int[] states = new int[100];
//菜品的赞数
	int[] zan = new int[100];
	
//客户昵称
	String[] name = new String[100];
//客户地址
	String[] address = new String[100];
//客户送餐时间
	int[] time = new int[100];
//客户所选菜品总金额
	double[] money = new double[100];
//接收的次数
	int count = 0;
//接收点赞的次数
	int zancount = 0;

	
	public void show(String name, String address, int time, double money, String dinnerName) {
		this.name[count] = name;
		this.address[count] = address;
		this.money[count] = money;
		this.time[count] = time;
		this.dinnerName[count] = dinnerName;
		count++;

	}

	
	public void showzan(int zan, int num) {
		for (int i = 0; i < this.zan.length; i++) {
			if (num == i + 1) {
				this.zan[i] += zan;

			}
		}

	}

}


2.编写管理类的方法

代码如下:

import java.util.Scanner;

public class MydinnerBiz {
	
	MydinnerSystem[] a = new MydinnerSystem[100];
	
	String[] dinnerName = new String[] { "鲍鱼盖饭", "帝王蟹", "油焖龙虾", "烤全羊" };
	
	double[] dinnerPrice = new double[] { 255, 800, 500, 1100 };
	
	int count;
	Scanner input = new Scanner(System.in);

	
	public MydinnerBiz() {
		for (int i = 0; i < a.length; i++) {
			System.out.println("欢迎使用:“吃货联盟订餐系统");
			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("请选择");
			switch (input.nextInt()) {
			case 1:
				System.out.println("******我要订餐******");
				ding();
				break;
			case 2:
				System.out.println("******查看餐袋******");
				showCaidan();
				break;
			case 3:
				System.out.println("******签收订单******");
				qianshow();
				break;
			case 4:
				System.out.println("******删除订单******");
				deleteshow();
				break;
			case 5:
				System.out.println("******我要点赞******");
				zanshow();
				break;
			case 6:
				System.out.println("******退出系统******");
				return;
			default:
				System.out.println("输入错误!");
				break;
			}
		}
	}

	
	MydinnerSystem b = new MydinnerSystem();

	public void ding() {
		//送餐费
		double deliCharge=0;
		//消费总额
		double money;
		//点菜名称
		String dinner = null;
		System.out.println("请输入姓名:");
		String name = input.next();		
		System.out.println("序号t菜品t单价t点赞");
		for (int i = 0; i < dinnerName.length; i++) {
			if (dinnerName[i] != null) {
				System.out.println((i + 1) + "t" + dinnerName[i] + "t" + dinnerPrice[i] + "t" + b.zan[i]);
			}
		}	
		System.out.println("请选择菜品编号:");
		int num = input.nextInt();
		System.out.println("请输入几份");
		int num1 = input.nextInt();
		
		System.out.println("请输入订餐时间(送餐时间10点到20点整点送餐");
		int time = input.nextInt();
		if (time < 10 || time > 20) {
			System.out.println("您的输入有误,请输入10点~20点间的整数");
			return;
		}
		System.out.println("请输入送餐地址");
		String address = input.next();
		switch (num) {
		case 1:
			money = dinnerPrice[0] * num1;
			if(money<300) {
				deliCharge=20;
				money+=deliCharge;
			}
			System.out.println("订餐成功!");
			System.out.println("您订的是:" + dinnerName[0] + num1+"份t" + "订餐时间是:"+time+"点"+"t餐费:" + money+"元,送餐费:"+deliCharge+"元"+"总计:"+money);
			dinner = "鲍鱼盖饭";
			b.show(name, address, time, money, dinner);		
			a[count] = b;
			count++;
			break;
		case 2:
			money = dinnerPrice[1] * num1;
			System.out.println("订餐成功!");
			System.out.println("您订的是:" + dinnerName[1] + num1+"份t" + "订餐时间是:"+time+"点"+"t餐费:" + money+"元,送餐费:"+deliCharge+"元"+"总计:"+money);
			dinner = "帝王蟹";
			b.show(name, address, time, money, dinner);
			a[count] = b;
			count++;
			break;
		case 3:
			money = dinnerPrice[2] * num1;
			System.out.println("订餐成功!");
			System.out.println("您订的是:" + dinnerName[2] + num1+"份t" + "订餐时间是:"+time+"点"+"t餐费:" + money+"元,送餐费:"+deliCharge+"元"+"总计:"+money);
			dinner = "油焖龙虾";
			b.show(name, address, time, money, dinner);
			a[count] = b;
			count++;
			break;
		case 4:
			money = dinnerPrice[3] * num1;
			System.out.println("订餐成功!");
			System.out.println("您订的是:" + dinnerName[3] + num1+"份t" + "订餐时间是:"+time+"点"+"t餐费:" + money+"元,送餐费:"+deliCharge+"元"+"总计:"+money);
			dinner = "烤全羊";
			b.show(name, address, time, money, dinner);
			a[count] = b;
			count++;
			break;
		default:
			System.out.println("输入错误");
			break;
		}
	}

	
	public void showCaidan() {

		System.out.println("序号t姓名t地址t菜品t总价t时间t订单状态");
		for (int i = 0; i < count; i++) {
			String states = (a[i].states[i] == 0) ? "已预订" : "已完成";
			if (a[i].name[i] != null && a[i].address[i] != null && dinnerName[i] != null && a[i].money[i] != 0
					&& a[i].time[i] != 0) {
				System.out.println((i + 1) + "t" + a[i].name[i] + "t" + a[i].address[i] + "t" + a[i].dinnerName[i]
						+ "t" + a[i].money[i] + "元t" + a[i].time[i] + "点t" + states);
			}
		}
	}

	
	public void qianshow() {
		System.out.println("请输入订单编号");
		int num = input.nextInt();
		for (int i = 0; i < count; i++) {
			if (b.name[i] != null && b.states[i] == 0 && num == i + 1) {
				b.states[i] = 1;
				System.out.println("订单签收成功!");
			} else if (b.name[i] != null && b.states[i] == 1 && num == i + 1) {
				System.out.println("您选择的订单已完成签收,不能再次签收!");
				return;
			} else {
				if (i + 1 == count) {
					System.out.println("没有找到该订单!");
				}
				continue;
			}
		}
	}

	
	public void deleteshow() {
		System.out.println("请输入要删除的订单编号:");
		int num = input.nextInt();
		for (int i = 0; i < count; i++) {
			if (b.name[i] != null && num == i + 1) {
				b.name = null;
				b.address[i] = null;
				b.time[i] = 0;
				b.dinnerName[i] = null;
				b.money[i] = 0;
				b.states[i] = 0;
				count -= 1;
				System.out.println("删除成功!");
			} else {
				System.out.println("没有找到该订单");
			}
		}
	}

	
	public void zanshow() {
		int zan = 0;
		System.out.println("请输入点赞的菜品号");
		int num = input.nextInt();
		for (int i = 0; i < dinnerName.length; i++) {
			if (num == i + 1) {
				zan += 5;
				System.out.println("点赞成功!");
				b.showzan(zan, num);
				return;
			}
			if (i == dinnerName.length - 1) {
				System.out.println("没有找到该菜品");
			}

		}
	}
}
3、测试类

        代码如下:      

public class MydinnerTest {

	public static void main(String[] args) {	
		new MydinnerBiz();
	}

}



总结

          前期学习尽量扎实点,多敲敲代码和实例,锻炼一下敲代码的逻辑思维,为以后打好基础

毕竟学校里学到工作中都用不到

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5522415.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存