Solved

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

Posted on 2003-11-09
3
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

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

Expert Comment

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

   InheritanceShape
Point   Square    Cube

or like

InheritanceShape
Point
Square
Cube
0
 
LVL 5

Accepted Solution

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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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.

617 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