代写CSE214、代做Java语言程序
HOMEWORK - SPRING 2025
HOMEWORK 4 - Sunday, May 18th before 7PM (China time)

REMINDERS:

Be sure your code follows the coding style for CSE214.
Make sure you read the warnings about academic dishonesty. Remember, all work you submit for homework or exams MUST be your own work.
Submit Assignment: upload and submit your assignment in QQ Group.
You are not allowed to use Java API Tree, ArrayList, Vector, LinkedList or any other Java API Data Structure classes to implement this assignment.
You may use Scanner, InputStreamReader, or any other class that you wish for keyboard input.
Design a program that will be used as a versatile decision-making system based on user input. There are several places where this application can be used. An example is online Technical Support for a product or group of products. A series of questions might be asked and based on the answers, a different branch of questions will be asked as follow-up-questions to determine exactly how to help the user. Another example is a telephone Technical Support, like a 1-800 number. When calling a 1-800 number, you might communicate with a machine. A series of questions are asked and as answers you typically press the numbers on the keypad, 1-9. After determining exactly what the problem is, a simple answer is usually possible.

In this assignment, you will use Ternary (3-ary) trees to represent the flow of data. In each node in the Ternary tree there will be a question to ask. The "answers" will be branches towards more questions in the tree. For the normal assignment, it will be a Ternary (3-ary) tree, meaning that any node can have at most three children. The extra credit part of this assignment should handle 9-ary trees (up to 9 children). For example:

1. Write a fully-documented class named TreeNode that stores the data in each node. It should have:
Three references to other TreeNodes. Left, Middle, Right.

OR
An array with three references to other TreeNodes. If you're doing the extra credit, the array should store potentially 9 TreeNodes.
private String label
The "name" of this TreeNode. It will be used when constructing the tree. More info on labels will follow.
private String message
The message will be displayed to the screen. It will either be a question or just a normal message. If this TreeNode has children TreeNodes, it should then traverse one level downwards to each child node to get the prompts as answers. If this TreeNode is a leaf node, then it should just display the message which will act as a solution.
private String prompt
The prompt will be displayed to the screen as a possible answer to a question. For example, when starting at the root of the tree, there will be a question (message) to ask, and as possible answers the root will traverse one level downwards each child TreeNode to display the prompt as a possible answer.
This class should have a constructor, mutator and accessor methods for each instance variable. You may also want to have a method to determine if this TreeNode is a leaf (no children).

2. Write a fully-documented class named Tree that will have a reference to the root of the tree and other useful methods described below:
Constructor.
public boolean addNode(String label, String prompt, String message, String parentLabel)
A method to add a TreeNode to the tree. The location will be a child of parentLabel. The child node should be left justified meaning that it should first be placed in the left most TreeNode reference, then the middle, then the right. A return value of true indicates that the node was successfully added to the tree. Otherwise, the return value is false. More info on the label is in the input file format.
Note: You can use a different method signature if you need to, or define a separate method for adding each child (i.e. addNodeLeft, addNodeMiddle, addNodeRight).
public TreeNode getNodeReference(String label)
Returns a reference to the TreeNode that has the given label. The return value is null if the label is not found. This may be helpful to implement the above method. Efficiency is not important and you can use any traversal order you wish. Also, if you are more comfortable with placing this method in the TreeNode class, that is perfectly acceptable.
public void preOrder()
Traverses the tree in preorder, and prints the contents of the tree to the screen.
Note: This method can also be in the TreeNode class.
public void beginSession()
This method will be used to start the question and answer session.
Note: You may include additional instance variables or methods as needed.

3. Write a fully-documented class named TreeDriver which contains the main() method and it should display a menu:
L (Load input file and build a tree)
Prompt the user for a file name and build a new tree. The entire tree will be recreated each time this menu option is chosen.
H (Start help session)
This option will begin asking questions starting from the root of the tree; if there is no tree set up, display an error message. When displaying a question with answers, display each answer on a separate line with a number associated with it, similar to a menu. Include another option, 0 (zero) to exit the help session and return to the main menu. For example:
What is the Model of the Washing Machine?
1) WM200
2) WM300
3) WM400
0) Exit Session.

If the node is a leaf, then display the message and go back to the main menu. For example:
You have to put in quarters to start the Washing Machine.
Thank you for using our automated help system.
(Menu...)
T (Traverse the tree in pre-order)
Traverse the tree in pre-order and display the label, prompt, and message in each node on a separate line (see sample input/output).
The order is root, left subtree, middle subtree, right subtree.
Q (Quit)
Quit the program.

INPUT FORMAT
All strings in the input file will be no longer than 60 characters so that they will not take up more than one line.
Blank lines in the input file are to be ignored.
The length of the filename will not be longer than 20 characters.
OUTPUT FORMAT
Be sure your prompts and error messages for the user are clear and understandable.
Be sure to have a menu after each operation.
INPUT FILE FORMAT

Since this program is designed to be a versatile decision-making system based on user input, we will be using input files so that anyone with a tree of questions/answers can use this program, including but not limited to Tech Support. It is strongly recommended that you post any sample text files you create in the Blackboard discussion board so that others can test their code. The input file will always start with "root" on the first line. Look at the input file comments and ask any questions you may have on the discussion board.
The format of the input file is as follows:
label, prompt, and message for the root node (on three separate lines)
label1
label, prompt, and message for the first child of label1 (on three separate lines)
label, prompt, and message for the second child of label1 (on three separate lines)
.....
label2
label, prompt, and message for the first child of label2 (on three separate lines)
label, prompt, and message for the second child of label2 (on three separate lines)
.....
label3
label, prompt, and message for the first child of label3 (on three separate lines)
label, prompt, and message for the second child of label3 (on three separate lines)
.....

Label is a one-word string with no spaces that is used during the creation of a tree. It determines the location of a node in the tree. A picture of a tree with only their labels is shown below. Note that labels do not have to be in any specific format, and they will not necessarily be made of numbers and dashes.
Prompt is a string that will be printed to the screen as a choice or answer.
(NOTE: The prompt for the root node should not be printed to the screen. Look at the example text file input.)
Message is a string that will be displayed to the screen as either question or if the node is a leaf node, as a final message.
All strings (label, prompt, message) in the input file will be no longer than 60 characters so that they will not take up more than one line.
Another possible line in the input file is the name of a previously defined label followed by a number, separated by at least one space. This number will indicate the number of children this node has. The child nodes will then be directly after this line.
Any blank lines in the input file are to be ignored. They will help the creator of the input file for readability purposes.
If at any point during the reading in of the text file, you encounter an error in the format, you may stop reading in the text file then report a message to the user.
For the normal assignment, a node can have 0, 1, 2, or 3 children. For EXTRA CREDIT, be ready to handle 0 through nine children.
A sample input text file: Sample text file with comments , Sample text file without comments (this is the file that must be used to test your program).
The visualization of the text file is the second tree below.
For simplicity, we will not include comments in our test cases.

Extra Credit
Handle any number of child leaves. Note that since we may want this to be used in a telephone service, there will be anywhere from zero to nine children for any given node. 2 extra points.
Display an option to go backwards in the tree (e.g. go back to previous menu). The option should be 'B'. 2 extra points.
If you can come up with a creative idea regarding this programming assignment, then in your comments in the beginning of the driver class, write a brief description of what special functions your program does. The grade is determined per TA judgment. Up to 4 extra points.
SAMPLE INPUT/OUTPUT
As usual, comments in green, user input in black, and computer output in blue.

L - Load a Tree.
H - Begin a Help Session.
T - Traverse the Tree in preorder.
Q - Quit
Choice> L

Enter the file name> exampleText.txt

Tree created successfully!

L - Load a Tree.
H - Begin a Help Session.
T - Traverse the Tree in preorder.
Q - Quit
Choice> H

Help Session Starting...
What Model is the Washing Machine?
1 WM200
2 WM300
3 WM400
0 Exit Session.
Choice> 1

What is the problem?
1 No Water.
2 Water too hot.
3 Water too cold.
0 Exit Session.
Choice> 1

Is the hose attached?
1 Yes, but the hose is broken.
2 No, didn't know there was a hose.
3 Yes, but still no water.
0 Exit Session.
Choice> 3

Make sure the water valve is turned on.

Thank you for using this automated help service!


L - Load a Tree.
H - Begin a Help Session.
T - Traverse the Tree in preorder.
Q - Quit
Choice> H

Help Session Starting...
What Model is the Washing Machine?
1 WM200
2 WM300
3 WM400
0 Exit Session.
Choice> 2

What is the problem?
1 Machine won't start.
2 Machine ends too early.
3 Machine knobs are broken.
0 Exit Session.
Choice> 1

Is the machine plugged in?
1 Yes, but an error is displayed
2 I didn't know there was a plug.
3 Yes, but still won't turn on.
0 Exit Session.
Choice> 2

Try plugging it in the back.

Thank you for using this automated help service!


L - Load a Tree.
H - Begin a Help Session.
T - Traverse the Tree in preorder.
Q - Quit
Choice> T

Traversing the tree in preorder: // Visits root, left, middle, then right nodes.
Label: root
Prompt: Root Node
Message: What Model is the Washing Machine?

Label: 1
Prompt: WM200
Message: What is the problem?

Label: 1-1
Prompt: No Water.
Message: Is the hose attached?

Label: 1-1-1
Prompt: Yes, but the hose is broken.
Message: Purchase a new hose.

Label: 1-1-2
Prompt: No, didnít know there was a hose.
Message; Plug it in the back.

Label: 1-1-3
Prompt: Yes, but still no water.
Message: Make sure the water valve is turned on.

Label: 1-2
Prompt: Water too hot.
Message: Turn the temperature knob to warm.

Label: 1-3
Prompt: Water too cold.
Message: Turn the temperature knob to warm.

Label: 2
Prompt: WM300
Message: What is the problem?

Label: 2-1
Prompt: Machine wonít start..
Message: Is the machine plugged in?

Label: 2-1-1
Prompt: Yes, but an error is displayed, ìFuser out.î
Message: Weíll send someone over.

Label: 2-1-2
Prompt: I didnít know there was a plug.
Message: Try plugging it in the back.

Label: 2-1-3
Prompt: Yes, but still wonít turn on.
Message: Call an Electrician.

Label: 2-2
Prompt: Machine ends too early.
Message: Turn the timer knob.

Label: 2-3:
Prompt: Machine knobs are broken.
Message: Weíll send someone over.

Label: 3
Prompt: WM400
Message: What is the problem?

Label: 3-1
Prompt: My clothes are wet.
Message: Great! Now purchase a dryer.

Label 3-2
Prompt: Lid wonít close.
Message: Call a repair man to fix it.


L - Load a Tree.
H - Begin a Help Session.
T - Traverse the Tree in preorder.
Q - Quit
Choice> Q

Thank you for using our automated help services!
// Program terminated normally...

Course Info | Schedule | Sections | Announcements | Homework | Exams | Help/FAQ | Grades | HOME

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图