BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

计算机代写|Comp 313/413: Test 2 Practice Exam

计算机代写|Comp 313/413: Test 2 Practice Exam

这是一篇来自美国的关于解决下面一些问题的测试计算机代写

 

Problem 1

a.TRUEor FALSE (circle one)? To add another shape (such as Ellipse) to the graphical shapes in project 3, we must add the corresponding Shape implementation  No changes to existing classes or interfaces are required.

b.TRUEor FALSE (circle one)? To add another capability (a Visitor such as BoundingBox) to the graphical shapes in project 3, we must define the corresponding method in the Shape interface and implement it in all classes that implement this

Problem 2

In this test, we will look at a data structure for representing containers of items produced by a 3D printer. The overall interface for these containers is here:

interface Container {

int size(); // # of 3D-printed items in the Container Container  duplicate(int factor);

// duplicates the number of Items by the factor, presumably by 3D-printing them  void   collect(Collection<Item>   warehouse);

//  moves  all   3D-printed  Items  in  the  Container  into  the  given  warehouse

}

 

a.First, complete the following class for representing individual3D-printed items in a  abstract class Item implements Container {

@Override public int size() { // TODO

 

}

@Override public Container duplicate(final int factor) { /* TODO in 2d) below, not here */ }

@Override public void collect(final Collection<Item> warehouse) { // TODO

 

}

}

// Here are some concrete 3D-printed items to package up and put in the warehouse:

class Gear extends  Item  {  /*  intentionally  left  empty  */  } class  Flange  extends  Item  { /* intentionally  left empty  */ }\

 

b.Next, complete the following class to collect up multiple  Containers of 3D-printed class Carton implements Container {

public Carton(final Container… contents) { this.contents = Arrays.asList(contents); } private final List<Container>  contents;

public List<Container> getcontents() { return contents; }

@Override public int size() { // TODO

 

}

@Override public Container duplicate(final int factor) { /* TODO in 2d) below, not here */ }

@Override public void collect(final Collection<Item> warehouse) { // TODO

 

}

c.Now,complete the following class for representing multiples of the same sub-container in a compact  Concretely, a Crate node makes its contents (sub-container) appear howmany times for the purpose of the operations size and collect. The size of each Crate node is the actual size of the node’s contents times the multiplier; e.g., Crate(4, Carton(Gear, Flange)) has size 8.

class Crate implements Container {

public Crate(final int howmany, final Container contents) { this.howmany = howmany; this.contents = contents;

}

private final  int  howmany; private final Container  contents;

public  int  getMultiplier()  {  return  howmany;  }

public Container getcontents() { return contents; }

@Override public int size() { // TODO

 

}

@Override public Container duplicate(final int factor) { // TODO

// duplication occurs here!!! use a suitable new multiplier in the result

 

}

@Override public void collect(final Collection<Item> warehouse) { // TODO

 

}

d.Implement the duplicate methods for Itemand Carton Keep your code as simple as possible. Hints: these are simple methods; introduce new Container nodes as appropriate.

/* Item: */ @Override public Container duplicate(final int factor) { // TODO

 

}

/* Carton: */ @Override public Container duplicate(final int factor) { // TODO

 

}

e.Usingthe classes CartonGear, and Flange, write code that builds the following hybrid Container:

    • ashipping container (main Carton) of the Container
      • asub-carton with three separate Gears (without any Crate)
      • another sub-cartoncontaining

∗ a Crate of one Gear

∗ a Crate of two Flanges

final Carton shippingContainer = new Carton( // TODO

 

);

f.Whatis the size of this Container, e., what should shippingContainer.size() return?

g.Whatis the result of collecting the Item in this Container, e., what will be in the warehouse after executing final List<Item> warehouse = …; shippingContainer.collect(warehouse);?

 

h.Whatis the size of the Container after having duplicated it fourfold by evaluating shippingContainer.duplicate(4);,  i.e.,  what  should  shippingContainer.size()   return now?

i.Whatare the two software design pattern underlying the Container interface and its implementation classes called? Circle exactly  Composite Strategy Decorator Abstract Factory

j.TRUEor FALSE? (circle one)? Containers with Crates can always be replaced by Containers with explicit multiples instead of Crates?

k.Whichis the relevant software design principle for the requirement in the preceding subproblem jCircle exactly 

Design by Contract Single Responsibility Principle Moore’s Law Liskov Substitution Principle

i.TRUEor FALSE (circle one)? To add another kind of Container (such as a new type of Item), we must add the corresponding Container implementation  No changes to existing classes or interfaces are required.

m.TRUEor FALSE (circle one)? To add another capability (such as collect) to these Containers, we must define the corresponding method in the Container interface and implement it in all classes that implement this interface.

bestdaixie

评论已关闭。