Solved

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

Posted on 2003-11-09
3
351 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

786 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