Advertisement
utroz

RecipeCalc

Jun 19th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. // Run.java
  2. // This file is part of Recipe Calc.
  3. // Copyright ©2011 - @uthor #Utroz#.
  4.  
  5. import java.util.Scanner;
  6.  
  7. class Run {
  8.     static Scanner input = new Scanner(System.in); 
  9.     static String title = "Recipe Calc (v0.1) by #Utroz#";
  10.    
  11.     public static void main(String[] args){
  12.         System.out.println("");
  13.         System.out.println(title);
  14.         System.out.println("------------------");
  15.         System.out.println("Input a amount of cream milk:");
  16.         int amount = input.nextInt();
  17.  
  18.         // Send the amount.
  19.         Recipe obj = new Recipe(amount);
  20.  
  21.         // Calculate.
  22.         obj.Calculate();
  23.  
  24.         // Print the Result.
  25.         obj.Print();
  26.  
  27.         // Exit System.
  28.         System.out.println("");
  29.         System.out.println("Thanks for use the system!");
  30.         System.exit(0);
  31.        
  32.     }
  33. }
  34.  
  35. // Recipe.java
  36. // This file is part of Recipe Calc.
  37. // Copyright ©2011 - @uthor #Utroz#.
  38.  
  39. public class Recipe {
  40.  
  41.     /* Base container values */
  42.     public final double CONTAINER = 99.899;
  43.     public final double BASE_1_3 = 33.3;
  44.     public final double BASE_2_3 = 66.6;
  45.  
  46.     public final String FORMAT_0 = "100% or 1/1.";
  47.     public final String FORMAT_1 = "33% or 1/3";
  48.     public final String FORMAT_2 = "66% or 2/3.";
  49.  
  50.     public int data_0 = 0, data_1 = 0, data_2 = 0;
  51.  
  52.     public final String MSG = "Need to adding a: ";
  53.  
  54.     public int amount;
  55.     public double[] containers;
  56.  
  57.     public Recipe(int arg){
  58.         this.amount = arg;
  59.         containers = new double[arg];      
  60.     }
  61.  
  62.     public void Calculate(){
  63.         int count = 0;
  64.         double inputMilk = 0.0; // reference.
  65.  
  66.         while(amount > 0){
  67.  
  68.             // Adding a 1/3 base on recepient.
  69.             if(containers[count] < CONTAINER){
  70.                 containers[count] += BASE_1_3;
  71.                 inputMilk += BASE_1_3;
  72.  
  73.                 if(inputMilk == BASE_2_3){
  74.                     amount--; inputMilk = 0;
  75.                     continue;
  76.                 }
  77.             }  
  78.  
  79.             // If the container to be higher than base container change of recepient.
  80.             if(containers[count] >= CONTAINER) ++count;
  81.            
  82.         }
  83.     }
  84.  
  85.     // Printing Recepients.
  86.     public void Print(){
  87.         System.out.println("");
  88.         System.out.println("Report Data:");
  89.         System.out.println("------------------");
  90.         for(double print : containers){
  91.             if(print >= CONTAINER){
  92.                 System.out.println(MSG + FORMAT_0);
  93.                 data_0++;
  94.             }
  95.  
  96.             if(print == BASE_1_3){
  97.                 System.out.println(MSG + FORMAT_1);
  98.                 data_1++;
  99.             }
  100.  
  101.             if(print == BASE_2_3){
  102.                 System.out.println(MSG + FORMAT_2);
  103.                 data_2++;
  104.             }
  105.         }
  106.  
  107.         Data();
  108.     }
  109.  
  110.     public void Data(){
  111.         System.out.println("");
  112.         System.out.println("Result Data:");
  113.         System.out.println("------------------");
  114.  
  115.         if(data_0 >= 0)
  116.         System.out.println("| "+FORMAT_0+": "+data_0+" |");
  117.  
  118.         if(data_1 >= 0)
  119.         System.out.println("| "+FORMAT_1+": "+data_1+" |");
  120.  
  121.         if(data_2 >= 0)
  122.         System.out.println("| "+FORMAT_2+": "+data_2+" |");
  123.     }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement