Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In your lab4 directory, create a program named Hyperbola.java This program uses the Graphics object in a DrawingPanel. In order to use the DrawingPanel you

In your lab4 directory, create a program named Hyperbola.java

This program uses the Graphics object in a DrawingPanel. In order to use the DrawingPanel you must download DrawingPanel.java. Save the DrawingPanel.java file to your lab4 directory.

To help get you started, the following code creates a DrawingPanel object and then accesses the Graphics object in order to call drawLine. The below only makes two calls to drawLine, which produces an "X" shape. You will need to replace these calls with one loop (or two) that can produce the hyperbola pictures.

import java.awt.*;

public class Hyperbola {

// The width and height of the DrawingPanel.

public static final int PANEL_SIZE = 444;

// Right now this draws an X, but should draw two hyperbolas.

public static void main(String[] args) {

DrawingPanel panel = new DrawingPanel(PANEL_SIZE, PANEL_SIZE);

Graphics g = panel.getGraphics();

g.drawLine(0, 0, PANEL_SIZE, PANEL_SIZE);

g.drawLine(0, PANEL_SIZE, PANEL_SIZE, 0);

}

}

Your hyperbola DrawingPanel should be 512 pixels wide and 512 pixels tall. The hyperbola in the lower left-hand corner has grid lines separated by 32 pixels, and the hyperbola in the upper right-hand corner has grid lines separated by 8 pixels.

drawLine from point (0, 0) to (0, 512) drawLine from point (0, 32) to (32, 512) drawLine from point (0, 64) to (64, 512) drawLine from point (0, 96) to (96, 512) drawLine from point (0, 128) to (128, 512)

But do not use those numbers directly (your code must use a loop). Use class constants for the size of the drawing panel, and for the 8- and 32-pixel intervals of the hyperbolas. You must pick clear names for the class constants.

Note that the sample code that draws an "X" uses a class constant for the size of the panel with the wrong value. See pages 106-108 of your text to find out how class constants can be used.

A properly implemented Hyperbola program shouldn't take more than 18-25 lines of code and one or two for loops.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Explain the two meanings that the term equality can have.

Answered: 1 week ago