smashita / coffeemaker-2019 Goto Github PK
View Code? Open in Web Editor NEWSoftware Design and Architecture 2019 2020
Software Design and Architecture 2019 2020
Most of the check styles problem is probably incorrect indentation. Indentation is a space should be used(4 spaces) as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4). Indentation is used to avoid using more than 80 characters in a line. This is because the terminals and the tools cannot handle well lines that consist of more than 80 characters. In addition, the indentation does not matter for code “runability”. In other words, if you don’t indent it perfectly, your code will still run. However, it is good for code readability, so you can understand what you’ve written.
Example of incorrect code:
public CoffeeMaker() {
recipeBook = new RecipeBook();
inventory = new Inventory();
}
'ctor def modifier' has incorrect indentation level 8, expected level should be 2'
following the example given the curly bracket {} is at different indentation.
Correction
public CoffeeMaker()
{
recipeBook = new RecipeBook();
inventory = new Inventory();
}
wrong: private final int NUM_RECIPES = 4;
catch(IOException e)
int userInput = Integer.parseInt(inputOutput("Please press the number that corresponds to what you would like the coffee maker to do."));
for(int i = 0; i < recipes.length; i++) {
if (recipes[i] != null) {
System.out.println((i+1) + ". " + recipes[i].getName());
}
}
In class Recipe.java the if-clause is missing {}
@Override public boolean equals(Object obj) { if (this == obj){ return true;} if (obj == null){ return false;} if (getClass() != obj.getClass()){ return false;} final Recipe other = (Recipe) obj; if (name == null) { if (other.name != null){ return false;} } else if (!name.equals(other.name)){ return false;} return true; }
if (recipe >= 0 && recipe <= 2) { //do nothing here. }
220 Inventory.coffee += r.getAmtCoffee();
In Inventory.Java , method useIngredients is used to substract the amount of ingredients needed to make a coffee from the amount of ingredients available inside the Inventory. However in the line 220 the compiler will store the amount of available coffee in the inventory (Inventory.coffee) by adding the amount of coffee needed to make the coffee (r.getAmtCoffee();) with Inventory.coffee. This is logically wrong because when we make the coffee, the amount of coffee available should be decreased.
To solve this simply change the line += sign to -= sign
And the code will look like this:
220 Inventory.coffee -= r.getAmtCoffee();
/**
* @return Returns the price.
*/
Wrong:
setCoffee(15); -> 4 empty space and a tab are used
Solution:
setCoffee(15); -> 4 empty space is used
(Note: The empty space at the beginning of the line should be 4, not 8)
(Note: Use only empty space at the beginning of the line, no need tab)
if (this == obj)
return true;
if (userInput == 1) addRecipe();
if (userInput == 2) deleteRecipe();
if (userInput == 3) editRecipe();
if (userInput == 4) addInventory();
if (userInput == 5) checkInventory();
if (userInput == 6) makeCoffee();
if (userInput == 0) System.exit(0);
if (recipeEdited != null) {
System.out.println(recipeEdited + " successfully edited.\n");
}
else {
System.out.println(recipeEdited + "could not be edited.\n");
}
String chocolateString = inputOutput("\nPlease enter the units of chocolate in the recipe: ");
Typically when we write at-clause which is @ , we generally write a description after that for this case:
Incorrect
> /**
> * Add the number of coffee units in the inventory
> * to the current amount of coffee units.
> * @param coffee
> * @throws InventoryException
> */
>
Instead it should be written as:
/**
* Add the number of coffee units in the inventory
* to the current amount of coffee units.
* @param coffee represents something
* @throws InventoryException when this exceptional condition happens
*/
System.out.println((i+1) + ". " + recipes[i].getName());
for (int i = 0; i < recipeArray.length; i++) {
if (r.equals(recipeArray[i])) {
exists = true;
}
/** Array of recipes in coffee maker */
if (userInput == 1) {
addRecipe();
}
if (userInput == 2) {
deleteRecipe();
}
if (userInput == 3) {
editRecipe();
}
if (userInput == 4) {
addInventory();
}
if (userInput == 5) {
checkInventory();
}
if (userInput == 6) {
makeCoffee();
}
if (userInput == 0) {
System.exit(0);
}
Wrong:
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Recipe other = (Recipe) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
Wrong:
if(recipeToEdit < 0) {
mainMenu();
}
Solution:
if (recipeToEdit <0) { mainMenu(); }
WhitespaceAround: 'for' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
for(int i = 0; i < recipes.length; i++) {
main.java line 7,8
import edu.ncsu.csc326.coffeemaker.exceptions.InventoryException;
import edu.ncsu.csc326.coffeemaker.exceptions.RecipeException;
try {
returnString = br.readLine(); }
private final int NUM_RECIPES = 4;
System.out.println("Please enter a number from 0 - 6");
undefined integer
Example:
private String name;
(4 empty space is used at the beginning of declaration of variable)
Solution:
private String name;
(only 2 empty space is used at the beginning of declaration of variable)
int userInput = Integer.parseInt(inputOutput("Please press the number that corresponds to what you would like the coffee maker to do."));
if(chocolate >= 0) {
In the class inventory.java of the coffee maker project, through checkstyle activation, i found an error at public String toString() { ..... (line 235)
It said that its overrides java.lang.Object.toString
The java.lang.Object.toString() method returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
Line (277:43) [WhitespaceAround]
if (recipe >= 0 && recipe <=2)
int userInput = Integer.parseInt(inputOutput("Please press the number that corresponds to what you would like the coffee maker to do."));
int recipeToPurchase = recipeListSelection("Please select the number of the recipe to purchase.");
int recipeToDelete = recipeListSelection("Please select the number of the recipe to delete.");
throw new InventoryException("Units of milk must be a positive integer");
-Abbreviation in name 'NUM_RECIPES' must contain no more than '2' consecutive capital letters.
-Member name 'NUM_RECIPES' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'.
if(milk >= 0) {
Inventory.milk = milk;
}
Braces are needed for 'if' construct.
if (userInput == 1) addRecipe();
Below is the issues detected in CoffeeMaker using CheckStyle. There are total 100 issues out of 1320 codes.
Description | Resource | Location | Type
The parameter 'r' should be declared 'final' in Class RecipeBook.java on line 31.
(31:43)[FinalParameters]
public synchronized boolean addRecipe(final Recipe r) { //Assume recipe doesn't exist in the array until //find out otherwise boolean exists = false; //Check that recipe doesn't already exist in array for (int i = 0; i < recipeArray.length; i++) { if (r.equals(recipeArray[i])) { exists = true; } }
Solution (1 level space)
/**
* Constructor for the coffee maker
*
*/
public CoffeeMaker() {
recipeBook = new RecipeBook();
inventory = new Inventory();
}
if (userInput == 1) addRecipe();
- 'if' construct must use '{}'s.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.