Question: Question: View: a class with one field private List models and 3 methods: public void Attach ( Model m ) public void Detach ( Model

Question:
View: a class with one field private List models
and 3 methods:
public void Attach(Model m)
public void Detach(Model m)
public void Notify(int s)
ConcreteView: a class inheritents from View,
one field
private int state =0;
and two methods:
public int GetState()
public void SetState(int s)
Model: an abstract class with one abstract method:
public abstract void Update(int s);
ConcreteModel: a class inheritents from Model.
two fields
private int state;
private ConcreteView view;
one method
public void Update(int s)
Task: finish implementing the code and run the main method below.
public static void main(String[] args){
// TODO Auto-generated method stub
Random r = new Random();
int max =100;
int min =0;
View v = new ConcreteView();
Model m1= new ConcreteModel(352, v);
v.Attach(m1);
for(int i =0; i <10; i++){
int temp = r.nextInt((max-min)+1)+min;
Model m = new ConcreteModel(temp, v);
v.Attach(m);
}
List models = v.getModels();
System.out.println("Size of models "+models.size());
v.Detach( m1);
System.out.println("Size of models after delection "+models.size());
v.Notify(max);
ConcreteView v2=(ConcreteView) v;
System.out.println("Current State is "+v2.GetState());
}
Sample Output:
Size of models 11
Size of models after delection 10
Current State is 100

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!