In: Computer Science
Create a class named Ship with a field that stores a collection of Shippable things and another that stores a maximum weight capacity. Include a constructor with a parameter for the max weight, and that gives the Ship an empty collection of Shippables. (Javascript)
CODE:
Text:
function printNumber(arr) {
for (var i = 0; i < 10; i++) {
var number = window.prompt("Enter a number");
if (number > 10 && number < 100) {
if (arr.find(aNumber => aNumber === number) == undefined) {
arr.push(number);
console.log(number + " ");
}
}
}
}
class Ship{
constructor(maxWeight){
this.capacity = maxWeight;
this.shippableItems = [];
}
addItems(item){
if(this.shippableItems.length < this.capacity){
this.shippableItems.push(item);
}
}
printItems(){
for(let item of this.shippableItems){
console.log(item);
}
}
}
var ship = new Ship(5);
ship.addItems("Veg");
ship.addItems("Meat");
ship.addItems("Fish");
ship.addItems("colddrink");
ship.addItems("beverage");
ship.printItems();
OUTPUT: