• Post Reply Bookmark Topic Watch Topic
  • New Topic

Variable declaration  RSS feed

 
adrei boadrei
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello my friends.
I have a question:


i have 4 class:
1.Artist
2.Album
3.Track
4.Country-enum

with following variables:

1. Artist
private String nameArtist;------------
private Country countries;
private String webpage;
private String Biography;
private Icon artistImage; ------------a)variable is declared correctly?is of type icon?

2.Album
private Icon coverAlbum;
private Artist numeAutor; ---------------b)need to declare this variable if the variable is declared in class Artis?
private String nameAlbum;


3.Track
private Artist numeCantaret;----------------c)need to declare this variable if the variable is declared in class Artis end Album?
private int year;
private String genre;
private String composer;
private int frequency;
private String fileName;
private String filePath;
private String format;
private Album nameAlbum;
private String titleSong;
private int rating;
private String lengthSong;-----------------d) lengthSong;(ex : (4:35))-it is String or Time(javax.media) tipe -or....?


e.If the variable should be declared in each class, then variabelii name must be the same in each class? Or different as it is to me?

1. clasa ----nameArtist or nameArtist
2 clasa----numeAutor or nameArtist
3 clasa----numeCantaret or nameArtist


 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a)variable is declared correctly?is of type icon?

possibly. The API does have an interface defined called "Icon". It would have to be implemented somewhere and you'd have to have the proper imports.
b)need to declare this variable if the variable is declared in class Artis?
c)need to declare this variable if the variable is declared in class Artis end

What are these supposed to represent?
d) lengthSong;(ex : (4:35))-it is String or Time(javax.media) tipe -or....?

How are you going to use it?

Basically, to me, it looks like you are doing things wrong. You are writing code before you have thought through the design. I suggest you Stop Coding (<---click and READ THAT PAGE).
 
Taylor Smolik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like your going to want to have Artist as a superclass for Album, and Album as a superclass for Track. You can re-use a variable of your superclass in your subclasses.







If you want to access a superclass variable from the subclass, use "super"



Hope this helps
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Smolik wrote:Looks like your going to want to have Artist as a superclass for Album, and Album as a superclass for Track. You can re-use a variable of your superclass in your subclasses.



Hope this helps


No actually that's a very bad practice. You shouldn't extend just to reuse. Class A should exten B only there is a Is a relationship between the 2 classes. If the relationship is a Has a relationship you should use encapsulation. In this case an albums Has a artist. Album is not an artist. So, album shouldn't extend artist.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!