May 08, 2024, 06:27:28 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Class CD Collection

Started by Techno, June 14, 2015, 02:41:09 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

June 14, 2015, 02:41:09 AM Last Edit: June 14, 2015, 02:43:19 AM by Techno
Dear support,

I don't know how I can translate this code from java to iwbasic. It's about this part of code:

1) Constructor with parameters


[b][color=red][color=red]class CD {
public CD (int cd_nr, String titel, int jaar, String artiest, Cd volgende, Cd vorige, String genre) {
this.m_cd_nr = cd_nr;
this m_titel = titel;
this m_jaar = jaar;
this m_artiest = artiest;
this m_genre = genre;

this p_volgende = volgende;
this p_vorige = vorige;
....[/color][/color][/b]


2) toString method

[b][color=red]public String toString(){
return("CD_Nummer: " + this.m_cd_nr +
      "Titel van de CD: " + this.m_titel +
      "Muziekjaar: " + this.m_jaar +
      " )
}
[/color][/b]

3) The original code of the class CD

[size=10pt][b][i][color=blue]class CD {

//Declaratie van de private members

private int m_cd_nr = 0;
private String m_titel;
private String m_artiest;
private int m_jaar;
private String m_genre;

private Cd p_volgende;
private Cd p_vorige;

// Maken van de constructor
public CD (int cd_nr, String titel, int jaar, String artiest, Cd volgende, Cd vorige, String genre) {

// De members initialiseren
this.m_cd_nr = cd_nr;
this m_titel = titel;
this m_jaar = jaar;
this m_artiest = artiest;
this m_genre = genre;

this p_volgende = volgende;
this p_vorige = vorige;

// Schrijven property methods
public String getTitel(){
return(m_titel);
}

public int getCD_nr(){
return(m_cd_nr);
}

public int getJaar() {
return(m_jaar);
}

public int getArtiest() {
return(m_artiest);
}

public void setTitel(String titel){
this.m_titel = titel;
}

public void setCD_nr(int nr){
this.m_cd_nr = nr;
}

public void setJaar(int jaar){
this.m_jaar = jaar;
}

public String toString(){
return("CD_Nummer: " + this.m_cd_nr +
      "Titel van de CD: " + this.m_titel +
      "Muziekjaar: " + this.m_jaar +
      " )
}
}

}[/color][/i][/b][/size]


4) My translated IWBasic code


CLASS CD
private
m_cd_nr : int
m_cd_titel : string
m_cd_artiest : string
m_cd_jaar : int
m_cd_genre : string

p_volgende : POINTER CD
p_vorige : POINTER CD

PUBLIC
declare CD()
DECLARE _CD()

DECLARE getTitel(), string
DECLARE getCD_nr(), int
DECLARE getJaar(), int
DECLARE getArtiest(), string
DECLARE getGenre(), STRING
DECLARE toString(), STRING

DECLARE setTitel(titel : STRING)
DECLARE setCD_nr(nr : INT)
DECLARE setJaar(jaar : int)
DECLARE setArtiest(artiest : STRING)
DECLARE setGenre(genre : STRING)

DECLARE toString(), STRING
endclass


SUB CD::CD()

end sub

SUB CD::getTitel(), STRING
RETURN m_cd_titel
ENDSUB

SUB CD::getCD_nr(), int
RETURN m_cd_nr
ENDSUB

SUB CD::getJaar(), int
RETURN m_cd_jaar
ENDSUB

SUB CD::getArtiest(), STRING
RETURN m_cd_artiest
ENDSUB

SUB CD::getGenre(), STRING
RETURN m_cd_genre
ENDSUB

SUB CD::setTitel(titel : STRING)
m_cd_titel = titel
ENDSUB

SUB CD::setCD_nr(nr : int)
m_cd_nr = nr
ENDSUB

SUB CD::setJaar(jaar : int)
m_cd_jaar = jaar
ENDSUB

SUB CD::setGenre(genre : STRING)
m_cd_genre = genre
ENDSUB


Thanks if you can help for the questions
Stephane