Forums Register Login

New Week, new assignment: "Polymorphic containers and text processing in Java"

+Pie Number of slices to send: Send
Hi again everyone,

It seems we have abandoned Dice/Die(s), and are now working on something completely foreign. I don't even have a code to start with because I haven't the faintest clue what is going on here (no notes given on this topic, as usual). We are given 4 half-written programs to work with. If I can get just one portion right today, I'll feel accomplished lol.

The instructions are:

"Examine the FormLetterEntry abstract class, and create the two derived classesTextEntry and DataItemEntry. Be sure to implement all the abstract methods in each derived class."


This is the code we were given:




I understand (and correct me if I am wrong) that a derived class is a class that is created from a base class via inheritance. What I don't see are any notes on how to write a derived class. I see some notes online on how to do so, but they don't fit with what he's written above. I have no idea what he means by "Be sure to implement all the abstract methods in each derived class." I'll keep working on it, but some examples would be greatly appreciated.

Thanks.
1
+Pie Number of slices to send: Send
Class inheritance is really a wide and tricky topic with all kinds of weird rules, so really you have to find a reliable tutorial or book and buckle down. There's no way you can cover all the relevant issues in just a thread. Polymorphism and abstract classes are separate topics that should be tackled afterward.

The general gist of inheritance is that you use the extends keyword to indicated what class your derived class came from. Then you won't have to repeat code, you just write anything that's new.

Abstract classes are meant to be extended and force the extending to class to complete (give a body to) the abstract methods that they declared. That's what your teacher means by "implement all the abstract methods in each derived class." If you don't your code won't compile.
+Pie Number of slices to send: Send
What have you actually been taught in your class? I can't understand why you would be asked to write classes that implement an abstract class if you haven't at least been pointed at a tutorial explaining the concepts.

Have you been taught about inheritance and polymorphism?
Have you been told anything about abstract classes and what it means for a class to be abstract?


Also have you been told what TextEntry and DataEntry are actually meant to do? Even if you know how to write a class that extends FormLetterEntry, if you don't know what functionality the derived classes should have then you're going to struggle and we will only be able to guess at what you're meant to do.

Here are some Oracle tutorials that you may find useful:

Inheritance
Abstract Methods and Classes

Also the abstract Class you have been given only has abstract methods and has no fields or implemented methods of its own, so really should have been an Interface. It doesn't seem like a great example to me.
+Pie Number of slices to send: Send
In our notes (the class is online), there's a 10 line blurb called "should I use interfaces or inheritances?", and also another 10 liner about interfaces in another set of notes. I just went back and reread them, and nothing in there mentions a thing about derived classes. Just to give you an idea of how sporadic the class/notes are, in week 4 there was a power point called "intro to object oriented programming". Week 1 was a "Hello World" thing, which I actually got right (though I couldn't tell you how), and then weeks 2-4 were Dice. Last week was creating graphics, and this week is what I posted above. There was no real intro to the course -- just "Do this, and it's due this week". I'm the kind of person that needs examples. If he wants me to write a program about dice, I need to see something to liken it to first (i.e. -- give me an example about cats and dogs first). The only thing I can compare this to (given that my undergrad is in social science and arts) is telling an avid programmer to learn a piano piece by next week and play it in symposium, even though they've never read music in their life.

Don't get me wrong, I blame myself. I wanted to try something new and probably just don't have the brain type to learn it. But still, it would have been nice if there were more direction to the course.

So in sum, I can see a few notes on abstract classes. I have no idea what polymorphism is. It doesn't say anything about why we are doing the exercises we are doing, just to do them. So that would be a no on TextEntry and DataEntry. But again, this has burned a hole where my brain used to be, so I could be reading exactly what I need to know, and still not retain or understand it. That's all on me, no one else.

I probably shouldn't do this, but desperation makes us do funny things: here's the link to the course page.

http://mysite.du.edu/~mschwart/ICT4361/javahw5a.html





Thanks guys.
1
+Pie Number of slices to send: Send
 

D Doemer wrote:Don't get me wrong, I blame myself. I wanted to try something new and probably just don't have the brain type to learn it.


I'd say it's waaay too early to say that yet. Programming certainly isn't for everybody, but 4 weeks is no time at all in the grand scheme of things. To use your own analogy: would you expect to be able to play the piano in 4 weeks? And would you (or anybody else) be able to work out if you were any good at it in that time? I doubt it.

But still, it would have been nice if there were more direction to the course.


Now there, based on what I've seen in the exercise notes, I'd have to agree with you. They even confused me, and I've been at this lark a long time.

One thing that helped me kind of work out what's going on was to look at the FormLetterHello.java file, which has quite a lot of sample code in it, so you can actually see how a letter is built up. It's in the "homework starter files" zip, under the directory "src/hw5".

However, before you start all that, or worrying about abstract classes and interfaces and polymorphism - Do you actually know what a "form letter" does? Have you ever seen one in action with MS Word (or some other such program)?

If so, try and describe it for yourself in English - forget about Java for the moment. What does it do? And what does the user need to supply in order to get it to print out properly?

When you've done that, feel free to post it here; or go back and re-read the notes and see if they make any more sense. I think right now you're getting bogged down in all that structural Java-babble, when what you really need to understand is what a form letter does.

HIH

Winston
1
+Pie Number of slices to send: Send
I fully agree with Winston here. All the knowledge on Inheritance and abstract classes in the world won't help you until you know what the form letter is and what its meant to do.

In addition to the class that Winston mentioned, also check out the unit test in the 'test' directory. It shows you example input data along with the expected output. You can use that to see if you understand the concept of a FormLetter, and also during development to make sure your implementation is correct.

As a first step I suggest you describe to us what a FormLetter is.
+Pie Number of slices to send: Send
A form letter is simply a template which is meant to be sent to many recipients at the same time. (i.e. -- school acceptance or rejection letter, offer or decline on employment, etc).
+Pie Number of slices to send: Send
 

D Doemer wrote:A form letter is simply a template which is meant to be sent to many recipients at the same time. (i.e. -- school acceptance or rejection letter, offer or decline on employment, etc).


OK, but there's bit more to them than just that. For example, they often contain placeholders or fields so that you can substitiute things like names and dates, so as to "personalize" them.

It might be worth looking up a few defintions online as well, because the fuller a description you can get to start with, the better it's likely to be.

Winston
+Pie Number of slices to send: Send
You guys are such good people trying to walk me through this, but I'm afraid it's just not going to sink in at this point. The course moved too quickly for me, and in order for me to truly understand Java, I'd need to go back and figure out why we write things like public, void, main, stingargs, why we indent what we indent and where, and frankly, why we even do this in the first place. It must have been assumed that everyone already had a class prior to this, though there wasn't a prereq.

Anyhow, I've literally spent the last 2 weeks spending about 18 of 24 hours staring at this screen, so I need someone who can walk me through this, if possible. I started writing some stuff based on examples on the internet, but I'm sure it isn't correct since errors are flying at me left and right:

package homework5;

import java.util.Properties;

public abstract class FormLetterEntry {

abstract public String templateString();

abstract public String formLetterString();

abstract public void doProcess(Properties data);





This is for #2 on my assignment.
1
+Pie Number of slices to send: Send
To answer your first two questions:

1) Don't worry about the signature of the main method. The makers of Java defined that the entry point of Java programs would be public static void main(String[]).

There are good reasons why its public, static and void, but that would be best answered in another question. The name main is probably to make it similar to C/C++.

All you need to know is that that OS is the defined entry point for a Java program.

2) Indentation is only to make code easy to read. You don't need it, it will compile just fine without it. There are conventions in place so that programs are generally easy to read, and if you don't follow them other programmers may be less likely to read your code. The compiler doesn't care though.

Now on to your code:

Your abstract class named Derived was not one of the classes you were asked to write. You need two concrete (dont use the abstract keyword) classes names TextEntry and DataItemEntry.

Create those two classes and compile them. Post any compilation errors here and we'll help.
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1090 times.
Similar Threads
FBNS: Inherit from Data class and How to operate db.db
Application Testing Techniques
instanceOf
inheritance
when should i use abstract class and when i should i interfaces
Form Letter Template
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:02:04.