Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Spamming

- Coding

DESCRIPTION

Complete the classes using


the Specifications given below. Consider default visibility of
classes, data fields, and methods unless mentioned otherwise.

Specifications

class definitions:
class SpamDetector:
data members:
int PrimaryCount
int PromotionCount
int UpdateCount
visibility: private
__. ,:- A.uto Implemented properties

SpamDetector( int PrimaryCount, int PromotionCount, i

method definition:
Addmessage( String Email) :
return : String
visibility: public
int PrimaryCount
int PromotionCount
int UpdateCount
visibility: private
U':ir Auto Implemented properties

SpamDetector( int PrimaryCount, int PromotionCount, int

method definition:
Addmessage(String Email) :
return : String
visibility: public

class SpamAttackException: Exception :


method definition:
SpamAttackException(l ring Message) : base(Message
visibility: public

class SuspendException: Exception :


method definition:
suspendException(String Message) : base(Message)
visibility: public

"

p
Class SP-amDetector
l:i:

I - - •
I • I I
-
• I
~ ,,~~·v,rw·r>--- - ~-

Class ~RamDetector

- define all the variables and constructors according to the


above specifications.

Implement the below methods for this class:

-String AddMessage(String Email}_; ·

• Write a code that updates the Email type count ori th~
basis of the following-
. . .
.

1. If the Email contains ar{) of,tHe'. e1ements in the list , . ,,


I .I I I, 1, '
I 'II

["offer", "bonanza", "sal.e"/'Hur~,y"] then update . I I


I
1...
11

II
,.11
' :1:
,111

,1
!1

PromotionCount with t , , , .. i' '


• . · 11 'I 1
1
11
1 1
,1 , • , '':,,, ' , ,_, , .
11
. " ' ·II' I I ,: '' 1111
' I , 'I'' '1' · I' 11 , ' ,
Ii',,/ JI I I ' ii, , " "

2..Else If the Email con,tains ~~~,1 o{t~~ ~,lements irit~~,:11


' ' • • I I -;- ! 11 II :,
1

1i~t\, 11

,I 11 . .l1 . 1
1

1' : ,,,"
,I,.

, ' , ' ' ' ' ' ! I i'' II ' I ' , \ :;:: ,,,

["excel'~ "word", "ppt", "update'a:'~~l~n,,upda~e' ' . ,· ! I'' '· ,I ,, ,, I '· I,


I

• 11 I ,! I •

. UpdateCount with 1 ·
1
11 11

,J'
1

I',
1

i"1' ,1 ' 11 ,',,::


I I 11 11 l,i 11

I., Ii
I ','

' , i' 111 r' 1

,I I .,

3. Else update PrimaryCount by'1. Iri'·':.'{


1

,/' ii",, ,, · ,, ,
, '
1
'Ii /I''," 1 , t'1
1
,
1

1
1(r ,ii} 1
A/I· ii ·I
. .r i/J , i}jt,\ 11(11 . ,,,
. • ' 1lf 'i ' L:1" I I' I 111 ! . !

• After ·Updating the CountGheclt l]elbw'conclitions ,:i-


. .,; l I 11 ', 1llill1 :1,1 ,, •
1


T , I ,Jil l
i
Ir' r ' iI
• . . 1
' ',

. ' ' ,,,,11 ·,,, ,11:


' I II"' II I ! ,/

1. If the PromotionCount >_URdateC:ouArt > Rrima.ryCount 1


,,,, jl I I• • • !

th~i,.ttirOw Suspen~Exception 'with a m~ssage (''ACcourit


UpdateCount with 1
3. Else update Pr imaryCount by 1.

• After Updating t he Cou nt Check below cond itions -

1. If the PromotionCount > UpdateCount > PrimaryCount


then throw Suspend Exception with a message ("Account
Suspended").
2. Else If the PromotionCount > ((PrimaryCount +
UpdateCount)*0.75) then throw SpamAttackException
with a message ("Account in Attack'').
3. Else return "Safe".

Class SusQendExceQtion
i 11
, I
Ii , ; ,

'! I, :
!: I :
- - ., ;:·: '., _ :1 I .
- define SuspendException g]as s,ct~' 'i v~"d from the Exception
1

class.

Class SP-amAttackExceQtion

- define SpamAttackException class derived from t he -


• • I •

Exception class ..

Sample Input

SpamDetector spamDetector = new SpamDetector( l0 , 10, 19


spamDetector .Addmessage(
11
' I ,l·1, nt~ 21 11
)
Sample Output

1111,'

.111111 ,111111,1·
1111

NOTE:
1111 i1w1

,,1
,, 11111
111 , 111111
• • 111
111
111111
,1, iilll;I ,,, 1:1111 I
1 1 1
' ,1111 -111111 "' '
11111111 , . I' .
You can make suitable.fune'ti·on d use the RU N-
1
11111
1 1

l/!s 11'1
11
e • • I
1
:
11
' ii' ' '.'

CODE button to checkV~ · od output.


f
EXECUTI ON TIME LIMIT · cc

5 seconds

'.I
1
< PREVIOUS ,PROBLEM
--

. \
I
I < PREV

Digital India
- Coding

DESCRIPTION

Complete the classes using


the specifications given below. Consider default visibility of
classes, data fields, and methods unless mentioned otherwise.

Specifications

data member:
string[] Patterns
visibility: public

method definition:
Credit(f l oat amount)
r--eturn : float
visibility: public
Credit( string pattern, float amount)
return :float
visibility: public
Credit( string pattern, float amount, i nt tax)
r ~+11rn • fln.::1 +
data member:
string [] Patterns
visibility : ', l j_c

method defi nition:


Credit( amount)

visibility: public
Credit( string pattern, f l~ at amount)
1· _ ·':
1
I"n : float
visibility: public
Credit( string pattern, float amount, int tax)
-·: •,-.:· : float
visibility: public

Class Payment

~define data members


.
as per the given specifications.
.

• lniti.alize Patterns with value = {"#go#ogle#upi",


• ' t •

''@phone$Pay#upi", "!amazonApay%'\ '.'bharat$upi&"}

-Implement the below methods forth is class:

~float ·cred_it (float amount)~


Class PaY-ment

-define data members as per the given specifications.

• Initialize Patterns with value= {"#go#ogle#upi~',


"@phone$Pay#upi", "!amaz<!'"pay%",_~'bharat$~upi&"}
'
' II

-Implement the below methods for this class:

-float Credit(float amount)~ -


111
,Ill I
, 'II

• Write a code that returos ,110%,of the parameter I • I ·111

amount.

at_
-float Credit(st~ing_.g___ · . . . . .,. . .

1
• · Write a code that chet '"San)i\ /;l
• • I 1i!• , ,' ,' t ur.ir the !'Iii" ,I;
amount as it is if -

the pattern(string) giVen ih :th~ fi:kictionpara~eter c~n


.. ' I! ,II ",I: !,I .
• , • • i1 1ili1t i''I.. .:11: .; ,:,. - . -· -, .

be created using the charact~:r s ~f:: any 9f,the._ ,., .


· 1.

1
II ·1 11111 ' I' :11: I' • f :I

:patterns(string} from.the·Pa~tern~ Ust, el~.e r~·turn 110%-


, ' ' . ' . - ' ' ' ,'. ,,. ' t \ "'ill ,1 , , 1' '. ' ' - ' I

of the am_
ount. 1 •• ,

I'

.
' '
\
II J -1'I I t • II . ' ,
11 ' 1
be created using the characters of any of the
patterns{string) from the Patterns list, else return 110%
of t he amount.

Given pattern "goog/e". It will returns the given amount only as


this string can be created by using the characters of the one of
the pattern in the Patterns array "#go#og/e#upi".

-float Credit(string_gattern, float amount, int tax)~

• Write a code that checks if the given parameter pattern


is equal to any one of the patterns in the Patterns array
then it returns the amount else it returns amount+tax.

Sample Input 1

Payment payment= new Payment();


f-!_ ,~: d = payment.Credit( google" ., 99.0f);
11

Console.Writeline(d);

Sample Output 1
then it returns the amount else it returns amount+tax.

Sample Input 1

Payment payment= new Payment();


1
,_,at d = payment. Credit( go r le
II II , 99. 0f );
Console.Writeline(d);

Sample Output 1

Sample Input 2

Payment payment= new Payment();


~--1 Jat d = payment. Credit ( ! amazonJ\pay 99 . 0f, 10);
11 11
,

Console.Writeline(d);

Sample Output 2
Sample Output 2

NOTE:

• You can make suitable.function calls -and use the RUN


• ,, II '

CODE button to check your mai.n() method output. ;;'

EXECUTI O N TIME LIM-11\

5 seconds . ' .
-
;_ :
-
=-- =
-
"" C -

I '• ' '

Having an issue with .this qu;~~ti9n? O Report

. !
< PREVIOUS l?ROBLEM -FINISH AND ~
"
... - ,..,,_,,.,,,_,,, .._, "'' """-""'' """- .,,,,. ..... ,,.... ,,,, ..... ,, . .....,.,
,
1• ., ;;1'

111 i Ii •
' II• I I' I, I :1
1' Ill I 11 I 'I
I, Ii Ill I 11·: ii !I' 'I 'I
1
' i
1 111 '' Ii
Sample Output 2

NOTE:
..

• You can mak.e suitablefundio~ ~~11s and use t~ e RUN


• I I', I Ii f' . I

CODE button to check:i q':y:,~,'', iiai,'o,O:method output.


'/:tt/i1/),,, '1

,I ;i' ,II / ( 1• J
I

11
1'(11 /!' 1i1i1

EXECUTION TI ME LIMIT , :::;}(;.,,, 11 /

1
I 11 I' I

',
11li l,1i 1, ' ',I I
' ,I

5 Seconds ii
11 ii ,,,,,, , '/, '," !
;I

I I 1i
i1

i ' 1/ II '
1
'

Having an i·ssue with this question?-


• ,, ,
. ,:'Re'pO(t '.
1
I Ji' 11 I •
11 11
'~' 1" '11 ·• a- ,, ,!1'1 111"'1!' ill'1ll'i\1'' ·1,-111 ,1,--11'1 '"-- 1' ,.. , '!, - - -i~~,t-,,:L~-- ,,,- .=c-,~~- " - - - ~ ~
1 ' ' I II :I i j' I' 11
1 1 11
11 11 11 ! I 1i,
II I· ·11 II .
' •I

II < PREVIOUS P~,OB~E,tyl,/


, , I Ii
11 I. .:1

'I ,'
1

,. FJNISH AND SUB.


. I 11
I
• - ~ _..... , .. ,..,,~m'-"•-4'-""•""""•!m•·"'-•"'-•''•'•",~•'•'-•""" ·,,i' " ' · ;ti ,I
q I /

,I 11 ·1
ti ,: 11, 11

, II I .I /,III 1[
I 1 ,II ![
1
, 11· / 1' II
I I I I 111' II
I, I II
, 11
I < PREV

Summing Prime [
- Coding

DESCRIPTION

Problem Statem·ent

You are given a number n. You·have to tell whether it is


possible to express that number as a sum of two prime
m of a prime and non-prime·numqer
numbers as well as the su_
$eparately~
I •I
' '

·Return "Yes" if it is possibte·i_:)


""
1

,:,,,,, JSe.return
:· " . ,"No". (without . -
_
-

quotes)
, -· ·,· .. ·!,

Note-: A number is s~idfo ~;:t~,Prirrie number ifit has only 2


positive factors which is·1 andthe number itself.

Input Format -
I ,. .f

,. i' -~ •i'
' .;

, ... i

• First-line of input contains an integern. \


I

i,·; • , .
• •

. . I

;"
ii 1,

I
I, ,t , .-1
1 I II I

I , • 'r l,1i

Constraints
1
• I
I lfl'li I ;11·11 )1
1
1'1
I , 1111 I
I 1,11
1,
Problem Statement

You are given a number n. You have to tell whether it is


possi ble to express that number as a sum of two prime
numbers as wel l as the sum of a prime _
and non-prime number
separately.

Return "Yes" if it is possible, or else return "No". {without


quotes)

Note-: A number is said to be a prime number if it has o·n1·y 2


. '

positive factors which is 1 and the number itself.


_i'•_

Input Format i ii

• First-line of input . " \. --'t_eger n.

Constraints

• 1 < n < 105 ! j

Ii

' I

Output Format /,

• Return the string asirequired;. _, · . ,1 ·:, ., ! •

!' 'f

' ' I •

Evaluation Para.meters
11 ' 11
( . I I I .; ; ' I II J
. I 1111
, ~,1:. l ,
'I I

I-
I ' -~ '.
Input t-ormat

• Fi rst -l ine of input contains an integer n.

Constraints

• 1 < n < 105

Output Format

• Return the string as require.d.

Evaluation Parameters

• Sample Input

• Sample Output

• Explanation

5 can be expressed as 1 + 4 and 2 + 3.


. \
• Sample Output

• Explanation

5 can be expressed as 1 + 4 and 2 + 3.

EXECUTI ON TI M E LIMIT .

5 seconds

Having an issue with th is .question? O Report .

- ---·
-·-· ~- _PREVIOUS PROBLEM .:
,-I'l__-• __ FINISH AND SU

,, '
I ,,

,,,
. \
I
1111

;II
,I
I
'I
'11

I
~:.t.YYf:15.idi>:;g~.;t'~~~-- !'~'"L:~~..,;_:~:a-~r·._;:~
CODE: INPUl OU, Pl 11
C# ..... 0 R.'-lH ( . on~ "'". ' l"t ~\l", •
1 - us ing System;
2 us ing Syst:em.Collections .Ge n e r1c;
3 us ing System.IO;
4 us ing System . Linq~
5
6T class SpamDetector{
7 / / Code Here ..
8 }
9
10 T cla s s SpamAttackException Exception{.
11 I / Code Here . .
I
12 }
13
14• cl as s SuspendException Exception{
15 I /C ode Here.:.
l6 }
17
18 ... c l a ss Source {
-19 .,. stat ic void Main( stringt1 args) \
I * Enter your code here. Read in~ut. from S,t)1.~. ~r-i.nt. O\l~ ~u'- t.o S\t
20
21 }
...
22 I
}
.; J:
~11
l "--' V l'l ::>VLV t u I
CODE INPUT OUTPUT C# ,.. O, R UNC.0 0 £ =-, \I£~,~~ .•
l • usi ng System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5
6• class Payment{
7 II Code here
8 .}
9
1
10 ... class Sour,ce {
11 • static void Matn( string() args) {
12 / * Enter your .. code here. Read input. from S\1)1.\-1. ?rint. out.\mt. t o '
13 }
14 }
15
class Result {
/*
* Complete the 'summingPr i me ' f u nc tion below .
*
* The function :fs expected to retu rn a n StRING .
* The function accepts INTEGER n as pa rameter .
*
*I
G
pu blic static string summingPrime( int n) {
// Write your code here
}
}
public c~ass Source {
public static void Main( string() args) {
•• • __ /'\. T ...... ~w,(\\•
.----~- ·-=,<...,,."~-
I•
t ornr,) , ..t,,. ti-.e
:;.,;...,...11..,.gPr:,. - ... .c
+ The funct.i or-
is ewce ~t e d t~ ~-tur
.. The -functio,-, ~--· <',i~lW
acceo~c; 1 -1,E Gt.~ .... ~·::- p ~r .,:\f'f',c1,4 o.-
*
*/
p ubli c static string s umrnin gPrime (int n ) \
// Wri t e yo u r code here
}
}
I
p u b l i c class Source {
pub l ic static void Main( stringt 1 args ) {
int n ' = Convert.Tolnt32(Console. Readline \).1,im \))~
str i ng result = Result.summing?rime (n)~
Console.Writeline(result);
.}
}

You might also like