• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple java project  RSS feed

 
Adin Cebic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I am a student and all my programming experience is in c++. This semester I need to learn java. I am studying from Absolute Java 5th edition and I am stuck in chapter 5 question 4

You are interested in keeping track of the team members and competition information for your school’s annual entries in computer science programming competitions. Each team consists of exactly four team members. Every year your team competes in two competitions. As an initial start for your database, create a class named Team that has the following instance variables:
//Name for the team
String teamName;
//Names for each team members
String name1, name2, name3, name4;
Competition competition1, competition2;

Note that there is a much better way to represent the team members and competitions using arrays; this is covered in a subsequent chapter. The class should also have a method that outputs all the names of all team members and the competition information to the console.
The Competition class contains variables to track the following:

String: Name of the competition, Name of the winning team, Name of the runner-up.
Integer: Year of the competition
Implement Team and Competition classes with appropriate constructor, accessor and mutator methods. In entering data for past competitions, you note that an entry is usually very similar to the previous year’s entry. To help with the data entry, create a deep copy of an existing team object, changing the competition information for the copy, and outputting the data for the original and the copy. The original object should be unchanged if your deep copy constructor is working properly.

I am not asking you for the full solution but for the guidelines because I still don't get the objects and constructors very well.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adin Cebic wrote:
I am not asking you for the full solution but for the guidelines because I still don't get the objects and constructors very well.


Well, for the most part, constructors are pretty much very similar between Java and C++. So, your C++ experience should work very well here. The differences are ...

1. Java uses the super() construct on the first line (of the constructor) to initialize the superclass. C++ uses the ":" construct prior to the code block (of the constructor) to achieve the same.
1a. C++ can also use the same construct (mentioned #1) for instance variables as well.
2. Java, while having a concept of a finalizer, doesn't really have the concept of a destructor like C++.

So, arguably, Java constructors may be a bit easier to use. Although, as a counter argument, may not be as flexible.
Henry
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:. . . Java, while having a concept of a finalizer, doesn't really have the concept of a destructor like C++. . . .
Finalisers are probably an advanced topic and you will go a long time before you need to use a finaliser. The reason Java® object don't have destructors is that the JVM executes automatic memory management, and any objects not required are automatically deleted if there is a risk of all the memory being filled up. So there is no need for destructors.

And welcome to the Ranch
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!