Last weeks college java programming question I did not understand how to do

Posted on 2003-11-09
Last Modified: 2008-02-26
This is an old question and I have already taken a 0 for my score on it, but I'd still like to know how it is done, It is puzzling me. Any help would be appreciated. It goes like this:

Rewrite the following code

1 // Fig. 9.5: PointTest.cs
2 // Testing class Point.
4 using System;
5 using System.Windows.Forms;
7 // PointTest class definition
8 class PointTest
9 {
10 // main entry point for application
11 static void Main( string[] args )
12 {
13 // instantiate Point object
14 Point point = new Point( 72, 115 );
16 // display point coordinates via X and Y properties
17 string output = "X coordinate is " + point.X +
18 "\n" + "Y coordinate is " + point.Y;
20 point.X = 10; // set x-coordinate via X property
21 point.Y = 10; // set y-coordinate via Y property
23 // display new point value
24 output += "\n\nThe new location of point is " + point;
26 MessageBox.Show( output, "Demonstrating Class Point" );
28 } // end method Main
30 } // end class PointTest

To complete this exercise, rewrite the case study of Section 9.5 as a Point-Square-Cube hierarchy with inheritacne. In other word, which class should be parent or superclass and which should be not?
Use the Shape abstract class (see below) as top level parent. The Shape class capture two common behaviors such as computing an area and volume. Each child class must override these two methods to provide its own verion of the area and volume. For example, the formula for computing the area of the point is quite different from square. In addition, each child class must provide a concrete implementation of the getName() method.
public abstract class InheritanceShape {
// no constructor is needed because this class is abstract
public double area() {
return 0.0;
public double volume() {
return 0.0;
// in order for subclasses to be concrete, they will have
// to define getName()
public abstract String getName();
} // end class InheritanceShape
The output should look similar to:

Question by:johnnys123
LVL 15

Expert Comment

ID: 9713946
If you've already taken a 0 for the assignment, you would be better to ask your tutor for the model solution and clarify your questions with them one-to-one.

At least it will show you were interested in the question.  If you don't ask your tutor, it's going to look like you can't be bothered (which won't stand you in good stead for future assignments).

Expert Comment

ID: 9724499
You posted a C# source code and you tell something about a Java course.
Try using a java.awt.Point instead of a Windows.System.Forms.Point

import java.awt.*;
replace all string by String
replace all .X by .x and .Y by .y
Don't know a synonym for Messagebox.Show right now. You could try System.out.println()
Make the class and the Main-Method public

Point-square-cube hierarchy:
Inheritance is normally done by expansion, not by restiction. A cube is most complex, so it is neither parent of a point nor a square. Also, a square is more complex than a point and therefore should not be parent of point.
In my eyes, you can do it like

Point   Square    Cube

or like


Accepted Solution

g0rath earned 500 total points
ID: 9724631
sounds like a homework question reworded

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which programming language is best for beginning Object-oriented programming 11 149
sum28 challenge 31 115
WPF issue with Trigger 2 113
What language/protocol is the Angular Chat? 2 83
This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question