Exercism.org-Java-Cook your lasagna

https://exercism.org/tracks/java/exercises/lasagna

Instructions

In this exercise you’re going to write some code to help you cook a brilliant lasagna from your favorite cooking book.

You have four tasks, all related to the time spent cooking the lasagna.

1. Define the expected oven time in minutes

Define the expectedMinutesInOven() method that does not take any parameters and returns how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:

1
2
3
4
5
Lasagna lasagna = new Lasagna();
//Create a Lasagna object using the new keyword
lasagna.expectedMinutesInOven();
//Invoking the expectedMinutesInOven() method in the Lasagna
// => 40

2. Calculate the remaining oven time in minutes

Define the remainingMinutesInOven() method that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.

1
2
3
4
Lasagna lasagna = new Lasagna();
lasagna.remainingMinutesInOven(30);
//Invoking the remainingMinutesInOven() method in the Lasagna
// => 10

3. Calculate the preparation time in minutes

Define the preparationTimeInMinutes() method that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.

1
2
3
Lasagna lasagna = new Lasagna();
lasagna.preparationTimeInMinutes(2);
// => 4

4. Calculate the total working time in minutes

Define the totalTimeInMinutes() method that takes two parameters: the first parameter is the number of layers you added to the lasagna, and the second parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes in total you’ve worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.

1
2
3
Lasagna lasagna = new Lasagna();
lasagna.totalTimeInMinutes(3, 20);
// => 26

Question Answers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Lasagna {
// TODO: define the 'expectedMinutesInOven()' method
public int expectedMinutesInOven(){
return 40;
}

// TODO: define the 'remainingMinutesInOven()' method
public int remainingMinutesInOven(int time){
return expectedMinutesInOven() - time;
}

// TODO: define the 'preparationTimeInMinutes()' method
public int preparationTimeInMinutes(int layers){
return layers*2;
}

// TODO: define the 'totalTimeInMinutes()' method
public int totalTimeInMinutes(int layers,int time){
return preparationTimeInMinutes(layers)+remainingMinutesInOven(time);
}
}

Word

Instructions
n.
(计算机的)指令;指示;说明书;命令;操作指南;吩咐;用法说明
instruction的复数

brilliant
adj.
明亮的;很成功的;很好的;巧妙的;聪颖的;技艺高的;使人印象深的
n.
宝石;钻石

lasagna
n.
(意大利)千层面

task
n.
任务;(尤指艰巨或令人厌烦的)工作;(尤指语言教学中旨在帮助达到某一学习目的的)活动
vt.
交给某人(任务);派给某人(工作)

relate
vt.
联系;讲(故事);把…联系起来;叙述;使有联系;讲述

expect
v.
预期;预计;期待;要求;指望;预料;等待;盼望;猜想

expected
adj.
预期的;预料的
v.
预期;预计;期待;要求;指望;预料;等待;盼望
expect的过去分词和过去式

oven
n.
烤箱;烤炉

remaining
adj.
剩下的;仍需做的;还需处理的
v.
仍然是;剩余;保持不变;遗留;继续存在;仍需去做(或说、处理)
remain的现在分词

actual
adj.
实际的;(强调事情最重要的部分)真正的,…本身;真实的

remain
v.
(事实、问题等)仍然是(表示强调);剩余,余留;保留,坚持(观点、态度或信念);保持不变;仍然存在,继续存在;留下,逗留,停留;(最后)属于;(最后)取决于;尚待,留待;仍需去做(或说、处理)
n.
剩余物,残余(物);遗体,残骸;(历史)遗迹,残迹

previous
adj.
以前的, 先前的, 以往的;上一次的, 上一个的;<口>过早的, 过急的;(时间上)稍前的

preparation
n.
准备;(医药、化妆品等)配制品,制剂;准备工作;预备

layers
n.
层;表层;层次;阶层
v.
把…分层堆放
layer的第三人称单数和复数

assuming
conj.
假如;假设…为真
v.
假设;假定;承担(责任);认为;呈现(外观、样子);取得(权力);显露(特征);就(职)
adj.
傲慢的
assume的现在分词

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

You Found Me.

支付宝
微信