Class to create and draw five squares

Assignment Help Programming Languages
Reference no: EM1348062

Q1) Write a class Square that represents a square to be drawn. Store the following information in instance variables:

size (length of any side)
x coord of upper left-hand corner
y coord of upper left-hand corner
color

Provide the following methods:

A parameterless constructor that generates random values for the size, color, x, and y. Make the size between 100 and 200, x between 0 and 600, y between 0 and 400. The squares can be any color-note that you can pass a single int parameter to the Color constructor, but it will only consider the first 24 bits (8 bits for each of R, G, B component).

IMPORTANT: Your random number generator must be declared at the class level (not inside the constructor), and must be declared static. So its declaration and initialization should appear with the declarations of size, color, x, and y, and should look like this:

private static Random generator = new Random();

A draw method that draws the square at its x,y coordinate in its color. Note that you need a Graphics object, like the page parameter of the paint method, to draw.Your draw method should take a Graphics object as a parameter.

2. Now write applet DrawSquares that uses your Square class to design and draw 5 squares. This code must be very simple; the paint method will simply create a Square and then draw it, repeated 5 times. Don't forget to pass the Graphics object to draw.

Reference no: EM1348062

Questions Cloud

Cost allocation-master budgeting-capital decisions : There're four primary techniques of examining capital decisions - two are discounting techniques and two aren't. Please pick one of them, describe the method and the pros and cons.
Loss of generality in private-key encryption : Prove that, in the context of private-key encryption, we can assume without loss of generality that keys are chosen uniformly at random (and so Gen is trivial).
Cost considerations-operating effectiveness : Auditors should decide, based upon cost considerations, whether to test the design effectiveness or operating effectiveness of controls. Inquiry alone provides sufficient evidence to support operating effectiveness of a control.
Understanding practical business-organizational research : Selecting an article that either deals with Measuring Performance or Incremental Analysis write down an introduction to the article. Include the following sections and include no opinions, judgments, or beliefs about the study. Only present the fa..
Class to create and draw five squares : Now write applet DrawSquares that uses your Square class to design and draw 5 squares. This code must be very simple.
Creative strategy pick an animal : Creative strategy Pick an animal. Any animal. a) Now think of 5 products that could utilized that animal in their ad campaigns and
Estimate the stocks current market value : Nachman just paid a dividend of $1.32. Analysts expect firm dividend to increase by 30 percent this year, by 10 percent in Year second, and at a constant rate of 5% in Year 3 and thereafter.
Explain why paul collier seems industrialization or trade : Explain why Paul Collier seems to argue that export oriented industrialization or trade liberalization policies enacted by African countries would not help Africa develop.
Income statement-balance sheet of purchases : Make an income statement for Packer, Inc. for 2013, and the balance sheet as of December 31, 2013. Case study is given below:

Reviews

Write a Review

Programming Languages Questions & Answers

  Statement to read variables of type double

Suppose two variables p1 and p2 of type POINT, with two fields, x and y, both of type double, have been declared. Write a statement that reads values for p1 and p2 in that order.

  Creating table-find employee attended meeting on given date

The rows of this table record the fact that an employee from a particular project attended a meeting on the given date.

  Explaining handles clause of sub procedure

You are asked to design a form with a textbox named txtQty, a label named lblStatus, and a button named btnGetStatus. What will be Handles clause at the end of sub procedure?

  Solve the programming problem

Solve the programming problem

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Programming problem

Programming Problem can be solved by a program that performs three basic tasks-Input Data, Process Data, and Output Results.

  Program to display weekly payroll report

Write down a program to display a weekly payroll report.

  C program to accept three numbers inputs by user

Write down C program to accept three numbers input by a user, and outputs a table of temperatures in Fahrenheit, Celsius, and Kelvin.

  Designing system to handle donations of non-profit agency

You have been hired by worldwide non-profit agency to create a system to handle their donations.

  Use of various bash commands

Assignment On: This work will require scripting the use of various bash commands and / or small programs that involve directory and file structures.

  Describe purpose of keyword super in programs

Describe purpose of keyword 'super' in programs

  Creating application to test class rectangle

Write down application to test class Rectangle.

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