Probleme static Java
boabab95
Messages postés
20
Date d'inscription
Statut
Membre
Dernière intervention
-
Marco la baraque Messages postés 996 Date d'inscription Statut Contributeur Dernière intervention -
Marco la baraque Messages postés 996 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
j'ai un problème ! je m'arrache les cheveux à la compilation de test.java j'ai 5 fois l'erreur :
Cannot make a static reference to the non-static method.
voici mon code :
public class test {
public static void main (String args[]) {
avion av;
billet a,b,c,d;
a = new billet("a",1,1);
a = new billet("b",2,1);
a = new billet("c",3,1);
a = new billet("d",4,1);
av = new avion("avion",1,3,3);
avion.embarquer(a);
avion.embarquer(b);
avion.embarquer(c);
avion.embarquer(d);
System.out.println(avion.toString());
}
}
class billet{
private String nom;
public int num, date;
public billet(){
this.nom = " ";
this.num = 0;
this.date = 0;
}
public billet(String s, int n, int r){
this.nom = s;
this.num = n;
this.date = r;
if(this.date<1 || this.date>31){
this.date = 0;
}
}
public String getNom(){
return this.nom;
}
public int getNum(){
return this.num;
}
public int getDate(){
return this.date;
}
public void setNumDate(int n, int d){
this.num = n;
this.date = d;
}
public String toString(){
return "Billet " +this.nom +" a la date " +this.date +" avec le numero " +this.num;
}
}
class avion {
//propriété de la classe
private String iden;
private int date;
private int libre;
private int [][] place;
//constructeur
public avion(String s,int d,int r,int p){
this.iden = s;
this.date = d;
this.place = new int [r][p];
this.libre = r*p;
}
//Accesseurs
public int getNrRang(){
return this.place.length;
}
public int getTailleRang(){
return this.place[0].length;
}
public String getIden(){
return this.iden;
}
public int getDate(){
return this.date;
}
public int getLibre(){
return this.libre;
}
//Modifieurs
public void setIden(String s){
this.iden = s;
}
public void setDate(int d){
this.date = d;
}
//Methodes de la classe
public boolean embarquer(billet b){
if((this.date == b.date) && (libre != 0)){
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == 0){
place[i][j] = b.num;
this.libre --;
return true;
}
}
}
}
return false;
}
public boolean debarquer(billet b){
if(this.date != b.date){
return false;
}
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == (b.num)){
place[i][j] = 0;
this.libre ++;
return true;
}
}
}
return false;
}
public String toString(){
String x = " ", y = " ";
char [][] c;
c = new char [getNrRang()][getTailleRang()];
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == 0){
c[i][j] = 'L';
}
else{
c[i][j] = 'O';
}
}
}
x = "Avion " +this.iden +" ,nombre de places : " +(getNrRang()*getTailleRang()) +", libres : " +this.libre +", date de depart : " +this.date +"\n";
for(int a = 0; a<c.length; a++){
for(int q = 0; q<c[a].length; q++){
y = y + c[a][q];
}
y = y + "\n";
}
return (x + y);
}
}
Si quelqu'un peut m'aider je vous remercie !
j'ai un problème ! je m'arrache les cheveux à la compilation de test.java j'ai 5 fois l'erreur :
Cannot make a static reference to the non-static method.
voici mon code :
public class test {
public static void main (String args[]) {
avion av;
billet a,b,c,d;
a = new billet("a",1,1);
a = new billet("b",2,1);
a = new billet("c",3,1);
a = new billet("d",4,1);
av = new avion("avion",1,3,3);
avion.embarquer(a);
avion.embarquer(b);
avion.embarquer(c);
avion.embarquer(d);
System.out.println(avion.toString());
}
}
class billet{
private String nom;
public int num, date;
public billet(){
this.nom = " ";
this.num = 0;
this.date = 0;
}
public billet(String s, int n, int r){
this.nom = s;
this.num = n;
this.date = r;
if(this.date<1 || this.date>31){
this.date = 0;
}
}
public String getNom(){
return this.nom;
}
public int getNum(){
return this.num;
}
public int getDate(){
return this.date;
}
public void setNumDate(int n, int d){
this.num = n;
this.date = d;
}
public String toString(){
return "Billet " +this.nom +" a la date " +this.date +" avec le numero " +this.num;
}
}
class avion {
//propriété de la classe
private String iden;
private int date;
private int libre;
private int [][] place;
//constructeur
public avion(String s,int d,int r,int p){
this.iden = s;
this.date = d;
this.place = new int [r][p];
this.libre = r*p;
}
//Accesseurs
public int getNrRang(){
return this.place.length;
}
public int getTailleRang(){
return this.place[0].length;
}
public String getIden(){
return this.iden;
}
public int getDate(){
return this.date;
}
public int getLibre(){
return this.libre;
}
//Modifieurs
public void setIden(String s){
this.iden = s;
}
public void setDate(int d){
this.date = d;
}
//Methodes de la classe
public boolean embarquer(billet b){
if((this.date == b.date) && (libre != 0)){
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == 0){
place[i][j] = b.num;
this.libre --;
return true;
}
}
}
}
return false;
}
public boolean debarquer(billet b){
if(this.date != b.date){
return false;
}
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == (b.num)){
place[i][j] = 0;
this.libre ++;
return true;
}
}
}
return false;
}
public String toString(){
String x = " ", y = " ";
char [][] c;
c = new char [getNrRang()][getTailleRang()];
for(int i=0; i<getNrRang(); i++){
for(int j=0; j<getTailleRang(); j++){
if(place[i][j] == 0){
c[i][j] = 'L';
}
else{
c[i][j] = 'O';
}
}
}
x = "Avion " +this.iden +" ,nombre de places : " +(getNrRang()*getTailleRang()) +", libres : " +this.libre +", date de depart : " +this.date +"\n";
for(int a = 0; a<c.length; a++){
for(int q = 0; q<c[a].length; q++){
y = y + c[a][q];
}
y = y + "\n";
}
return (x + y);
}
}
Si quelqu'un peut m'aider je vous remercie !
A voir également:
- Probleme static Java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo