EX11

tz33quvu
Windoof-User
Windoof-User
Beiträge: 40
Registriert: 29. Jan 2017 09:26

EX11

Beitrag von tz33quvu » 1. Feb 2018 09:27

Hi,

I got some questions here:

1)What does copy method do? In which scenario it should be used?

2) So the whole Formula class works like

Code: Alles auswählen

    val f = new Formula
    var nextPlaceHolder = f.findNextPlaceholder.get //root
    val add = new Add(Placeholder(),Placeholder())
    val + = f.replace(nextPlaceHolder,add)
    val n1 = Number(1)
    nextPlaceHolder = f.findNextPlaceholder.get
    f.replace(nextPlaceHolder,n1)
    val n2 = Number(2)
    nextPlaceHolder = f.findNextPlaceholder.get
    f.replace(nextPlaceHolder,n2)
and the result should be 1+ 2 ??

3) If our formula contains variable, how would the evalutae result be? so like (x + (3+4)) then the result should be x + 7?

thx in advance!

meichholz
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 167
Registriert: 30. Mär 2016 08:28

Re: EX11

Beitrag von meichholz » 1. Feb 2018 13:31

Hi,
tz33quvu hat geschrieben:
1. Feb 2018 09:27
1)What does copy method do? In which scenario it should be used?
This is explained on the latest version of the exercise sheet.
tz33quvu hat geschrieben:
1. Feb 2018 09:27
2) So the whole Formula class works like
CODE: ALLES AUSWÄHLEN
val f = new Formula
var nextPlaceHolder = f.findNextPlaceholder.get //root
val add = new Add(Placeholder(),Placeholder())
val + = f.replace(nextPlaceHolder,add)
val n1 = Number(1)
nextPlaceHolder = f.findNextPlaceholder.get
f.replace(nextPlaceHolder,n1)
val n2 = Number(2)
nextPlaceHolder = f.findNextPlaceholder.get
f.replace(nextPlaceHolder,n2)
and the result should be 1+ 2 ??
Looks correct.
tz33quvu hat geschrieben:
1. Feb 2018 09:27
3) If our formula contains variable, how would the evalutae result be?
If the environment doesn't contain a mapping for a variable, you can just throw an exception.

Best,
Matthias

Antworten

Zurück zu „Archiv“