Write a java application that displays the triangle patterns

Assignment Help Computer Engineering
Reference no: EM131291795

Programming Assignment

START EARLY!

This programming assignment has two programs:

1) a Java application (Triangles) that displays alternating triangle patterns side-by-side on the console outputting individual '*' and ' ' (space) characters using nested while loops, and

2) a Java applet extending the Mickey program from PA2 to be more Object-Oriented and add some functionality.

README

START EARLY!

You are required to provide a text file named README, NOT Readme.txt, README.pdf, or README.docx, etc. with your assignment in your pa3 directory. There should be no file extension after the file name "README". Your README should include the following sections:

Program Description:

Explain how the user can run and interact with each program. What sort of inputs or events does it take and what are the expected outputs or results? How did you test your program? How well do you think your program was tested?

Write your README as if it was intended for a 5 year old or your grandmother. Do not assume your reader is a computer science major. The more detailed the explanation, the more points you will receive.

Short Response ( 7 points ) : Answer the following questions:

Vim related Questions:

1. How do you jump to a certain line number in your code with a single command in vim?

For example, how do you jump directly to line 20? (Not arrow keys)

2. What command sets auto-indentation in vim? What command turns off (unsets) auto-indentation in vim?

3. What is the command to undo changes in vim?

4. In vim, in command mode, how do you move forward one word in a line of code?

Move back one word? (Not arrow keys)

Unix/Linux related Questions:

5. How can you remove all .class files in a Unix directory with a single command?

6. How do you remove a Unix directory? Define the commands you would run on the terminal when the directory is empty and when it is not empty. How do these command(s) differ?

7. What is the command to clear a Unix terminal screen?

STYLE

Please see previous programming assignment for details on Coding Style.

CORRECTNESS ( 70 points, 35 points each program)

All of your code/files for this assignment need to be in a directory named pa3 in your cs11f home directory.

Please see previous programming assignments to setup your pa3 directory, compile, and run your programs.

Remember we run/execute applications differently than applets.

START EARLY!

Program 1 - Triangles:

Write a Java application (Triangles.java) that displays the following triangle patterns side-by-side using nested while loops. Everything can be in main().

- Use class Scanner to read input.
- Allow the user to input the number of rows defining the size of the side-by-side triangles.
No hardcoding or magic numbers in your code.
- Make sure your prompt and output messages match the sample prompt and messages word-for-word.
- Each loop must be based on the current row number/iteration of the outer-most loop.
- Hint: Treat each of the four triangle patterns as its own set of nested loops. Each row of each triangle pattern is made up of some number of individual '*' and ' ' (space) chars.
- Note there is a space character between adjacent triangles.

To get a better understanding, if size of the triangle is 5, here's the spacing (represented in a grid, for a clearer
picture of the individual '*' and ' ' characters).

* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *

- All asterisks ('*') and spaces (' ') must be printed a single character at a time using System.out.print( '*' ) or System.out.print( ' ' ) controlled by the nested while loops.

No Strings! You are not allowed to use a String or StringBuilder or StringBuffer or any data structure to build each line to be output.

- Formatting is important for this program. If your output does not match the required output character-for-character, no credit will be awarded. Note there is no space at the end of each line.

- Only valid integers will be entered, but you must check for integers less than 2 and report the exact error message as shown in the example below.

Example Executions (user input in BOLD):

Program 2 - Mickey:

This program will build off of your last Mickey program, so you should make sure that program is working correctly first. Being more Object-Oriented, we will separate the GUI controller and the Mickey object.

In this program you will be adding a feature that allows you to flip the Mickey left if the mouse is pressed on his left ear, flip right if the mouse is pressed on on his right ear, and flip upside-down if the mouse is pressed on his face all mouse presses must last for longer than 500 milliseconds (1/2 second) during a mouse click.

Once the Mickey is flipped upside-down, if the mouse presses the face in the Mickey for longer than 500 milliseconds during a mouse click, the Mickey should flip right-side up again. Even when Mickey is upsidedown, it could still be flipped either left or right by clicking on its ears. For flipping the Mickey either left or right, the flip should be centered on the ear that was clicked on. A long mouse press during a mouse click not in Mickey will not flip Mickey. Recall: a mouse click event is fired if there is a mouse press event followed by a mouse release event with no mouse movement between the press and release. A mouse press followed by moving the mouse one pixel and then a mouse release does not fire a mouse click event.

Notes: You should be able to drag mickey around despite however the figure was flipped. Also, even if part of the Mickey is off the canvas, you can still flip Mickey based on its parts that are still left on the canvas.

You will need four files for this program:

Mickey.html Timer.java
Mickey.java FlippingMickey.java
Mickey.html - change the applet tag's code attribute to be FlippingMickey.class

FlippingMickey.java - this is the main GUI controller class that handles all mouse events and controls what we see on the canvas. This class needs to extend WindowController. Methods defined in this class include: begin(), onMouseClick(), onMouseDrag(), onMousePress( ), onMouseRelease(), onMouseExit( ), onMouseEnter( ). Where appropriate, code in this class will create an instance of a Mickey and send messages to this Mickey object (tell the Mickey figure to flip, ask the Mickey figure to check if the current mouse Location is contained in the Mickey figure, tell the Mickey figure to move, tell the Mickey figure to remove itself from the canvas).

Mickey.java - this class defines what a Mickey figure is (the 3 filled ovals) and what a Mickey figure can do (what messages it can respond to). This class will define a constructor to initialize a new Mickey object placing it on the canvas as part of the FlippingMickey along with the methods to determine if the mouse pointer is contained in the Mickey figure, move the Mickey figure some delta, remove the Mickey figure from the canvas, and flip the Mickey figure.

Timer.java - this class calculates timing between events. Just copy the code on page 168 of the textbook for the class Timer.

It is important to note the difference between the FlippingMickey class and the Mickey class. The Mickey class should have all the relevant variables and methods specific to each Mickey created on the canvas (in this case we only create one at a time). The GUI controller class, FlippingMickey, handles all the activities that occur on the canvas - this includes the mouse interactions/events with the canvas and Mickey object on the canvas.

Since both classes interact with each other, the FlippingMickey (GUI) needs to have a reference to a Mickey object and the Mickey object needs a reference to the GUI canvas in the FlippingMickey. This is done by passing the canvas as an actual argument to the Mickey constructor when the code in onMouseClick() in FlippingMickey creates a Mickey object. Examples in Chapter 6 of the textbook show how to do this.

Specifications:

The program should still have same functionality as was specified in PA2 (able to create a Mickey on the canvas and drag it around).

A skeleton example of FlippingMickey.java:

import objectdraw.*;

public class FlippingMickey extends WindowController
{
private Text instr1, instr2, instr3;
private static final int INSTR1_X = 50;
private static final int INSTR1_Y = 50;
private static final int INSTR2_X = INSTR1_X;
private static final int INSTR2_Y = INSTR1_Y + 20;
private static final int INSTR3_X = INSTR1_X;
private static final int INSTR3_Y = INSTR2_Y + 20;

private static final int FLIP_PRESS_THRESHOLD = 500; // Half a second
private Timer timer;

...

// additional variables you might need and begin() and the event handling methods
}
A skeleton example of Mickey.java:

import objectdraw.*;

public class Mickey
{
private FilledOval leftEar, rightEar, face;
private static final int FACE_RADIUS = 50;
private static final int EAR_RADIUS = 30;
private static final int EAR_OFFSET = 50; // Center of each ear is this
// offset up and over (x and y)
// from center of face.
private DrawingCanvas canvas;

...

// additional variables you might need and ...

public Mickey( Location point, DrawingCanvas canvas ) // ctor

public boolean contains( Location point ) {}

public boolean inFace( Location point ) {}

public boolean inLeftEar( Location point ) {}

public boolean inRightEar( Location point ) {}

public void move( double dx, double dy ) {}

public void removeFromCanvas() {}

public void flipLeft() {}

public void flipRight() {}

public void flipUpDown() {}

}

Use calls to the Timer class methods in FlippingMickey to determine how long the mouse button was pressed:

- Create a Timer object in begin()

- When the mouse is pressed, the timer should reset (start the timer).

- When the mouse is released, get the elapsed time in milliseconds and if the mouse was on the Mickey (grabbed) and the elapsed time was longer than ½ second (500 milliseconds) then flag that the Mickey figure should be flipped if this was indeed a mouse click (vs. a drag).

- In mouse click event handler send the flip message to the Mickey object if it should be flipped. Note the mouse click event will be fired after a mouse press event and mouse release event with no mouse motion between the press and release.

- The Mickey should not flip if the mouse is dragged or if the mouse press/click is not on the Mickey.

- When the mouse is clicked, if the mouse was pressed for enough time (1/2 second), the Mickey should flip upside-down or right-side up. Otherwise the Mickey does not change.

- You should use the following constant to compare with the elapsed time Mickey was pressed:

private static final int FLIP_PRESS_THRESHOLD = 500; // Half a second

The starting text/instructions of your program should be adjusted to look like the following (and should disappear when a Mickey is placed, just like in your last assignment).

Reference no: EM131291795

Questions Cloud

Calculate ordinary gain when it is sold during third year : A drill press with a cost basis of $55,000 is a 7-year MACRS property. Calculate ordinary gain when it is sold during the third year for $35,000. Round to the nearest integer.
Calculate ordinary gain when it is sold during third year : A drill press with a cost basis of $55,000 is a 7-year MACRS property. Calculate ordinary gain when it is sold during the third year for $35,000. Round to the nearest integer.
Compute the depreciation charges at year two : A depreciable asset costs $20,000 and has an estimated salvage value of $4,500 at the end of its 5-year depreciable life. Use DB depreciation with depreciation rate 1.5 to compute the depreciation charges at year 2.
What is the turnaround time of each process : What is the turnaround time of each process for each of the scheduling algorithms in part and what is the waiting time of each process for each of these schedul-ing algorithms?
Write a java application that displays the triangle patterns : Write a Java application (Triangles.java) that displays the following triangle patterns side-by-side using nested while loops. Everything can be in main().
Discuss about the motivations of altruistic behavior : Justify the use of elements by connecting them to various motivations of altruistic behavior as identified in social exchange theory.
Compare and/or contrast your responses : encourage further dialogue and discussion,encourage your classmate to think about other aspects of the topic,ask a relevant, meaningful question to better assist with your understanding,compare and/or contrast your responses
Mission or values statement : Which of the following exist in an organization where you've worked: mission or values statement, policy manual, code of conduct, ethics training (who conducts it), hotline? Were they consistent and credible?
What kinds of ethical dilemmas are unique to organization : Think about an organization where you've worked. What kinds of ethical dilemmas are unique to that organization? To that industry? What might be the best way to prepare employees to deal with those dilemmas?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Define the process of database normalization

Explain the method of database normalization. Why does it occur and how is data "cleaned up" as it moves through forms 1NF, 2NF, and 3NF? When would data need to be placed in 4NF or BCNF?

  How many hour work each week to pay for gas to fuel the car

As a part time student and a part time worker, you earn $4.50 an hour. Your parents would buy you a used car, but you must pay for the gas. gas costs $1.10/gallon and you use 20 gallons/week. How many hours will you work each week to pay for the g..

  Explain the synthesis of guar gum

Explain the synthesis of guar gum - Explain the life cycle and environmental impact of guar gum

  What devices use to get efficient network communication

CNT Books has expanded considerably as you first got network up and running three years ago. It at the present occupies an entire floor in building, and its LAN has full-grown to contain several servers and more than 60 workstations.

  1 write a script to help users calculate compressed file

1. write a script to help users calculate compressed file size. prompt the user to enter the original size of a file

  Questionfor this module you will require to complete

questionfor this module you will require to complete following tasks. this section will be additional to the end of

  What are the differences between a pre-test loop a

wrtie 200-300 woods on this questionwhat are the differences between a pre-test loop a post-test loop and a for

  Find out the min-term of the circuit

find out the min-term of the circuit - Find the min-term expansions for X, Y, and Z (i.e. the Standard SOP expression for each). Put your final answer in short-hand notation (e.g. Sum of minterms(1, 4, 6)).

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Analyze all e-mail messages found in the pst file

Use FTK to analyze all e-mail messages found in the pst file. Find correspondence that supports the company's suspicions. The company wants a solid case, so showing the information was exchanged is important

  Find minimal cover and identify all possible candidate keys

Find minimal cover and identify all possible candidate keys - Functional Dependencies

  Discuss the subsequent questions relative to compilersa

discuss the subsequent questions relative to compilersa. which phase of a compiler could give you a syntax error? b.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd