Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PaymentProcessor {
- constructor (types,precision) {
- this.types=["service", "product", "other"];
- this.precision=2
- // let obj={id:"string", name:"string", type:"string", value:"Number"}
- this.prop=[]
- }
- deletePayment(idss) {
- this.prop.forEach(element => {
- let err ='p';
- if (element.id===idss) {
- this.prop.pop(element)
- err='s';
- }
- throw new Error(`Entity with id: ${idss} does not exist!`)
- });
- if (err=='p') {
- }
- }
- get(ids) {
- let ret =''
- let name2 =''
- let typ=''
- let balance=0
- this.prop.forEach(element => {
- if(element.id===ids)
- {
- ret=ids
- name2=element.name
- typ=element.type
- balance=Number(element.value)
- }
- });
- if (ret==='') {
- throw new Error(`Entity with id: ${ids} does not exist!`)
- }
- return `Details about payment ID: ${ret}\n- Name: ${name2}\n- Type: ${typ}- Value: ${balance.toFixed(this.precision)}`
- }
- registerPayment(id1,name1,type1,value) {
- this.prop.forEach(element => {
- if(element.id===id1)
- {
- throw new Error(`Entity with id: ${id1} exist!`)
- }
- });
- let num=Number(value)
- let obj = {id:`${id1}`, name: `${name1}`, type:`${type1}`, value:num}
- this.prop.push( obj)
- }
- toString() {
- let sum =0
- this.prop.forEach(element => {
- sum =sum+element.value
- });
- let str = `Summary:\n- Payments: ${this.prop.length}\n- Balance: ${sum.toFixed(this.precision)}`
- return str
- }
- setOptions(op1,op2) {
- this.types=op1
- this.precision=op2
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement