Write a program that prompts the user to select a shape to be drawn on the scree
ID: 3603899 • Letter: W
Question
Write a program that prompts the user to select a shape to be drawn on the screen.
Objects: pyramid, hexagon, diamond, pentagon
Depending on the user’s choice from a Menu (Create a method to ask the user input), you will then ask for a number of rows or any requirements needed to draw the shape.
No main method only the shape class
Finally, you will display the shape selected by the user to the screen
Your project will need to loop for as long as the user wants (you pick your choice of a loop) for example, the user has the option to draw more than one object.
Every shape should be implemented in a function (your choice how).
Make sure no wrong input by the user is allowed.
Use the asterisk character to draw the shapes.
*****************************************************
Every time a user creates a shape the output needs to be written to a file.
Create an enumeration (enum) for the Menu method.
Create an Array of object (Shapes) to stores the objects created by the user. Remember to make the array large so that you don't have to run out of space.
Submit the UML diagram and Java files
Explanation / Answer
Partially completed Direction ENUM
*/
package edu.cuny.csi.csc330.lab5;
import edu.cuny.csi.csc330.lib.Randomizer;
public enum Direction {
NONE, NORTH, EAST, SOUTH, WEST ;
// !!! Add 4 more Direction Values - NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST
// methods
public Direction getFavorite() {
return SOUTH; // It's getting cold! ...
}
public Direction getNextRandom() {
Randomizer randomizer = new Randomizer();
/******************************
* !!!!!
* WHAT CHANGES NEED TO BE MADE HERE SO THAT THE 4 NEW RANDOM DIRECTIONS ARE CONSIDERED
*/
int direction = randomizer.generateInt(1, 4);
// 1 = south, 2 = west, 3 = north, 4 = east
if(direction == 1) { // south
return SOUTH;
}
else if(direction == 2) { // west
return WEST;
}
else if(direction == 3) { // north
return NORTH;
}
else { // east
return EAST;
}
}
public static void main(String [] args) {
int c = 0;
while(c++ < 100) {
System.out.println(Direction.NONE.getNextRandom() );
}
}
}
/
/
/
/
Drunk Walker
/
/
/
/
/
/
package edu.cuny.csi.csc330.lab5;
import java.math.*;
import java.util.*;
public class DrunkWalker {
private Intersection startIntersection;
private Intersection currentIntersection;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// add other data members here including Collection instances that you will use to
// to track history and statistics ...
private DrunkWalker() {
init();
}
/**
*
* @param avenue
* @param street
*/
public DrunkWalker(int avenue, int street) {
init();
}
private void init() {
// What should be do here to initialize an instance??
}
/**
* step in a random direction
*/
public void step() {
takeAStep();
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!
* Now, update the Collections that manage the following:
*
* 1) add this next step/intersection to a "history" List that will contain the sequence of all
* steps taken by this DrunkWalker instance
*
* 2) add this next step to a Intersection -> Counter Map ... The Map
* Collection can and should be of Generics "Type" <Intersection, Integer>
* key = Intersection
* value = Count Value
* Need to do something like this:
* if intersection is not saved in Map yet as a key yet, add a key->value pair of Intersection->1
* else if intersection value is there, the existing key->value pair need to be replaced as
* Intersection->existing_count+1
*
*/
}
private void takeAStep() {
Direction dir = Direction.NONE.getNextRandom();
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* now what do we do based on the random Direction created?
* How do we go about updating the "currentIntersection" instance to reflect the
* direction/step that was just selected?
*/
}
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* toString()
* @return
*/
/**
* generate string that contains current intersection/location info
*/
public String getLocation() {
// !!!!!!!!!!!!!!!!!
/**
return String.format("Current location: DrunkWalker [avenue=%d, street=%d]",
currentIntersection.getAvenue(), currentIntersection.getStreet() );
*/
return null;
}
/**
* Take N number of steps
* @param steps
*/
public void fastForward(int steps ) {
// Considering that we already have a step() method, how would we
// implement this method? Uhh, think reuse!
}
/**
* Display information about this current walker instance
*/
public void displayWalkDetails() {
/**
* This method needs to display the following information in a neat, readable format
* using calls to System.out.println() or System.out.printf()
*
* 1 - starting location
* 2 - current/ending location
* 3 - distance (value returned by howFar() )
* 4 - number of steps taken - which collection would be able to provide that information, and how?
* 5 - number of unique intersections visited -
* which collection would be able to provide that information, and how?
* 6 - Intersections visited more than once
*
*/
}
/**
* X Y Coordinate distance formula
* |x1 - x2| + |y1 - y2|
* @return
*/
public int howFar() {
/** |x1 - x2| + |y1 - y2|.
startAvenue = x1
avenue = x2
startStreet = y1
street = y2
return (Math.abs(startAvenue - avenue) ) + (Math.abs(startStreet - street));
*
*/
return 0;
}
public static void main(String[] args) {
// create Drunkard with initial position (ave,str)
DrunkWalker billy = new DrunkWalker(6,23);
for(int i = 1 ; i <= 3 ; ++i ) {
billy.step();
System.out.printf("billy's location after %d steps: %s ",
i, billy.getLocation() );
}
// get his current location
String location = billy.getLocation();
// get distance from start
int distance = billy.howFar();
System.out.println("Current location after fastForward(): " + location);
System.out.println("That's " + distance + " blocks from start.");
// have him move 25 random intersections
billy.fastForward(25);
billy.displayWalkDetails();
}