From d027b691d1119512183d8a24610d5e8085aad94b Mon Sep 17 00:00:00 2001 From: Swathi Siripurapu Date: Tue, 22 Aug 2017 22:28:40 +0530 Subject: [PATCH 1/2] Prasanth Assignment submit --- assignment.html | 22 +++++++++++++ main.js | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 assignment.html create mode 100644 main.js diff --git a/assignment.html b/assignment.html new file mode 100644 index 0000000..f8ed577 --- /dev/null +++ b/assignment.html @@ -0,0 +1,22 @@ + + +Sample HTML page + + + +
+ + + +

please check output in console

+ +
+ +
+ +
+ + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..515ef96 --- /dev/null +++ b/main.js @@ -0,0 +1,88 @@ + +function factorial(number) { + if (number === 0) { + return 1; + } + return number * factorial(number - 1); + } + + function sumofNaturalNum(){ + /* sn = n(n+1)/2*/ + //getting factorial number + + console.log('Factorial for the given number is '+factorial(document.getElementById("naturalNumber").value)); + + //calculating sum of natural number + var input = document.getElementById("naturalNumber").value; + var sum = Number(input)*(Number(input)+1)/2; + console.log('Sum of the given natural number is '+sum); + getMultipleSum(); + powerofTwo(); + fizzBuzz(); + palindrome(); + + } + + function getMultipleSum(){ + var input = document.getElementById("naturalNumber").value; + var sum = 0; + for(var i =0;i=1; i--) + { + + if ((i & (i-1)) == 0) + { + res = i; + break; + } + } + console.log('closest power of 2 which is less than or equal to the number is '+res ); + } + + function fizzBuzz(){ + var inputVal = document.getElementById("naturalNumber").value; + var str=""; + for (var i=1;i<=Number(inputVal);i++) + { + if(i%3==0) + { + str+=",fizz" + } + if (i%5==0) + { + str+=",buzz" + } + if (!(i%3==0||i%5==0)) + { + str+=','+i; + } + + } + console.log(str); + } + + function palindrome(){ + var inputVal = "sister";//document.getElementById("naturalNumber").value; + var stringArr = String(inputVal).split(""); + stringArr.reverse(); + var reverseStr=""; + for(var i = 0;i Date: Sun, 27 Aug 2017 17:51:25 +0530 Subject: [PATCH 2/2] Angular training Day-2 Assignment --- Day-2/Emp.js | 0 Day-2/Employee.js | 44 ++++++++++++---------- Day-2/Employee.ts | 9 ++++- Day-2/Organization.js | 53 +++++++++++++------------- Day-2/Organization.ts | 3 +- Day-2/cricket-match/ExecuteMatch.js | 6 +++ Day-2/cricket-match/ExecuteMatch.ts | 6 +++ Day-2/cricket-match/Player.js | 19 ++++++++++ Day-2/cricket-match/Player.ts | 20 ++++++++++ Day-2/cricket-match/match.js | 30 +++++++++++++++ Day-2/cricket-match/match.ts | 31 +++++++++++++++ Day-2/salary-updater.js | 21 ++++++----- Day-2/salary-updater.ts | 1 + Day-2/salary-upgrader.js | 58 ++++++++++++++++++++--------- Day-2/salary-upgrader.ts | 26 ++++++++++++- Day-2/test.html | 19 ++++++++++ 16 files changed, 270 insertions(+), 76 deletions(-) create mode 100644 Day-2/Emp.js create mode 100644 Day-2/cricket-match/ExecuteMatch.js create mode 100644 Day-2/cricket-match/ExecuteMatch.ts create mode 100644 Day-2/cricket-match/Player.js create mode 100644 Day-2/cricket-match/Player.ts create mode 100644 Day-2/cricket-match/match.js create mode 100644 Day-2/cricket-match/match.ts create mode 100644 Day-2/test.html diff --git a/Day-2/Emp.js b/Day-2/Emp.js new file mode 100644 index 0000000..e69de29 diff --git a/Day-2/Employee.js b/Day-2/Employee.js index f55454a..6631235 100644 --- a/Day-2/Employee.js +++ b/Day-2/Employee.js @@ -1,20 +1,24 @@ -"use strict"; -exports.__esModule = true; -var Employee = (function () { - function Employee(id, name, salary) { - this.id = id; - this.name = name; - this.salary = salary; - } - Employee.prototype.printInfo = function () { - console.log(this.name + " gets " + this.salary); - }; - Employee.prototype.updateSalary = function (newSalary) { - this.salary = newSalary; - }; - Employee.prototype.getSalary = function () { - return this.salary; - }; - return Employee; -}()); -exports.Employee = Employee; +"use strict"; +exports.__esModule = true; +var Employee = (function () { + function Employee(id, name, salary, rating) { + this.id = id; + this.name = name; + this.salary = salary; + this.rating = rating; + } + Employee.prototype.printInfo = function () { + console.log(this.name + " gets " + this.salary); + }; + Employee.prototype.updateSalary = function (newSalary) { + this.salary = newSalary; + }; + Employee.prototype.getSalary = function () { + return this.salary; + }; + Employee.prototype.getRating = function () { + return this.rating; + }; + return Employee; +}()); +exports.Employee = Employee; diff --git a/Day-2/Employee.ts b/Day-2/Employee.ts index ee0002f..ce289d3 100644 --- a/Day-2/Employee.ts +++ b/Day-2/Employee.ts @@ -2,12 +2,15 @@ export class Employee { id: number; name: string; salary: number; - constructor(id: number, name: string, salary: number) { + rating:number; + constructor(id: number, name: string, salary: number, rating:number) { this.id = id; this.name = name; this.salary = salary; + this.rating = rating; } printInfo() { + console.log(`${this.name} gets ${this.salary}`); } updateSalary(newSalary: number) { @@ -16,5 +19,9 @@ export class Employee { getSalary() { return this.salary; } + + getRating(){ + return this.rating; + } } diff --git a/Day-2/Organization.js b/Day-2/Organization.js index 4ec45dd..545d93a 100644 --- a/Day-2/Organization.js +++ b/Day-2/Organization.js @@ -1,26 +1,27 @@ -"use strict"; -exports.__esModule = true; -var Employee_1 = require("./Employee"); -var Organization = (function () { - function Organization(name) { - this.name = name; - this.listOfEmployees = []; - } - Organization.prototype.createEmployees = function () { - for (var i = 1; i <= 10; i++) { - var emp = new Employee_1.Employee(i, 'A' + i, i * 1000); - this.listOfEmployees.push(emp); - } - }; - Organization.prototype.printEmployeesInfo = function () { - this.listOfEmployees.map(function (emp) { return emp.printInfo(); }); - // this.listOfEmployees.map(function(emp) { - // return emp.printInfo(); - // }) - }; - Organization.prototype.getEmployeeList = function () { - return this.listOfEmployees; - }; - return Organization; -}()); -exports.Organization = Organization; +"use strict"; +exports.__esModule = true; +var Employee_1 = require("./Employee"); +var Organization = (function () { + function Organization(name) { + this.name = name; + this.listOfEmployees = []; + } + Organization.prototype.createEmployees = function () { + for (var i = 1; i <= 10; i++) { + var rating = Math.floor(Math.random() * (5 - 1 + 1) + 1); + var emp = new Employee_1.Employee(i, 'A' + i, i * 1000, rating); + this.listOfEmployees.push(emp); + } + }; + Organization.prototype.printEmployeesInfo = function () { + this.listOfEmployees.map(function (emp) { return emp.printInfo(); }); + // this.listOfEmployees.map(function(emp) { + // return emp.printInfo(); + // }) + }; + Organization.prototype.getEmployeeList = function () { + return this.listOfEmployees; + }; + return Organization; +}()); +exports.Organization = Organization; diff --git a/Day-2/Organization.ts b/Day-2/Organization.ts index 165daaf..2d9cac7 100644 --- a/Day-2/Organization.ts +++ b/Day-2/Organization.ts @@ -8,7 +8,8 @@ export class Organization { } createEmployees() { for (let i = 1; i <= 10; i++) { - let emp: Employee = new Employee(i, 'A' + i, i * 1000); + let rating = Math.floor(Math.random()*(5-1+1)+1); + let emp: Employee = new Employee(i, 'A' + i, i * 1000,rating); this.listOfEmployees.push(emp); } } diff --git a/Day-2/cricket-match/ExecuteMatch.js b/Day-2/cricket-match/ExecuteMatch.js new file mode 100644 index 0000000..dcc6e88 --- /dev/null +++ b/Day-2/cricket-match/ExecuteMatch.js @@ -0,0 +1,6 @@ +"use strict"; +exports.__esModule = true; +var Match_1 = require("./Match"); +var match = new Match_1.Match(); +match.createMatch("IND-NZ-ODI", "ODI", 50); +match.printPlayerInfo("Player 5"); diff --git a/Day-2/cricket-match/ExecuteMatch.ts b/Day-2/cricket-match/ExecuteMatch.ts new file mode 100644 index 0000000..913e8c9 --- /dev/null +++ b/Day-2/cricket-match/ExecuteMatch.ts @@ -0,0 +1,6 @@ +import { Match } from './Match'; +import { Player } from './Player'; + +var match: Match = new Match(); +match.createMatch("IND-NZ-ODI","ODI",50); +match.printPlayerInfo("Player 5"); diff --git a/Day-2/cricket-match/Player.js b/Day-2/cricket-match/Player.js new file mode 100644 index 0000000..e5a45ee --- /dev/null +++ b/Day-2/cricket-match/Player.js @@ -0,0 +1,19 @@ +"use strict"; +exports.__esModule = true; +var Player = (function () { + function Player(id, name, score, balls, wickets) { + this.id = id; + this.name = name; + this.score = score; + this.balls = balls; + this.wickets = wickets; + } + Player.prototype.printInfo = function () { + console.log(this.name + " scored " + this.score + " in " + this.balls + " balls"); + }; + Player.prototype.updateScore = function (score) { + this.score = score; + }; + return Player; +}()); +exports.Player = Player; diff --git a/Day-2/cricket-match/Player.ts b/Day-2/cricket-match/Player.ts new file mode 100644 index 0000000..422aa16 --- /dev/null +++ b/Day-2/cricket-match/Player.ts @@ -0,0 +1,20 @@ +export class Player { + id: number; + name: string; + score: number; + balls:number; + wickets:number; + constructor(id: number, name: string, score: number, balls:number,wickets:number) { + this.id = id; + this.name = name; + this.score = score; + this.balls = balls; + this.wickets = wickets + } + printInfo() { + console.log(`${this.name} scored ${this.score} in ${this.balls} balls`); + } + updateScore(score:number){ + this.score = score + } +} diff --git a/Day-2/cricket-match/match.js b/Day-2/cricket-match/match.js new file mode 100644 index 0000000..6eb9ece --- /dev/null +++ b/Day-2/cricket-match/match.js @@ -0,0 +1,30 @@ +"use strict"; +exports.__esModule = true; +var Player_1 = require("./Player"); +var Match = (function () { + function Match() { + } + Match.prototype.createPlayers = function () { + this.listOfPlayers = []; + for (var i = 1; i <= 11; i++) { + //let Score = Math.floor(Math.random()*(5-1+1)+1); + var player = new Player_1.Player(i, "Player " + i, 100, 72, 0); + this.listOfPlayers.push(player); + } + }; + Match.prototype.createMatch = function (matchName, matchType, overs) { + this.createPlayers(); + this.matchName = matchName; + this.matchType = matchType; + this.overs = overs; + }; + Match.prototype.printPlayerInfo = function (playerName) { + for (var i = 1; i <= 11; i++) { + if (playerName == this.listOfPlayers[i].name) { + this.listOfPlayers[i].printInfo(); + } + } + }; + return Match; +}()); +exports.Match = Match; diff --git a/Day-2/cricket-match/match.ts b/Day-2/cricket-match/match.ts new file mode 100644 index 0000000..8e630e3 --- /dev/null +++ b/Day-2/cricket-match/match.ts @@ -0,0 +1,31 @@ +import { Player } from './Player'; +export class Match{ + + matchName:String; + matchType:String; + overs:number; + listOfPlayers:Player[]; + createPlayers(){ + this.listOfPlayers = []; + for (let i = 1; i <= 11; i++) { + //let Score = Math.floor(Math.random()*(5-1+1)+1); + let player: Player = new Player(i, "Player "+i, 100,72,0); + this.listOfPlayers.push(player); + } + } + createMatch(matchName:string, matchType:String, overs:number){ + this.createPlayers(); + this.matchName=matchName; + this.matchType = matchType; + this.overs=overs; + } + printPlayerInfo(playerName:String) { + for (let i = 1; i <= 11; i++){ + if(playerName == this.listOfPlayers[i].name){ + this.listOfPlayers[i].printInfo(); + } + } + + } + +} \ No newline at end of file diff --git a/Day-2/salary-updater.js b/Day-2/salary-updater.js index a3a77b9..59f7902 100644 --- a/Day-2/salary-updater.js +++ b/Day-2/salary-updater.js @@ -1,10 +1,11 @@ -"use strict"; -exports.__esModule = true; -var Organization_1 = require("./Organization"); -var salary_upgrader_1 = require("./salary-upgrader"); -var org = new Organization_1.Organization('ABC'); -org.createEmployees(); -org.printEmployeesInfo(); -var salaryUpgrader = new salary_upgrader_1.SalaryUpgrader(); -salaryUpgrader.incrementSalary(10, org.getEmployeeList()); -org.printEmployeesInfo(); +"use strict"; +exports.__esModule = true; +var Organization_1 = require("./Organization"); +var salary_upgrader_1 = require("./salary-upgrader"); +var org = new Organization_1.Organization('ABC'); +org.createEmployees(); +org.printEmployeesInfo(); +var salaryUpgrader = new salary_upgrader_1.SalaryUpgrader(); +salaryUpgrader.incrementSalary(10, org.getEmployeeList()); +salaryUpgrader.addBonus(org.getEmployeeList()); +org.printEmployeesInfo(); diff --git a/Day-2/salary-updater.ts b/Day-2/salary-updater.ts index 159e761..fe73255 100644 --- a/Day-2/salary-updater.ts +++ b/Day-2/salary-updater.ts @@ -6,5 +6,6 @@ org.createEmployees(); org.printEmployeesInfo(); let salaryUpgrader: SalaryUpgrader = new SalaryUpgrader(); salaryUpgrader.incrementSalary(10, org.getEmployeeList()); +salaryUpgrader.addBonus(org.getEmployeeList()); org.printEmployeesInfo(); diff --git a/Day-2/salary-upgrader.js b/Day-2/salary-upgrader.js index cc82f12..c18cc44 100644 --- a/Day-2/salary-upgrader.js +++ b/Day-2/salary-upgrader.js @@ -1,17 +1,41 @@ -"use strict"; -exports.__esModule = true; -var SalaryUpgrader = (function () { - function SalaryUpgrader() { - } - SalaryUpgrader.prototype.incrementSalary = function (percentRaise, empList) { - empList.map(function (emp) { - var oldSalary = emp.getSalary(); - var newSalary = (oldSalary * percentRaise / 100) + oldSalary; - emp.updateSalary(newSalary); - }); - }; - SalaryUpgrader.prototype.addBonus = function () { - }; - return SalaryUpgrader; -}()); -exports.SalaryUpgrader = SalaryUpgrader; +"use strict"; +exports.__esModule = true; +var SalaryUpgrader = (function () { + function SalaryUpgrader() { + } + SalaryUpgrader.prototype.incrementSalary = function (percentRaise, empList) { + empList.map(function (emp) { + var oldSalary = emp.getSalary(); + var newSalary = (oldSalary * percentRaise / 100) + oldSalary; + emp.updateSalary(newSalary); + }); + }; + SalaryUpgrader.prototype.addBonus = function (empList) { + empList.map(function (emp) { + var oldSalary = emp.getSalary(); + var bonusAmt = 0; + switch (emp.getRating()) { + case 5: { + bonusAmt = 100000; + break; + } + case 4: { + bonusAmt = 75000; + break; + } + case 3: { + bonusAmt = 50000; + break; + } + default: { + bonusAmt = 0; + break; + } + } + var addBonus = oldSalary + bonusAmt; + emp.updateSalary(addBonus); + }); + }; + return SalaryUpgrader; +}()); +exports.SalaryUpgrader = SalaryUpgrader; diff --git a/Day-2/salary-upgrader.ts b/Day-2/salary-upgrader.ts index 7d66855..effbb93 100644 --- a/Day-2/salary-upgrader.ts +++ b/Day-2/salary-upgrader.ts @@ -10,7 +10,31 @@ export class SalaryUpgrader { emp.updateSalary(newSalary); }) } - addBonus() { + addBonus( empList: Employee[]) { + empList.map(emp => { + let oldSalary = emp.getSalary(); + var bonusAmt:number=0; + switch(emp.getRating()){ + case 5:{ + bonusAmt = 100000; + break; + } + case 4:{ + bonusAmt = 75000; + break; + } + case 3:{ + bonusAmt = 50000; + break; + } + default:{ + bonusAmt =0; + break; + } + } + let addBonus = oldSalary+bonusAmt; + emp.updateSalary(addBonus); + }) } } \ No newline at end of file diff --git a/Day-2/test.html b/Day-2/test.html new file mode 100644 index 0000000..2416b6c --- /dev/null +++ b/Day-2/test.html @@ -0,0 +1,19 @@ + + + Sample HTML page + + + + +
+ + +

please check output in console

+ +
+ +
+ +
+ + \ No newline at end of file