BLOG-2-Question Set 4, 5, 6 and Midterm Exam Summary Blog
(1)Foreword: InptaNo.4.5.6The knowledge points included in the second major assignment and midterm exam mainly include: understanding the concept of classes, creating classes and instantiating objects. Define the method, parameter passing and return value of the method. Use conditional statements (if-else), loop statements (for, while), etc. to control menu storage and user input. An array or array-like array used to store menu options and handle the user’s selections. The difficulty of the questions varies depending on the question. The fourth menu question only requires basic menu display and user input processing. The subsequent 5.6Two questions require consideration of abnormal input processing and the use of more complex data structures to implement menu functions. The amount of questions is relatively moderate, No. 4TaoptaThe questions may be relatively simple. The two big questions are mainly about the design and method implementation of classes, and the other two questions are about traversal sorting. Comparing with dates examines some basic knowledge and library function knowledge. 5.6The complexity of the question has been greatly increased and the number of questions has been reduced. Its programming design There are more design and implementation details to consider.
(2) Design and Analysis:
The code time complexity of the output class of dishes containing special flavors is generallyO(n), among whichn The quantity recorded for the input dish. Defined in the program
Dishname:dishname Name of dish,priceUnit price,Kind:Types of dishes
Menu: contains array of dishes
Table type: table_number: Table numberorders: List of ordered dishes
User class: name: Username,payUser needs to pay the price
Dish record category: order_number: Serial numberitems: List of ordered dishes
The properties and methods of these classes are relatively simple, so the overall logic of this code is clear and easy to understand and debug. In the main function of the program, the Scanner class is used to read input from the user’s input Information, based on the return value of Match, determine whether the input format is correct and then transfer to the corresponding Perform the corresponding operations in the if statement. Various methods of calling related classes are combined with the dish prices and dish types stored in Dish Calculate the price of the ordered dishes and finally get the total order price and the price that the user needs to pay and then output them uniformly. The discount judgment is completed after the table number data line is entered. The date discount judgment is then judged based on whether it is a special dish combined with the date during calculation. The discount value is used to calculate the price. By encapsulating different functions in different classes, the program structure can be made clearer and easier to expand and maintain.
Regarding the question of inputting a variety of incorrectly entered dishes, due to itssp; else
(int)num[1], menu);
; Payment of vegetables
{
if (table == 0)
{Break;}
WHILE (MATCHER1.Find ()) {
DishName = Matcher1. group();
int r = 0; teger.parseInt(matcher2.group ());
r++; Order[tablex[table-1]].addARecord(0,(int)num[0 ], dishname, (int)num[1], (int) num[2],-1, menu);
order[tablex[table-1]] .addARecord(0,(int)num[0], dishname, (int)num[2], (int) num[3], (int)num[1], menu);
“\ n \ n Enter delete “); ] = Integer.parseInt(matcher2.group());
order[tablex[table -1]].delARecordByOrderNum(delet[del-1][1], menu);
end else
}//while
}//main
}//main
; del++;
. }//Feiend else
}//while
}//main
}//main