首页 > > 详细

program辅导、java程序设计辅导

Introduction
In this assignment, you will extend Assignment 1 to add more features for the Digital Kinder Kit
program to simulate a part of the Kinder Kits. Kinder kits were given to 3-year-old children in Victoria,
Australia to stimulate their learning (https://www.vic.gov.au/early-childhood-update-october2022/kinder-kits-are-back-2023).
Speci cally, in this assignment you will build a program in which users can draw, zoom, move, and
rotate triangles on a drawing canvas to build di erent objects (e.g., kites).
The algorithm is quite similar if you want to support other basic shapes like rectangles and squares. However,
to do that properly, you would rst need to learn and understand the concept of inheritance & polymorphism
(Week 8). Due to that reason, in this assignment only triangles are in use.
Users can do freestyle drawing (in the "freestyle mode") or try to draw a prede ned object (in the
"challenge mode"). This assignment is designed in such a way that we can evaluate your knowledge
on the following topics: 1) more advanced class design and implementation, 2) arrays and ArrayList,
3) control ow structures (e.g., if-then-else, loops, nested loops), and 4) basic I/O (e.g., Scanner class,
formatted printing).
Your Task
You are given a sca old including four classes: KinderKit, DrawingTask, DrawingCanvas, and Triangle.
KinderKit.java will be the main application containing your main() method. These .java les are almost
empty---except for the KinderKit.java---and you are asked to add constructors, instance variables,
and methods to complete the program. See the application walk-through to understand the required
features of the program.
Regarding the newly introduced class named DrawingTask, you can use this class to encapsulate the
common methods and properties for the two drawing modes namely the challenge mode and
freestyle mode and also implement mode-speci c methods. For instance, in the challenge mode, you
can store the information of the prede ned object/drawing along with the user drawing and then
compare them. You are not strictly required to use/implement this class to complete the assignment but
you are advised to do so to improve the modularity of your code.
For this assignment, all user inputs will be assumed to be the correct data types; such that if a String is
expected then it is assumed a string will be entered, and the same for an integer. No error control for
incorrectly entered data types are required... as of yet! .
Application Walk-Through
pyramid.txt
For this assignment, all user inputs will be assumed to be of the correct data types; such that if a String is
expected then it is assumed a string will be entered, and the same for an integer number. No error control for
incorrectly entered data types are required... as of yet! .
All menu options are case insensitive, unless stated otherwise.
As happening in the real-world software development scenarios, the given spec might be incomplete or
inconsistent. You should play the role of a software engineer to collect precise requirements from your
"customers". So, please read the spec carefully and talk to your tutors/lecturers if you have any questions. You
are encouraged to post your questions to the Ed discussion board so everyone can be involved and learn
from that.
1. Your program must take only one argument which will be used to load a prede ned object from
le. We already provide the le processing code in the sca old so no worries if you do not know how
to handle le I/O yet. Following is a sample command to run the KinderKit application with a
prede ned shape (e.g., a pyramid) stored in a le named pyramid.txt.
java KinderKit pyramid.txt
This is the content of the pyramid.txt le. It follows a speci c format. The le consists of several lines
and in each line the data is separated by commas. The rst line stores the canvas information.
Speci cally, it stores the number of rows (which is 4 in this example), number of columns (which is 8
in this example), and the background character (which is '-' in this example).
4,8,-
-,-,-,-,-,-,-,-
-,-,-,*,#,-,-,-
-,-,*,*,#,#,-,-
-,-,-,-,-,-,-,-
If the le is loaded successfully and its format is correct, your program will show the main menu
----DIGITAL KINDER KIT: LET'S PLAY & LEARN----
Please select an option. Type 3 to exit.
1. Draw a predefined object
2. Freestyle Drawing
3. Exit
Using this menu, basically users can draw in two modes called "Challenge Mode" and "Freestyle
Mode". In the challenge mode, users can draw a prede ned object as loaded from the given input le.
In the freestyle mode, they can draw whatever they want. To exit, they just need to type 3 and then
press Enter.
Similar to the Assignment 1, if the user provides an unsupported option, an error message should be
displayed.
----DIGITAL KINDER KIT: LET'S PLAY & LEARN----
Please select an option. Type 3 to exit.
1. Draw a predefined object
2. Freestyle Drawing
3. Exit
4
Unsupported option. Please try again!
Please select an option. Type 3 to exit.
1. Draw a predefined object
2. Freestyle Drawing
3. Exit
This error handling approach & error message apply to all menus that take numerical inputs.
2. If the user selects the rst option from the main menu to draw a prede ned object, a sub-menu for
the challenge mode will be displayed.
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
In this menu, the user can (1) preview the sample drawing (as loaded from the given input le), (2)
start/edit their current drawing canvas, (3) compare their drawing with the sample one, and (4) go
back to the main menu.
When the user goes back to the main menu, their current drawing will be removed. Next time they choose to
either draw a prede ned object or do freestyle drawing, a new canvas should be created.
If the user chooses option 1 in this sub-menu, they can preview the sample drawing. Following is a
sample output
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
1
This is your task. Just try to draw the same object. Enjoy!
--------
---*#---
--**##--
--------
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
If the user chooses option 2, they can start drawing or edit their existing canvas. This feature works
similarly in both two drawing modes (i.e., challenge mode vs freestyle mode). Please see step 4 below
for more details. The di erence is that in the freestyle drawing mode (step 3), the user needs to set up
their drawing canvas. However, in the challenge mode, a clean canvas is set up for the user based on
the given input le. The user drawing canvas is of the same size with the sample drawing; they should
also use the same background character.
3. If the user selects the second option from the main menu to do freestyle drawing, the program will
ask for their canvas settings rst.
Please select an option. Type 3 to exit.
1. Draw a predefined object
2. Freestyle Drawing
3. Exit
2
Canvas width: 8
Canvas height: 4
Background character: -
Please select an option. Type 3 to go back to the main menu.
1. Start/edit your current canvas
2. Share your current drawing
3. Go back to the main menu
When the user goes back to the main menu, their current drawing will be removed. Next time they choose to
either draw a prede ned object or do freestyle drawing, a new canvas should be created.
4. In both two mode, users can start drawing/editing their current canvas. First, the current canvas
should be displayed. In the following example, this is a clean canvas. However, it could have triangles
on it if the user would choose to edit an existing canvas.
--------
--------
--------
--------
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
In this sub-menu, the user has options to (1) add a new triangle, (2) edit an existing triangle, and (3)
remove one from the canvas. If the rst option is chosen, the user can provide information of the
triangle to be added (e.g., its side length and printing character). Once a triangle is added, the user can
transform it similarly to what was implemented in the Assignment 1. In this assignment, one more
transformation is supported which is rotation. Your program should support both clockwise and
anti-clockwise rotations of 90 degree each.
The rotation algorithm is quite simple as demonstrated below. Pressing the R key is to do a 90-degree
clockwise rotation and pressing the L key to do a 90-degree anti-clockwise rotation.
**** **** ---* *--- ****
***- ->R-> -*** ->R-> --** ->R-> **-- ->R->. ***-
**-- <-L<- --** <-L<- -*** <-L<- ***- <-L<- **--
*--- ---* **** **** *---
1
Side length:
2
Printing character:
*
**------
*-------
--------
--------
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
5. Following is a sample usage in which a user tries to draw a pyramid shape after creating one
triangle in the previous step.
5.1. First, they move the triangle to a new location and then rotate it several times.
**------
*-------
--------
--------
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
m
**------
*-------
--------
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menuw
You cannot move this triangle outside of the drawing canvas!
**------
*-------
--------
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menus
-**-----
-*------
--------
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menu
s
--**----
--*-----
--------
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menu
z
--------
--**----
--*-----
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menu
k
--------
--**----
--*-----
--------
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
r
--------
--**----
--*-----
--------
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating mr
--------
--**----
---*----
--------
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating mr
--------
---*----
--**----
--------
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating m5.2. And then they try to draw a new triangle and move it close to the existing one before going back
to the previous menu.
When there are multiple triangles on the canvas and there are overlaps between them, the later shape will be
displayed on top of others. As shown in this sample output, the second triangle is displayed on top of the rst
one.
--------
---*----
--**----
--------
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating mk
--------
---*----
--**----
--------
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
k
--------
---*----
--**----
--------
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
1
Side length:
3
Printing character:
#
###-----
##-*----
#-**----
--------
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
m
###-----
##-*----
#-**----
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menus
-###----
-##*----
-#**----
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menus
--###---
--##----
--#*----
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menus
---###--
---##---
--*#----
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menus
----###-
---*##--
--**#---
--------
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menu
z
--------
---*###-
--**##--
----#---
Type A/S/W/Z to move left/right/up/down. Use other keys to go back to the Zooming/Moving/Rotating menu
k
--------
---*###-
--**##--
----#---
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
r
--------
---*###-
--**##--
----#---
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating ml
--------
---*#---
--**##--
----###-
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating ml
--------
---*--#-
--**-##-
----###-
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating ml
--------
---*###-
--**-##-
------#-
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating ml
--------
---*###-
--**##--
----#---
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating ml
--------
---*#---
--**##--
----###-
Type R/L to rotate clockwise/anti-clockwise. Use other keys to go back to the Zooming/Moving/Rotating mk
--------
---*#---
--**##--
----###-
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
k
--------
---*#---
--**##--
----###-
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
5.3. At this time, they may gure out that the second triangle need some changes because it looks
bigger than the rst one. To do that, they choose the second option from the current menu ("Edit a
triangle"). The program will rst list all the triangles on the current canvas along with their indexes so
that the user can select the one they want to make modi cations. In this case, the user chooses to
edit the second triangle. Speci cally, they zoom out the triangle to make it smaller. Now, the canvas
looks identical to the prede ned object and the user can choose to check their result if they are in the
challenge mode. If they are in the freestyle mode, they might just want to share it with others and
challenge them to draw something similar ;) They can do so by printing the canvas info following the
format describe in Step 1. Please see Step 8 for more details.
Note that every triangle in this application is bounded by a square of the same side length. For instance, a
triangle that has a side length of 2 is bounded by a 2x2 square. Therefore, a triangle position (xPos, yPos) is
calculated based on the top-left coordinates of the bounding square on the canvas. xPos in the x-axis equals
to the square's column index, which starts from 0. And yPos in the y-axis equals to the square's row index,
which also starts from 0. Following is an example.
As a result, rotating a triangle does not change its position (i.e., xPos and yPos) because the rotations happen
inside the bounding square. Moreover, editing a shape does not change its order.
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
2
Shape #1 - Triangle: xPos = 2, yPos = 1, tChar = *
Shape #2 - Triangle: xPos = 4, yPos = 1, tChar = #
Index of the shape:
2
--------
---*#---
--**##--
----###-
Type Z/M/R for zooming/moving/rotating. Use other keys to quit the Zooming/Moving/Rotating mode.
z
--------
---*#---
--**##--
----###-
Type I/O to zoom in/out. Use other keys to go back to the Zooming/Moving/Rotating menu.
o
--------
---*#---
--**##--
--------
Type I/O to zoom in/out. Use other keys to go back to the Zooming/Moving/Rotating menu.
If the user tries to edit a shape on a clean canvas, an error message should be displayed. Following is a sample
output.
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
2
The current canvas is clean; there are no shapes to edit!
--------
--------
--------
--------
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
If the user tries to give a shape index that is larger than the number of shapes on the canvas, an error message
should also be displayed. Following is a sample output.
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
2
Shape #1 - Triangle: xPos = 2, yPos = 1, tChar = *
Shape #2 - Triangle: xPos = 4, yPos = 1, tChar = #
Index of the shape:
3
The shape index cannot be larger than the number of shapes!
--------
---*#---
--**##--
----###-
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
6. They can also remove a triangle from the canvas and the logic is quite similar to editing. The user
will need to provide the index of the triangle they want to delete. Once the operation is done, the
canvas is re-displayed and as we can see in the following sample output, the second triangle has been
removed.
--------
---*#---
--**##--
--------
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
3
Shape #1 - Triangle: xPos = 2, yPos = 1, tChar = *
Shape #2 - Triangle: xPos = 4, yPos = 1, tChar = #
Index of the shape to remove:
2
--------
---*----
--**----
--------
Please select an option. Type 4 to go back to the previous menu.
1. Add a new Triangle
2. Edit a triangle
3. Remove a triangle
4. Go back
Similar to the editing feature, error handling is required. If there is no shape on the canvas, the
program should display "The current canvas is clean; there are no shapes to remove!". If the given
index is larger than the number of shapes, the program should display "The shape index cannot be
larger than the number of shapes!".
7. In the challenge mode, if the user is happy with their drawing, they can check their result by
selecting the 3rd option from the menu.
The program should compare the canvases' content (i.e., the actual characters drawn on the canvases), not
the number of triangles and the properties of individual triangle. Two drawings are considered the same if
they look identical --- no matter how many triangles have been used to draw them.
This is sample output in case the user successfully completes the drawing task.
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
3
You successfully complete the drawing task. Congratulations!!
This is the sample drawing:
--------
---*#---
--**##--
--------
And this is your drawing:
--------
---*#---
--**##--
--------
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
And this is a sample output if the drawings (user drawing vs simple drawing) are di erent
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
3
Not quite! Please edit your canvas and check the result again.
This is the sample drawing:
--------
---**---
--****--
--------
And this is your drawing:
--------
---*#---
--**##--
----###-
Please select an option. Type 4 to go back to the main menu.
1. Preview the sample drawing
2. Start/edit the current canvas
3. Check result
4. Go back to the main menu
If the user chooses this option when their current canvas is clean, the program will produce the same error
message.
8. After completing a drawing in the freestyle mode, users can share it with others by printing the
canvas info following the format describe in Step 1. They can do so by choosing the 2nd option from
the menu.
Please select an option. Type 3 to go back to the main menu.
1. Start/edit your current canvas
2. Share your current drawing
3. Go back to the main menu
2
This is the detail of your current drawing
4,8,-
-,-,-,-,-,-,-,-
-,-,-,*,#,-,-,-
-,-,*,*,#,#,-,-
-,-,-,-,-,-,-,-
Please select an option. Type 3 to go back to the main menu.
1. Start/edit your current canvas
2. Share your current drawing
3. Go back to the main menu
This feature should work even if the current canvas is clean. In that case, the output looks like this
This is the detail of your current drawing
4,8,-
-,-,-,-,-,-,-,-
-,-,-,-,-,-,-,-
-,-,-,-,-,-,-,-
-,-,-,-,-,-,-,-
9. When the user chooses to exit the application, a goodbye message should be displayed, similar to
Assignment 1.
Please select an option. Type 3 to exit.
1. Draw a predefined object
2. Freestyle Drawing
3. Exit
3
Goodbye! We hope you had fun :)
Happy coding!

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!