首页 > 其他分享 >前三次题目总结

前三次题目总结

时间:2023-05-24 23:12:24浏览次数:42  
标签:总结 菜单 题目 int Dish arr1 time 三次 order

1,前言

前三次题目集涉及的知识点主要包括输入输出的考察,循环的应用以及if-else的运用,类的创建,方法的调用,封装等等;题量适中,第一次九道入门的题目,第二次四道,第三次七道;难度而言第一次题目集由于有着C语言的基础还是较为简单的,第二次作业开始难度就上来了,如果平时没有花时间在学习java上面的话,完成上面的题目是有困难的,总结下来难度还是偏大的。

2,设计与分析

菜单计价程序-1类图

 第一次的菜单计价较为简单,只要创建一个dish类,在根据题目要求创建变量及相应的构造方法,方法,对象的构造及使用即可,通过Calculate方法计算出总价,通过Compare方法判断订单中的菜是否存在于菜单中;通过第一次的菜单计价学会了类的创建,能够较为熟练的通过编译器书写构造方法及方法。

菜单计价程序-2类图

 第二次菜单计价在第一次的基础上多了几个变量及方法,使得菜单的功能更加齐全,此次较上次增加了删除订单中某一菜品的方法,通过创建一个数组将菜品信息存入,再通过订单中菜品的序号来将其删除;通过Judge方法判断订单中是否存在菜谱中不存在的菜品;通过第二次菜单计价程序更为熟练的掌握了对象的构造及使用,以及通过编译器调试程序。

菜单计价程序-3类图

 菜单3又在菜单2的基础上添加了桌子,代点菜,和判断时间打折扣的功能,菜单3的难度较上次菜单2大幅提高,通过创建Table类及其方法来进一步实现点菜和新增的代点菜的功能以及判断餐馆是否开门及打折的功能,其他则和菜单2无太大的区别。而通过这次的菜单程序的编写,知道了如何运用各个网站学习相关的方法编写。

3,踩坑心得


static class Table {
Order order = new Order();
int num;
int order_count=0;
LocalDateTime time ;
long sum=0;
void od(Menu menu,int menu_count,String str1,String str2,int portion,int quota){
if(str2.equals("delete")){
if(order.delARecordByOrderNum(Integer.parseInt(str1),order_count))
order_count--;
}
else {
if(menu.searchDish(str2,menu_count)!=-1){
order.records[order_count] = new Record();
order.records[order_count] = order.addARecord(Integer.parseInt(str1),str2,portion,quota,menu_count,menu);
order_count++;
}
else System.out.println(str2+" does not exist");
}
}
void getSum() {
int weekday = time.getDayOfWeek().getValue();
for(int i=0;i<order_count;i++) {
sum+=order.records[i].getPrice();
}
if(weekday>0&&weekday<6) {
if(time.getHour()>=17&&time.getHour()<20)sum=Math.round(sum*0.8);
if(time.getHour()==20) {
if(time.getMinute()<=30)sum=Math.round(sum*0.8);
}
if(time.getHour()>=10&&time.getHour()<14)sum=Math.round(sum*0.6);
if(time.getHour()==14) {
if(time.getMinute()<=30)sum=Math.round(sum*0.6);
}
}
}
boolean isOpen() {
int weekday = time.getDayOfWeek().getValue();
if(weekday>0&&weekday<6) {
if(time.getHour()>=17&&time.getHour()<20)return true;
if(time.getHour()==20) {
if(time.getMinute()<=30)return true;
}
if(time.getHour()>10&&time.getHour()<14)return true;
if(time.getHour()==10){
if(time.getMinute()>=30)return true;
}
if(time.getHour()==14) {
if(time.getMinute()<=30)return true;
}
}
else {
if(time.getHour()>9&&time.getHour()<21)return true;
if(time.getHour()==9) {
if(time.getMinute()>=30)return true;
}
if(time.getHour()==21) {
if(time.getMinute()<=30)return true;
}
}
return false;

}
}
}


麻婆豆腐 12
油淋生菜 9
table 1 2022/12/3 19/5/12
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
table 2 2022/12/3 15/03/02
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
1 4 麻婆豆腐 1 1
7 delete
endtable 1:
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
table 2:
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
4 table 2 pay for table 1 12
delete error;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Dish[] menu = new Dish[10];//菜谱
int i = 0;
while (true) {
String name = in.next();
if (name.equals("1"))//第一个订单
break;
if(name.equals("end")){
System.out.println("0");
break;
}
int price = in.nextInt();
Dish temp = new Dish(name, price);
menu[i] = temp;
for (int j = 0; j <= i; j++) {
if ((menu[j].getName()).equals(menu[i].getName())) {
menu[j].setPrice(menu[i].getPrice());//将重名菜的价格赋值成最新的
}
}
i++;
}
Dish[] order = new Dish[20];//订单
Dish[] delete = new Dish[20];
int j = 0;
int d = 0;
while (true) {
if (j == 0) {//将第一单单独写入
String id = "1";
String name = in.next();
int portion = in.nextInt();
int num = in.nextInt();
int price = 0;
Dish temp = new Dish(id, name, portion, num, price);
order[j] = temp;
} else {
String id = in.next();
if (id.equals("end"))
break;
String name = in.next();
if (name.equals("delete")) {
//新的删除数组
Dish zip = new Dish(id, name);
delete[d] = zip;
d++;
} else {
int portion = in.nextInt();
int num = in.nextInt();
int price = 0;
Dish temp = new Dish(id, name, portion, num, price);
order[j] = temp;
}
}
j++;
}
Judge(order, menu);//订单中是否有不存在的项目
Caculate(order, menu);//计算每个菜的价钱
Delete(order, delete);
int sum = Compare(order, menu);
PrintDelete(delete);
System.out.println(sum);
}

public static void Judge(Dish[] arr1, Dish[] arr2) {
for (int i = 0; i < arr1.length; i++) {
int cont = 0;
if (arr1[i] == null)
break;
for (int j = 0; j < arr2.length; j++) {
if (arr2[j] == null) {
break;
}
if ((arr1[i].getName()).equals(arr2[j].getName())) {
cont++;
break;
}
}
if (cont == 0)
arr1[i].setId("-2");
}
}

public static void Caculate(Dish[] arr1, Dish[] arr2) {
for (int i = 0; i < arr1.length; i++) {//订单
if (arr1[i] == null)
break;
for (int j = 0; j < arr2.length; j++) {//菜单
if (arr2[j] == null)
break;
if ((arr1[i].getName()).equals(arr2[j].getName())) {
arr1[i].setPrice(arr2[j].getPrice(arr1[i].getPortion(), arr1[i].getNum()));
break;
}
}
}
}
public static Dish[] Delete(Dish[] order, Dish[] delete) {
for (int i = 0; i < delete.length; i++) {
int cont = 0;
if (delete[i] == null)
break;
for (int j = 0; j < order.length; j++) {
if (order[j] == null)
break;
if ((delete[i].getId()).equals(order[j].getId())) {
order[j].setPortion(-1);
cont++;
}
}
if (cont == 0)//无对应序号
delete[i].setName("wrong");
}
return order;
}

public static int Compare(Dish[] arr1, Dish[] arr2) {
int sum = 0;
for (int i = 0; i < arr1.length; i++) {
if (arr1[i] == null)
break;
for (int j = 0; j < arr2.length; j++) {
if (arr2[j] == null) {
break;
}
if ((arr1[i].getName()).equals(arr2[j].getName())) {
if(!(arr1[i].getId().equals("-2"))) {
System.out.println(arr1[i].getId() + " " + arr1[i].getName() + " " + arr1[i].getPrice());
}
if (arr1[i].getPortion()!=-1) {//菜单中有的菜
sum += arr1[i].getPrice();
}
break;
}
}
}
for (int i = 0; i < arr1.length; i++) {
if(arr1[i]==null)
break;
if (arr1[i].getId().equals("-2"))
System.out.println(arr1[i].getName() + " does not exist");
}
return sum;
}
public static void PrintDelete(Dish[] delete) {
for (int i = 0; i < delete.length; i++) {
if (delete[i] == null)
break;
if ((delete[i].getName()).equals("wrong"))
System.out.println("delete error;");
}
}


麻婆豆腐 12
油淋生菜 9
1 麻婆豆腐 2 2
2 油淋生菜 1 3
3 麻辣鸡丝 1 2
5 delete
7 delete
end
1 麻婆豆腐 36
2 油淋生菜 27
麻辣鸡丝 does not exist
delete error;
delete error;
63

进程已结束,退出代码为 0

菜单2无法实现多条订单多条点菜记录删除及删除异常的功能,而菜单3 无法实现对代点菜价格的输出及统计。

4,主要困难以及改进建议

在菜单2中对订单中菜品的序号,一开始使用的是整形变量,在之后的测试发现难以对其进行判断,之后便将其改成String类型,使用equals方法对其进行判断,对菜单中的菜谱及订单的菜品的存储可以将数组改成集合的方式构造ArrayList对象对菜品信息进行存储。

5,总结

通过这三次题目集,学习到了类的创建,方法的调用,封装等等;同时对代码的调试,运用编译器构造方法的能力得到了提高,在对集合以及类之间的关系的判断仍需继续学习和研究,同时对代码的优化及算法的改进及提高上仍要提高。

标签:总结,菜单,题目,int,Dish,arr1,time,三次,order
From: https://www.cnblogs.com/yt04/p/17429819.html

相关文章

  • 题目集1~3的总结性
    一、前言:总结三次题目集的知识点、题量、难度等情况题目集1:知识点:计算,单位换算,键盘录入,数组题量:9难度:中等题目集2:知识点:键盘录入,数组,类的创建,对象的创建和使用,java日期类,递归方法,条件语句和循环语句的使用题量:4难度:偏难题目集3:知识点:键盘录入,数组,类的创......
  • 每日总结 5.24
    今日进行了增删改查的继续学习,熟悉之前的代码书写。case"add":Stringname=request.getParameter("name");Stringpassword=request.getParameter("password");Students=newStudent(name,password);d.add(s)......
  • PTA前三次题目集总结BLOG
    一、前言本学期开展了面向对象程序设计这门课程,开始了Java语言的学习。现对前三次作业的题目集做概括分析: 1.第一次作业共九道题目,难度一般,均为基础题目,主要涉及到的主要是对java语法的认识,以及顺序结构、循环结构、选择结构等知识,这些与C语言并无太大区别,所以完成起来较为顺......
  • 总结加载Shellcode的各种方式
    1.内联汇编加载使用内联汇编只能加载32位程序的ShellCode,因为64位程序不支持写内联汇编#pragmacomment(linker,"/section:.data,RWE")//将data段的内存设置成可读可写可执行#include<Windows.h>//ShellCode部分unsignedcharbuf[]="\xfc\xe8\x8f\x00\x00\x00\x60\x89......
  • 题目集1~3总结
    一.前言Java编程语言是当今最流行的编程语言之一,由于其跨平台性、面向对象性和安全性等特点,受到广泛的应用。作为一名计算机专业的学生,在学习Java编程语言时,我们需要完成多个作业来巩固所学知识。在前三次Java作业中,我们已经学习了Java的基础知识和常用技术,通过完成这些作业,我们......
  • Blog-1-PTA题目集1~3
    前言:题目集1中共有9道题目,对应的题目及难度分别为:1.身体质量指数(BMI)测算(一星)2.长度质量计量单位换算(一星)3.奇数求和(一星)4.房产税费计算2022(一星)5.游戏角色选择(一星)6.学号识别(一星)7.巴比伦法求平方根近似值(一星)8.二进制数值提取(一星)9.判断三角形类型(一星)题目集2中共有4......
  • oop题目集1~3的总结性Blog
    1)前言第一次作业:7-1主要是从控制台输入问题,和嵌套循环。7-2的要点是数据的精确度,严格的输出。7-3是数组的调用,循环的使用。7-4要点在与if和else的使用和标准的输入和输出。7-5主要是switch方法的使用7-6主要是substring的调用和字符串长度的判断length()和.equals()的使用7-7主要......
  • 每日总结-23.5.24
    packagesan;importjava.sql.*;publicclassThesql{publicConnectionconnect;publicThesql()throwsException{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost:3306/web?useUnicode=......
  • 题目集1~3的总结
    1.前言在这三次的题目集中,主要涉及到了面向对象的相关知识点,包括类、对象、构造函数、封装、继承和多态等。我们学习了很多有关面向对象编程和软件设计的知识。这三次的题目集中,题目量和难度都有一定的增加。难度最大的题目集3中,我们需要设计一个完整的菜单计价系统,这一份题目集......
  • 前三次pta题目集分析
    (1)前言:我们是这个学期才开始学Java,上个学期学的是C,坦白说,我的C学的不好,然后这个学期的Java开始也是很吃力,编写代码很不熟练,这次pta的三个题目集,难度是在一步步增加的。第一次的题目一共是有9题,都算比较简单,知识点都是基础一些的计算等基本知识,我也拿到了满分。第二次的题目集......