Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ObjFilters {
- constructor(name) {
- this.name = name;
- this.id = hashCode(name);
- this.filters = false;
- }
- }
- class PollutionObject extends ObjFilters {
- constructor(name, date, municipality, temperature, PM10, NO2, O3, SO2) {
- super(name);
- this.date = date;
- this.temperature = temperature;
- this.municipality = municipality;
- this.PM10 = PM10;
- this.NO2 = NO2;
- this.O3 = O3;
- this.SO2 = SO2;
- }
- rizik() {
- if(this.PM10 && this.NO2 && this.O3 && this.SO2 && this.temperature<10)
- return "The object "+this.id+" " + this.name + " pollutes the air at high risk";
- if(this.PM10 && this.NO2 & this.O3 && this.SO2 && this.temperature>10)
- return "The object "+this.id+" " + this.name + " pollutes the air at average risk";
- if(this.NO2 && this.SO2 && this.O3)
- return "The object "+this.id+" " + this.name + " pollutes the air at average risk";
- if(this.PM10 && this.NO2 && this.O3)
- return "The object "+this.id+" " + this.name + " pollutes the air at average risk";
- if(this.SO2 && this.O3)
- return "The object "+this.id+" " + this.name + " pollutes the air at low risk"
- if(this.PM10 && this.NO2 && this.temperature>10)
- return "The object "+this.id+" " + this.name + " pollutes the air at low risk"
- if(this.PM10 == false && this.NO2 == false && this.SO2 == false && this.O3 == false)
- return "The object "+this.id+" " + this.name + " pollutes the air at low risk (eco friendly)"
- }
- toString () {
- var ret="Object "+this.id.toString() + " " + this.name.toString();//Object %id %name has/hasn't got filters
- if(this.filters) ret=ret+"has got filters";
- else ret=ret+"hasn't got filters";
- return ret;
- }
- }
- class AirPollution {
- constructor() {
- this.listofobj = [];
- }
- add_object(a) {
- this.listofobj.push(a);
- }
- test_object(a) {
- var help = a.date+"";
- help = help.substring(4,7);
- if(!(help == "Dec" || help == "Nov" || help == "Oct"))
- a.filters = true;
- }
- check() {
- for(var i=0; i<this.listofobj.length; i++){
- this.test_object(this.listofobj[i]);
- console.log(this.listofobj[i].rizik());
- }
- }
- safe_zone(opstina){
- var count = 0;
- var fil = 0;
- for(var i=0; i<this.listofobj.length; i++){
- if(this.listofobj[i].municipality == opstina)
- count++;
- if(this.listofobj.filters == true)
- fil++;
- }
- if(fil!=0)
- return "You are in a " + 100/fil + "% safe zone";
- return "You are in a 100% safe zone";
- }print() {
- for (var i=0;i<this.listofobj.length;i++)
- {
- console.log("PollutionObject {");
- var h = this.listofobj[i];
- var count = 0;
- for(var k in h) {
- if (k != "add_object" && k != "toString" && k!="safe_zone" && k!="check" && k!="test_object")
- count++;
- }
- var c = 0;
- for (var j in h)
- {
- if (j != "add_object" && j != "toString" && j!="safe_zone" && j!="check" && j!="test_object"){
- if(j=="name" || j == "municipality") {
- if(c!=count-1){
- console.log(" " + j + ": " + "'"+ h[j] + "',");
- }
- else
- console.log(" " + j + ": " + "'"+ h[j] + "'");
- }
- else{
- if(c!=this.count-1){
- console.log(" " + j + ": " + h[j]+",");
- }
- else
- console.log(" " + j + ": " + h[j]+",");
- }
- }
- c++;
- }
- console.log("}");
- }
- }
- }
- var hashCode = function(s){
- return String(s).split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement