Quilt Calculator


/ Published in: Java
Save to your folder(s)

Determines most cost beneficial cutting method of fabric.


Copy this code and paste it in your HTML
  1. // Created by: Seth Savage
  2.  
  3. package quiltcalc;
  4. import java.util.*;
  5. import javax.swing.JOptionPane;
  6. import java.text.DecimalFormat;
  7.  
  8.  
  9. public class QuiltCalc
  10. {
  11.  
  12. public static void main(String[] args)
  13. {
  14. // Variables
  15. double clothHeight = 42.0;
  16. double clothWidth = 0.0;
  17. double stripHeight = 42.0;
  18. double stripWidth = 0.0;
  19. double pieceHeight = 0.0;
  20. double pieceWidth = 0.0;
  21. double pieceAmt = 0.0;
  22. String HeightString = "";
  23. String WidthString = "";
  24. String AmtString = "";
  25. DecimalFormat format = new DecimalFormat("#.##");
  26.  
  27. // Dependant Vaiables
  28. double piecesPerStripA = 0.0;
  29. double piecesPerStripB = 0.0;
  30. double stripAmtA = 0.0;
  31. double stripAmtB = 0.0;
  32. double stripAmtAForm;
  33. double stripAmtBForm;
  34. double clothWidthA = 0.0;
  35. double clothWidthB = 0.0;
  36. double WasteA;
  37. double WasteAHeight;
  38. double WasteBHeight;
  39. double WasteB;
  40. double ExtraA;
  41. double ExtraB;
  42. double pieceArea;
  43. double clothAreaA;
  44. double clothAreaB;
  45.  
  46. double TotalPieceAreaA;
  47. double TotalPieceAreaB;
  48. double stripAmtALower;
  49. double stripAmtBLower;
  50. double WasteAreaA;
  51. double WasteAreaB;
  52. double TempCalc;
  53. double WasteAFinalH;
  54. double WasteBFinalH;
  55. double TotalWasteA;
  56. double TotalWasteB;
  57.  
  58.  
  59.  
  60. // User Input
  61. HeightString = JOptionPane.showInputDialog("Height of Pieces:");
  62. pieceHeight = Double.parseDouble(HeightString);
  63.  
  64. WidthString = JOptionPane.showInputDialog("Width of Pieces:");
  65. pieceWidth = Double.parseDouble(WidthString);
  66.  
  67. AmtString = JOptionPane.showInputDialog("Number of Pieces:");
  68. pieceAmt = Double.parseDouble(AmtString);
  69.  
  70. // Assignments
  71. stripWidth = pieceWidth;
  72.  
  73. // Calculations for Original Data
  74. pieceArea = (pieceHeight * pieceWidth);
  75. piecesPerStripA = (42/pieceHeight);
  76. piecesPerStripA = (double) Math.floor(piecesPerStripA);
  77. stripAmtA = (pieceAmt/piecesPerStripA);
  78. stripAmtAForm = (double) Math.ceil(stripAmtA);
  79. clothWidthA = (stripAmtAForm * stripWidth);
  80. clothAreaA = (42 * clothWidthA);
  81. TotalPieceAreaA = (pieceAmt * pieceArea);
  82.  
  83. WasteA = (clothAreaA - TotalPieceAreaA);
  84. TotalWasteA = WasteA;
  85.  
  86. WasteAHeight = (42 - (piecesPerStripA * pieceHeight));
  87. ExtraA = (stripWidth * WasteAHeight);
  88. stripAmtALower = (double) Math.floor(stripAmtA);
  89. WasteAreaA = (stripAmtALower * ExtraA);
  90.  
  91. WasteA = WasteA - WasteAreaA;
  92. TempCalc = stripAmtAForm - stripAmtA;
  93. WasteAFinalH = (42 * TempCalc);
  94. WasteAFinalH = Math.round(WasteAFinalH * 100.0)/100.0;
  95.  
  96.  
  97.  
  98. // Calculation for Inverted Data---------------------------------------------
  99. piecesPerStripB = (42/pieceWidth);
  100. piecesPerStripB = (double) Math.floor(piecesPerStripB);
  101. stripAmtB = (pieceAmt/piecesPerStripB);
  102. stripAmtBForm = (double) Math.ceil(stripAmtB);
  103. clothWidthB = (stripAmtBForm * pieceHeight);
  104. clothAreaB = (42 * clothWidthB);
  105. TotalPieceAreaB = (pieceAmt * pieceArea);
  106. WasteB = (clothAreaB - TotalPieceAreaB);
  107. TotalWasteB = WasteB;
  108.  
  109.  
  110.  
  111.  
  112.  
  113. JOptionPane.showMessageDialog(null,"Piece Height: " +pieceHeight +
  114. "\nPiece Width: " +pieceWidth +"\nNumber of Pieces: " +
  115. pieceAmt +"\nNumber of Pieces per Strip: " +piecesPerStripA +
  116. "\nNumber of Strips: " +stripAmtAForm +"\nYardage (in inches): " +
  117. clothWidthA +"\n\n----------Using Initial Data-----------"+
  118. "\nExtra on Last Strip: " +pieceWidth +" x "+WasteAFinalH +
  119. "\nExtra on Previous Strips: " +pieceWidth +" x " +WasteAHeight +
  120. "\nTotal Extra Area: " +TotalWasteA +"\n--------------------------------------------"
  121. +"\n\n\n----------Using Inverted Data-----------" +
  122. "\nTotal Extra Area: " +TotalWasteB+"\n-------------------------------------------------");
  123.  
  124. }
  125.  
  126. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.