Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Methoden zum Hinzufügen und Entfernen von Artikeln
  2.  
  3. // gloabales Array mit allen Artikeln
  4. var artikelSet = new Set();
  5. function neuerArtikel(name, preis, beschreibung, sonderpreis){
  6.     let artikel = new Artikel(name);
  7.         artikel.preis = preis;
  8.         artikel.beschreibung = beschreibung;
  9.         artikel.sonderpreis = sonderpreis;
  10.     artikelSet.add(artikel);
  11. }
  12.  
  13. function deleteArtikel(artikel){
  14.     artikelSet.delete(artikel);
  15. }
  16.  
  17. function neuerSchuh(name, groesse, preis){
  18.     let schuh = new Schuhe(name, groesse);
  19.     schuh.preis = preis;
  20.     artikelSet.add(schuh);
  21. }
  22.  
  23. function deleteSchuh(schuh){
  24.     artikelSet.delete(schuh);
  25. }
  26.  
  27. function listArticles(){
  28.     return artikelSet;
  29. }
  30. let Schuhe = function(name, schuhgroesse) {
  31.     Artikel.call(this, name);
  32.     let _schuhgroesse = schuhgroesse;
  33.     let _schuhmarke = undefined;
  34.     let _preis;
  35.     Object.defineProperty(this, 'schuhgroesse', {
  36.         get: function() { return _schuhgroesse;},
  37.         configurable: false
  38.     });
  39.     Object.defineProperty(this, 'schuhmarke', {
  40.         get: function() { return _schuhmarke;},
  41.         set: function(schuhmarke) {_schuhmarke = schuhmarke;}
  42.     });
  43.     Object.defineProperty(this, 'preis', {
  44.         get: function() { return (this.sonderpreis == undefined) ? _preis : this.sonderpreis;},
  45.         set: function(preis) {
  46.             if (preis >= 5) {_preis = preis;}
  47.         }
  48.     });
  49. }
  50. Schuhe.prototype = new Artikel;
  51. Schuhe.prototype.toString = function() {
  52.     // "superclass" toString response for current object + new toString additions
  53.     return Object.getPrototypeOf(Object.getPrototypeOf(this)).toString.call(this) + "<br>Schuhgröße: " + this.schuhgroesse + "<br>Schuhmarke: " + this.schuhmarke;
  54. }
  55. Schuhe.prototype.constructor = Schuhe;
  56. delete Schuhe.prototype.beschreibung;
  57. delete Schuhe.prototype.id;
  58. delete Schuhe.prototype.name;
  59. delete Schuhe.prototype.preis;
  60. delete Schuhe.prototype.sonderpreis;
  61. let Artikel = function(name) {
  62.    
  63.     // id für den Artikel generieren
  64.     Artikel.lastId = (Artikel.lastId) ? Artikel.lastId+1 : 1;
  65.     let _id = Artikel.lastId;
  66.    
  67.     // Name festlegen
  68.     let _name = name;
  69.     if (_name == "" || name == undefined) {
  70.         _name = "Artikel_" + _id;
  71.     }
  72.    
  73.     // Beschreibung festlegen
  74.     let _beschreibung;
  75.    
  76.     // Preis
  77.     let _preis = 0;
  78.    
  79.     // Der Sonderpreis ersetzt den regulären Preis
  80.     let _sonderpreis = undefined;
  81.    
  82.     // Objekt Definitionen
  83.     Object.defineProperty(this, 'id', {
  84.         get: function() { return _id;},
  85.         configurable: false
  86.     });
  87.     Object.defineProperty(this, 'name', {
  88.         get: function() { return _name;},
  89.         set: function(name) {
  90.             if (name != "" && name != undefined) {_name = name;}
  91.         }
  92.     });
  93.     Object.defineProperty(this, 'beschreibung', {
  94.         get: function() { return _beschreibung;},
  95.         set: function(beschreibung) {_beschreibung = beschreibung;}
  96.     });
  97.     Object.defineProperty(this, 'preis', {
  98.         get: function() { return (_sonderpreis == undefined) ? _preis : _sonderpreis;},
  99.         set: function(preis) {
  100.             if (preis >= 0) {_preis = preis;}
  101.         },
  102.         configurable: true
  103.     });
  104.     Object.defineProperty(this, 'sonderpreis', {
  105.         get: function() { return _sonderpreis;},
  106.         set: function(sonderpreis) {
  107.             if (sonderpreis >= 0) {_sonderpreis = sonderpreis;}
  108.             if (sonderpreis == undefined) {_sonderpreis = sonderpreis;}
  109.         }
  110.     });
  111. }
  112.  
  113. /**
  114.  * diese Methode vergleicht die Preise
  115.  */
  116. Artikel.prototype.isCheaperThan = function(artikel2) {
  117.     return (this.preis < artikel2.preis);
  118. }
  119.  
  120. /**
  121.  * für die Ausgabe
  122.  */
  123. Artikel.prototype.toString = function() {
  124.     return "Id: " + this.id + "<br>Name: " + this.name + "<br>Beschreibung: " + this.beschreibung + "<br>Preis: " + this.preis;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement