1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| import java.util.*;
import java.io.*;
abstract class Location
{
//Instanciation objet héritage classe classique
protected String leCode, leFormat, leTitre;
//On a le droit de construire
public Location (String leCode, String leFormat, String leTitre)
{
this.leCode = leCode;
this.leFormat = leFormat;
this.leTitre = leTitre;
}
public abstract double coutLocation();
//Méthode abstrait #1. Ne c'est pas comment retourner
public abstract int joursLocation();
//Méthode abstrait #2. Ne c'est pas comment retourner
public abstract double tauxRetard();
//Méthode abstrait #3. Ne c'est pas comment retourner
public double penalite(int nbJours)
{
return nbJours;
}
public double coutTotal(int prixBase_VHS)
{
return prixBase_VHS;
}
public String toString()
{
return String.format("%4s %4s %1f$ pour%3d jours",leFormat, leTitre, coutLocation(),joursLocation());
}
}
class Classique
extends Location
{
//Construit l'objet
private String code,
format,
titre;
int prixBase_VHS=0,
prixBase_DVD=0,
dureeMax=0,
penaliteRetard=0;
public Classique(String code, String format, String titre)
{
super(code, format, titre);
prixBase_VHS=2;
prixBase_DVD=3;
dureeMax=5;
penaliteRetard=1;
}
//Le probleme est ici. Je ne sais pas pourquoi?
//Il devrait dire sir format=VHS, alors prix=2$, si format =DVD alors prix=3$
public double coutLocation()
{
return (format=="VHS")?prixBase_VHS:prixBase_DVD;
}
public int joursLocation()
{
return dureeMax;
}
public double tauxRetard()
{
return penaliteRetard;
}
public String toString()
{
return "Classique" + super.toString();
}
} |
Partager