Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class BateauAcontainer
- using System;
- public class BateauAContainer
- {
- private string immatriculation;
- private float poidsVide;
- private int maxContainer;
- private Container[] tabContainer;
- private int nbContainerAct = 0;
- public BateauAContainer(string paramImmatriculation, float paramPoidsVide, int paramMaxContainer)
- {
- immatriculation = paramImmatriculation;
- poidsVide = paramPoidsVide;
- maxContainer = paramMaxContainer;
- tabContainer = new Container[paramMaxContainer];
- }
- /// <summary>
- /// Affiche les informations de ce bateau sur la console
- /// </summary>
- public void AfficherInfo()
- {
- Console.WriteLine("Immatriculation {0}, poid vide {1}, poid total {2}, max container {3}, nb container {4}",immatriculation,poidsVide,this.DonnePoidsTotal(),maxContainer,nbContainerAct);
- for(int i=0;i<tabContainer.Length;i++)
- {
- if(tabContainer[i] != null)
- {
- tabContainer[i].AfficherInfo();
- }
- }
- }
- /// <summary>
- /// Si la capacité du bateau le permet : ajoute un container au tableau des containers et retourne vrai. Retourne faux sinon.
- /// </summary>
- /// <param name="containerAAjouter">le container à ajouter</param>
- /// <returns>booléen en fonction de l'ajout du container</returns>
- public bool AjouterContainer(Container containerAAjouter)
- {
- if(nbContainerAct >= maxContainer)
- {
- return false;
- }
- else
- {
- tabContainer[nbContainerAct] = containerAAjouter;
- nbContainerAct = nbContainerAct + 1;
- return true;
- }
- }
- /// <summary>
- /// Donne le poids total du bateau avec l'ensemble de ses containers.
- /// </summary>
- /// <returns>Le poids total</returns>
- public float DonnePoidsTotal()
- {
- float poidTotal = 0;
- for(int i= 0;i < tabContainer.Length;i++)
- {
- if(tabContainer[i] == null)
- {
- poidTotal = poidTotal + 0;
- }
- else
- {
- poidTotal = poidTotal + tabContainer[i].DonnerPoids();
- }
- }
- return poidTotal;
- }
- }
- -------------------
- //class Container
- using System;
- /// <summary>
- /// Description of Container.
- /// </summary>
- public class Container
- {
- private float poids;
- private string contenu;
- public Container(float paramPoids, string paramContenu)
- {
- poids = paramPoids;
- contenu = paramContenu;
- }
- /// <summary>
- /// Affiche les informations de ce container sur la console
- /// </summary>
- public void AfficherInfo()
- {
- Console.WriteLine("contenu : {0} poids : {1}", contenu, poids);
- }
- /// <summary>
- /// Retourne le poids du container
- /// </summary>
- /// <returns></returns>
- public float DonnerPoids()
- {
- return poids;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement