注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
1.You're asked to write a controller for a sorting machine for Christmas decorations.
Decorations arrive at the scanner, and the percentages of red and green are reported.
Your must write a program that sorts the decorations into one of three bins:
Red, if the decoration is more than 35% red
Green, if the decoration is more than 30% green
Reject, if the decoration is both more than 35% red and 30% green - these are just too "loud".
The interfaces you have are the following:
interface ScannerAndSorter {
// Read and scan another item; return false when there are no more
// items.
bool nextItem();
// Percentage (0-100) of the current item that's red.
double redPercentage();
// Percentage (0-100) of the current item that's green.
double greenPercentage();
// Send the current item to the Red bin
void sendToRed();
// Send the current item to the Green bin
void sendToGreen();
// Send the current item to the Reject bin
void reject();
}
class DecorationSorter {
ScannerAndSorter sorter;
public DecorationSorter(ScannerAndSorter sorter) {
this.sorter = sorter;
}
// Sort the decorations that 'sorter' reads.
void sort() {
... fill this in ...
}
}
Implement the sort() function.
2.A maze is a group of linked Places. Each Place has a North, South, East, and West Place adjacent to it. There are two special pre-defined Place's:
Place Wall represents a wall - the mouse can't go there. Place Cheese is ... cheese! The connections between Places are symmetrical - if you start
from any Place and go North and then South, you return to where you were. To simplify things, the maze has no closed loops - that is, if you start in
any Place and follow any path, yo您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 使用VIP即刻解锁阅读权限或查看其他获取积分的方式 游客,您好! 本帖隐藏的内容需要积分高于 188 才可浏览 您当前积分为 0。 VIP即刻解锁阅读权限 或 查看其他获取积分的方式 int, will reach a Place where isCheese() is
// true. Return null if you can't find such a path.
public String findCheese(Place startingPoint) {
... fill this in ...
}
}
Implement findCheese(). You can add any fields or helper methods you need to Mouse.
Extra credit: Eliminate the "no closed loops" restriction. That is, change
your code so that it works correctly even if there might be a path like SSNEEW that leads the mouse back to the Place it started from.
|