Java代写:CSCI1110_A2

# CSCI 1110

Assignment 02

Please start this assignment early ; programming and logic take time - if you leave it to the last
minute, you might not have enough time to finish or might make silly mistakes that you otherwise
could avoid. Note that TAs and Instructors will not be able to answer last-minute questions!

All work is to be handed in Mimir, our online code learning environment. You should, however,
write your code on an IDE such as IntelliJ.

To complete this assignment, you will need to know about:

  • Basic Java
  • Conditionals
  • Boolean Variables
  • Simple Input Validation
  • Loops
  • Methods
  • Basic Objects and Classes
  • Instance Methods
  • Overloading

This is your first assignment with objects. The test cases from now on are slightly different. Some
test cases will be regular input/input as before; however, most tests cases will be unit tests. In
unit test cases there is no input from the user. The test can evaluate your code directly without
any user input when needed. The tests can also test methods individually as long as your code is
compiling
. Before you can even try to test your code it must be compiling.

Your code must compile. If it does not compile, you will receive a 0 (zero) on that portion of the
assignment, and no partial marks will be given.

Remember that students who hardcode their outputs to match the test cases in Mimir will
receive a zero on the entire assignment.

Grading Scheme: Please see the grading scheme at the end of this document.

Coding Style: You must proper variable names and comments. Please follow the guidelines on
https://web.cs.dal.ca/~franz/CodingStyle.html

Problem 1 – Coffee Beans

The goal for assignment 02 is to reinforce the concepts of classes and objects and how to
combine and work with multiple objects together. To do so, we will implement a Coffee Maker

so we can make some coffee

We will solve this problem in parts, separating each concept into its class. In the end, we will
combine everything (Coffee Grinder, Coffee Maker and Coffee Beans) to get some brew!

In problem 01, you will create a class to represent the concept of Coffee Beans. Beans can
either be ground or whole. They have a roast type, blend name and brand name. The UML
diagram below depicts the CoffeeBeans class.

The CoffeeBeans class also defines an Enumeration type inside of it: Roast .There are four
types of Roast for a CoffeeBean: LIGHT, MEDIUM, MEDIUM_DARK and DARK. You can define
the Roast enum inside the CoffeeBeans class (make sure the enum type is public)

On this page, you can find more info on enums in Java
https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Here is a description of the constructors and methods of CoffeeBeans

  • CoffeeBeans(String, String, Roast, boolean): Creates a new
    CoffeeBeans object with a brand name, blend names and roast type. It also sets the
    bean to ground or not. Set the boolean true to ground, false for whole bean
  • CoffeeBeans(String, String, Roast): Creates a new CoffeeBeans object
    with brand name, blend name and roast type. The CofeeBean is initialized as whole
    bean i.e., not ground
  • CoffeeBeans(String, String): Creates a new CoffeeBeans object with brand
    and blend names. Roast type is set to Medium. CofeeBean is initialized as whole bean
    i.e. not ground.
  • isGround(): returns a boolean informing if the bean is ground or not.
  • Getters: returns their respective proprieties
  • grind(): grinds the CoffeeBeans object from whole bean to ground. Returns true if
    the coffee switched from whole bean to ground. Returns false if the coffee was already
    ground.
  • toString(): returns a String representing the coffeeBean object according to the
    example below

There is no input or output for this question. All tests are unit test cases.

Please note that the class diagrams are defining some methods that you must implement.
You can, however, create more PRIVATE methods if you need them.

1
2
3
4
Brand: Kicking Horse
Blend: Horse 427
Roast type: Dark
whole bean

Problem 2 – The Coffee Machine and Coffee Grinder

To make coffee, we will also need a CoffeeMaker and a CoffeeGrinder. In this problem,
you will create both classe according to the diagrams depicted below. Please note that you
don’t need to write P2 after P1; you can write both in parallel or even P2 before P1. However,
you need to have all P1’s tests passing before you can thoroughly test the classes on this
problem.

See how the CoffeeMaker class depends on both CoffeeGrinder and CoffeeBeans
classes to function fully?

Here is a description of the constructors and methods of CoffeeGrinder

  • Default constructor only
  • grindCoffe(CoffeeBeans): grinds the coffee bean received as a parameter. If
    the beans are already ground return false.

Here is a description of the constructors and methods of CoffeeMaker. The machine is
always initialized with no water in the tank and off.

  • CoffeeMaker(CoffeeBeans, double): Create a new coffee maker with the
    beans already loaded into it and define the size of the water tank in millilitres.
  • CoffeeMaker(double): Create a new coffee maker object with a tank size defined
    by the double parameter in millilitres.
  • getWaterLevel(): returns the amount of water in the tank
  • switchPower(): toggles the power of the coffee maker on and off
  • hasCoffee(): returns true if the coffee maker has coffee loaded onto it; false
    otherwise
  • laodCoffee(CoffeBeans): loads coffee into the coffee maker. Returns false if
    the parameter is null.
  • brewCoffee(int): brews int cups of coffee. If the coffee beans in the machine are
    not ground, it will first grind the coffee using the internal coffee grinder. The machine
    cannot brew coffee if there isn’t enough water for the requested amount of coffee. The
    machine must be on to brew. Returns true if the maker successfully brewed the coffee.
  • clean(): removes coffee from the machine and empties the water container.
  • cupsToML(int): helper method (hence private) to convert cups to millilitres. One
    cup is ~ 236.59 ml
  • toString(): returns a String representing the CoffeeMaker object according to
    the example below
1
2
3
4
5
6
7
8
With coffee Without coffee
isOn: false
water left: 0.
loaded coffee:
Brand: Kicking Horse
Blend: Horse 427
Roast type: DARK
whole bean.
1
2
3
isOn: false
water left: 0.
no coffee loaded.

There is no input or output for this question. All tests are unit test cases.

Problem 3 – Let’s make some brew!

Now that we have both classes implemented and tested, we can make them work together so
we can brew some coffee! You will create a third class, HumanMakeCoffee, but this time
with the main method and user input/output.

Your program will have an Array of CoffeBeans to store four coffee types, which the user will
input. The program will also create a CoffeeMaker with a tank capacity of 2500ml

The program will work as follows:

  • First, it will read from the user 4 sets of coffee beans.
  • Then it will prompt the user for an option
    o 1 – To print the list of available coffees and load it into the machine
    o 2 – To print the machine string representation
    o 3 – To add water to the machine
    o 4 – To brew coffee. It will prompt the user for how many cups.
    o 0 – To exit the program

The next page contains examples for each option.

Input considerations

  • When reading the coffees from the user, each data (name, blend, roast) will be inputted
    in a different line
    o Example:
    o Kicking Horse
    o Horse 427
    o DARK
    
  • You will be reading the coffee’s roast as a String. You can convert into a Roast type using
    Roast.valueOf(theStringVariable). This method will work as long as the
    user’s input matches a roast type.
  • Assume that the user will always input correct/valid information (including the roast)

Options prompts/outputs examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Option selected Output Text/Prompt
1 Here are your coffee options^
(1)
Brand: Kicking Horse
Blend: Horse 427
Roast type: DARK
whole bean
---------
(2)
Brand: The Big Lift
Blend: Halifax Tour
Roast type: MEDIUM
whole bean
---------
(3)
Brand: Second Cup
Blend: Xmas Time
Roast type: LIGHT
whole bean
---------
(4)
Brand: Nespresso
Blend: Indonesia
Roast type: MEDIUM_DARK
whole bean
---------
Make a selection:
2 isOn: true^
water left: 0.
loaded coffee:
Brand: Kicking Horse
Blend: Horse 427
Roast type: DARK
whole bean.
3 How much water?^
4 (not enough water or
no coffee loaded)
1
2
3
4
How many cups?
Hmm... something went wrong
4 (enough water) How many cups?^
Brewing coffee...

Example Input/Ouput

1
2
3
Input Output
Kicking Horse
Horse 427
1
2
Welcome! Please select an option:
Here are your coffee options

DARK

The Big Lift
Halifax Tour
MEDIUM
Second Cup
Xmas Time
LIGHT
Nespresso
Indonesia
MEDIUM_DARK
1
2
2
0

(1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Brand: Kicking Horse
Blend: Horse 427
Roast type: DARK
whole bean)
---------
(2)
Brand: The Big Lift
Blend: Halifax Tour
Roast type: MEDIUM
whole bean)
---------
(3)
Brand: Second Cup
Blend: Xmas Time
Roast type: LIGHT
whole bean)
---------
(4)
Brand: Nespresso
Blend: Indonesia
Roast type: MEDIUM_DARK
whole bean)
---------
Make a selection:
isOn: true
water left: 0.
loaded coffee:
Brand: The Big Lift
Blend: Halifax Tour
Roast type: MEDIUM
whole bean.

Grading Scheme

Each problem on the assignment will be graded based on three criteria:

Functionality

“Does it work according to specifications?” This is determined in an automated fashion by
running your program on a number of inputs and ensuring that the outputs match the expected
outputs. The score is determined based on the number of tests that your program passes.

Quality of Solution

“Is it a good solution?” This considers whether the solution is correct, efficient, covers boundary
conditions, does not have any obvious bugs, etc. This is determined by visual inspection of the
code. Initially full marks are given to each solution and marks are deducted based on faults
found in the solution.

Code Clarity

“Is it well written?” This considers whether the solution is properly formatted, well-
documented, and follows coding style guidelines
(https://web.cs.dal.ca/~franz/CodingStyle.html).

If your program does not compile, it is considered non-functional and of extremely poor quality,
meaning you will receive 0 for the solution.

PROBLEM PARTIAL

POINTS

POINTS

PROBLEM 1

40

1
2
3
Functionality 30
Quality of Solution &
Code Clarity

10

PROBLEM 2

45

1
2
3
Functionality 30
Quality of Solution &
Code Clarity

15

PROBLEM 3 15

1
2
3
Functionality 10
Quality of Solution &
Code Clarity

5

TOTAL

100 100