Solved

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

Posted on 2003-11-09
3
348 Views
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.
3
4 using System;
5 using System.Windows.Forms;
6
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 );
15
16 // display point coordinates via X and Y properties
17 string output = "X coordinate is " + point.X +
18 "\n" + "Y coordinate is " + point.Y;
19
20 point.X = 10; // set x-coordinate via X property
21 point.Y = 10; // set y-coordinate via Y property
22
23 // display new point value
24 output += "\n\nThe new location of point is " + point;
25
26 MessageBox.Show( output, "Demonstrating Class Point" );
27
28 } // end method Main
29
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:



 
0
Comment
Question by:johnnys123
3 Comments
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
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).
0
 
LVL 2

Expert Comment

by:wellilein
Comment Utility
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

   InheritanceShape
Point   Square    Cube

or like

InheritanceShape
Point
Square
Cube
0
 
LVL 5

Accepted Solution

by:
g0rath earned 500 total points
Comment Utility
sounds like a homework question reworded
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now