Start early! | Computer Science homework help

Programming Assignment 3

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 ( 10 points )

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 ( 3 points ) :

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 ( 20 points )

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):

 

Example 1:

java Triangles

Enter the size of the triangles to display: 12

 

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

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

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

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

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

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

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

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

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

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

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

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

 

 

Example 2:

java Triangles

Enter the size of the triangles to display: -1

Triangle size must be > 1; Try again.

 

Enter the size of the triangles to display: 0

Triangle size must be > 1; Try again.

 

Enter the size of the triangles to display: 5

 

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

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

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

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

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

 

 

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): 

 

 

 

 

 

 

 

Custom Writings Help
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

})();