Skip to content

Commit

Permalink
refractoring
Browse files Browse the repository at this point in the history
  • Loading branch information
thetimeofblack committed Jun 5, 2018
1 parent 79e3264 commit 7ca9069
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 75 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
<<<<<<< HEAD
/bin/
=======
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
>>>>>>> branch 'master' of https://github.com/thetimeofblack/digitalcookbook.git
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# digitalcookbook
this is the code of Software Engineering
121 changes: 121 additions & 0 deletions src/CookBookController/DataBaseController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package CookBookController;
import DigitalCookbook.Recipe;
import java.io.IOException;
import java.util.*;

import DigitalCookbook.Ingredient;
import DigitalCookbook.Recipe;

import java.sql.Connection;
import java.sql.DriverManager ;
import java.sql.ResultSet;
import java.sql.SQLException ;
import java.sql.Statement ;


public class DataBaseController {
final private String databaseUser = "root";
final private String databasePassword = "heyining";
final private String databaseUrl = "jdbc:mysql://localhost:3306/recipedatabase?useSSL=true&serverTimezone=GMT";
final private String databaseDriver = "com.mysql.cj.jdbc.Driver";
private LinkedList<Recipe> recipelist = new LinkedList<Recipe>();
private Statement statement;

DataBaseController(){
try {
Class.forName(this.databaseDriver);
Connection con = DriverManager.getConnection(this.databaseUrl, this.databaseUser, this.databasePassword);
if(!con.isClosed())
System.out.println("Succeeded connecting to the Database!");
this.statement = con.createStatement();//»ñµÃÊý¾Ý¿âsession

}catch(Exception e) {
e.printStackTrace();
}
}

public void InsertRecipe(Recipe recipe) {
String name= recipe.getrecipename();
String category = recipe.getCategory();
double cooktime =recipe.getCooktime();
int number = recipe.getNumber();
LinkedList<String> recipesteps = recipe.getSteps();
LinkedList<Ingredient> recipeingredients = recipe.getIngredientlist();
double preparationtime = recipe.getPreparationtime();

}


public LinkedList<Recipe> searchRecipe(String recipename) {
Recipe recipe = new Recipe(recipename);
LinkedList<Recipe> recipelist = new LinkedList<Recipe>();
String sql = "select * from recipe where recipename = ";
sql = sql +"\'" +recipename + "\'";
try {
ResultSet rs = this.statement.executeQuery(sql);
while(rs.next()) {
recipe.setRecipename(rs.getString("recipename"));
recipe.setCategory(rs.getString("category"));
recipe.setCookingTime(rs.getDouble("cooktime"));
recipe.setNumber(rs.getInt("recipe"));
recipe.setrecipeid(rs.getString("recipeid"));
this.addingreforRecipe(recipe);

recipelist.add(recipe);
}
rs.close();
}catch(Exception e) {
e.printStackTrace();
}

return recipelist;

}


private void addingreforRecipe(Recipe recipe) {
String sql = "select * from Ingredientrecipes where recipeid = \'"+recipe.getrecipeid()+"\'";
try {
ResultSet rs = this.statement.executeQuery(sql);
LinkedList<Integer> ingredientid = new LinkedList<Integer>();



while(rs.next()) {

String name = rs.getString("ingredientname");
double amount = rs.getDouble("ingredientamount");
String unit = rs.getString("ingredientunit");

Ingredient ingredient = new Ingredient(name,amount,unit);

recipe.addIngredient(ingredient);
}
}catch(Exception e) {
e.printStackTrace();
}


}

private void addstepsforRecipe(Recipe recipe) {
String sql = "Select";
try {
ResultSet rs = this.statement.executeQuery(sql);
String step = rs.getString("description");
recipe.addPreparationStep(step);

}catch(Exception e) {
e.printStackTrace();
}
}


public LinkedList<Recipe> getRecipeList() {
return this.recipelist;
}
public void close(){

}

}
71 changes: 0 additions & 71 deletions src/DigitalCookbook/DataBaseController.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/DigitalCookbook/Ingredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public void setDescription(String description) {

private String description;

Ingredient(String ingredientname, double amount, String unit){
public Ingredient(String ingredientname, double amount, String unit){
this.ingredientname=ingredientname;
this.amount = amount ;
this.unit = unit;
}
Ingredient(String ingredientname, double amount , String unit, String description){
public Ingredient(String ingredientname, double amount , String unit, String description){
this.ingredientname = ingredientname;
this.amount = amount ;
this.unit = unit;
Expand Down
14 changes: 12 additions & 2 deletions src/DigitalCookbook/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ public class Recipe {
private int number;
private double preparationtime ;
private double cooktime ;
private String recipeid ;

Recipe(String recipename , String category,int number ){
public Recipe(String recipename , String category,int number ){
this.number= number ;
this.recipename = recipename ;
this.category = category;
this.steps = new LinkedList<String>();
this.ingredientlist= new LinkedList<Ingredient>();
}

Recipe(String recipename){
public Recipe(String recipename){
this.recipename = recipename;
}

Expand Down Expand Up @@ -156,5 +157,14 @@ public String toString() {
return toString;
}

public String getrecipeid() {
return this.recipeid;
}

public void setrecipeid(String recipeid) {
this.recipeid = recipeid;

}


}

0 comments on commit 7ca9069

Please sign in to comment.