Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.88 KB | None | 0 0
  1. /*
  2. ________________________________________________________________
  3. |  Class: Metric                                               |
  4. |  Author: Dustin Tucker                                       |
  5. |  Date: Mon Oct 25 22:03:32 EDT 2010                          |
  6. |  Purpose:                                                    |
  7. |       Create a OOP to display metric units of measurement in |
  8. |       meters, centimeters, and millimeters in standard form. |
  9. |       The program should allow for the user to create the    |
  10. |       object with all initial values, with one value and unit|
  11. |       or with 2 values and units.  The program should also be|
  12. |       able to create the object with zeroed values. The      |
  13. |       program should allow the user to set or get any of the |
  14. |       values.  The program should normalize the values so    |
  15. |       they can be displayed in standard form.                |
  16. |--------------------------------------------------------------|
  17. |  Member Data:                                                |
  18. |       -       double meter;                                  |
  19. |       -       String unitMeter;                              |
  20. |       -       double centimeter;                             |
  21. |       -       String unitCentimeter;                         |
  22. |       -       double millimeter;                             |
  23. |       -       String unitMillimeter;                         |
  24. |--------------------------------------------------------------|
  25. |  Methods:                                                    |
  26. |       +  String toString();                                  |
  27. |       +  Metric(double metric1, String unitMetric1,          |
  28. |                       double metric2,  String unitMetric2,   |
  29. |                       double metric3, String unitMetric3);   |
  30. |       +  Metric(double metric1, String unitMetric1,          |
  31. |                       double metric2, String unitMetric2);   |
  32. |       +  Metric(double metric1, String unitMetric1);         |
  33. |       +  MetricConversion();                                 |
  34. |       +  void setMeter(double meter);                        |
  35. |       +  void setCentimeter(double centimeter);              |
  36. |       +  void setMillimeter(double millimeter);              |
  37. |       +  double getMeter();                                  |
  38. |       +  double getCentimeter();                             |
  39. |       +  double getMillimeter();                             |
  40. |______________________________________________________________|
  41. */
  42.  
  43.  
  44. public class Metric
  45.    {
  46.       // member data
  47.       private double meter = 0;
  48.       private String unitMeter = "m";
  49.       private double centimeter = 0;
  50.       private String unitCentimeter = "cm";
  51.       private double millimeter = 0;
  52.       private String unitMillimeter = "mm";
  53.  
  54.  
  55.       /*
  56.       ______________________________________________________
  57.       |  Method:  Metric()                                 |
  58.       |  Author:  Dustin Tucker                            |
  59.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  60.       |  Params:                                           |
  61.       |  Returns:                                          |
  62.       |  Purpose:                                          |
  63.       |____________________________________________________|
  64.       */
  65.       public Metric(double metric1, String unitMetric1,  double metric2,  String unitMetric2, double metric3, String unitMetric3)
  66.          {
  67.          
  68.             {
  69.                 if (unitMetric1.equalsIgnoreCase("m"))
  70.                 {
  71.                     this.meter = metric1;
  72.                     this.unitMeter = unitMetric1;
  73.                 }
  74.                 else if (unitMetric1.equalsIgnoreCase("cm"))
  75.                 {
  76.                     this.centimeter = metric1;
  77.                     this.unitCentimeter = unitMetric1;
  78.                 }
  79.                 else if (unitMetric1.equalsIgnoreCase("mm"))
  80.                 {
  81.                     this.millimeter = metric1;
  82.                     this.unitMillimeter = unitMetric1;
  83.                 }
  84.                 else
  85.                 {
  86.                     System.out.println("Invalid Entry");
  87.                     System.exit(0);
  88.                 }
  89.             }
  90.            
  91.             {
  92.                 if (unitMetric2.equalsIgnoreCase("m"))
  93.                 {
  94.                     this.meter = metric2;
  95.                     this.unitMeter = unitMetric2;
  96.                 }
  97.                 else if (unitMetric2.equalsIgnoreCase("cm"))
  98.                 {
  99.                     this.centimeter = metric2;
  100.                     this.unitCentimeter = unitMetric2;
  101.                 }
  102.                 else if (unitMetric2.equalsIgnoreCase("mm"))
  103.                 {
  104.                     this.millimeter = metric2;
  105.                     this.unitMillimeter = unitMetric2;
  106.                 }
  107.                 else
  108.                 {
  109.                     System.out.println("Invalid Entry");
  110.                     System.exit(0);
  111.                 }
  112.             }
  113.            
  114.             {
  115.                 if (unitMetric3.equalsIgnoreCase("m"))
  116.                 {
  117.                     this.meter = metric3;
  118.                     this.unitMeter = unitMetric3;
  119.                 }
  120.                 else if (unitMetric3.equalsIgnoreCase("cm"))
  121.                 {
  122.                     this.centimeter = metric3;
  123.                     this.unitCentimeter = unitMetric3;
  124.                 }
  125.                 else if (unitMetric3.equalsIgnoreCase("mm"))
  126.                 {
  127.                     this.millimeter = metric3;
  128.                     this.unitMillimeter = unitMetric3;
  129.                 }
  130.                 else
  131.                 {
  132.                     System.out.println("Invalid Entry");
  133.                     System.exit(0);
  134.                 }
  135.             }
  136.           }
  137.          
  138.  
  139.       /*
  140.       ______________________________________________________
  141.       |  Method: Metric()                                  |
  142.       |  Author:  Dustin Tucker                            |
  143.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  144.       |  Params:                                           |
  145.       |  Returns:                                          |
  146.       |  Purpose:                                          |
  147.       |____________________________________________________|
  148.       */
  149.       public Metric(double metric1, String unitMetric1,  double metric2, String unitMetric2)
  150.           {
  151.            
  152.             {
  153.                 if (unitMetric1.equals("m"))
  154.                 {
  155.                     this.meter = metric1;
  156.                     this.unitMeter = unitMetric1;
  157.                 }
  158.                 else if (unitMetric1.equals("cm"))
  159.                 {
  160.                     this.centimeter = metric1;
  161.                     this.unitCentimeter = unitMetric1;
  162.                 }
  163.                 else if (unitMetric1.equals("mm"))
  164.                 {
  165.                     this.millimeter = metric1;
  166.                     this.unitMillimeter = unitMetric1;
  167.                 }
  168.                 else
  169.                 {
  170.                     System.out.println("Invalid Entry");
  171.                     System.exit(0);
  172.                 }
  173.             }
  174.            
  175.             {
  176.                 if (unitMetric2.equals("m"))
  177.                 {
  178.                     this.meter = metric2;
  179.                     this.unitMeter = unitMetric2;
  180.                 }
  181.                 else if (unitMetric2.equals("cm"))
  182.                 {
  183.                     this.centimeter = metric2;
  184.                     this.unitCentimeter = unitMetric2;
  185.                 }
  186.                 else if (unitMetric2.equals("mm"))
  187.                 {
  188.                     this.millimeter = metric2;
  189.                     this.unitMillimeter = unitMetric2;
  190.                 }
  191.                 else
  192.                 {
  193.                     System.out.println("Invalid Entry");
  194.                     System.exit(0);
  195.                 }
  196.             }
  197.  
  198.           }
  199.          
  200.          
  201.       /*
  202.       ______________________________________________________
  203.       |  Method:  Metric()                                 |
  204.       |  Author:  Dustin Tucker                            |
  205.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  206.       |  Params:                                           |
  207.       |  Returns:                                          |
  208.       |  Purpose:                                          |
  209.       |____________________________________________________|
  210.       */
  211.       public Metric (double metric1, String unitMetric1)
  212.          {
  213.  
  214.             {
  215.                 if (unitMetric1.equalsIgnoreCase("m"))
  216.                 {
  217.                     this.meter = metric1;
  218.                     this.unitMeter = unitMetric1;
  219.                 }
  220.                 else if (unitMetric1.equalsIgnoreCase("cm"))
  221.                 {
  222.                     this.centimeter = metric1;
  223.                     this.unitCentimeter = unitMetric1;
  224.                 }
  225.                 else if (unitMetric1.equalsIgnoreCase("mm"))
  226.                 {
  227.                     this.millimeter = metric1;
  228.                     this.unitMillimeter = unitMetric1;
  229.                 }
  230.                 else
  231.                 {
  232.                     System.out.println("Invalid Entry");
  233.                     System.exit(0);
  234.                 }
  235.             }
  236.            
  237.           }
  238.          
  239.          
  240.       /*
  241.       ______________________________________________________
  242.       |  Method:  Metric()                                 |
  243.       |  Author:  Dustin Tucker                            |
  244.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  245.       |  Params:                                           |
  246.       |  Returns:                                          |
  247.       |  Purpose:                                          |
  248.       |____________________________________________________|
  249.       */
  250.       public Metric()
  251.           {
  252.             // blank;
  253.  
  254.           }
  255.  
  256.          
  257.          
  258.       /*
  259.       ______________________________________________________
  260.       |  Method:  setMeter()                               |
  261.       |  Author:  Dustin Tucker                            |
  262.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  263.       |  Params:                                           |
  264.       |  Returns:                                          |
  265.       |  Purpose:                                          |
  266.       |____________________________________________________|
  267.       */
  268.       public void setMeter(double meter)
  269.           {
  270.             //   method code;
  271.             this.meter = meter;
  272.  
  273.           }
  274.          
  275.          
  276.       /*
  277.       ______________________________________________________
  278.       |  Method:  setCentimeter()                          |
  279.       |  Author:  Dustin Tucker                            |
  280.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  281.       |  Params:                                           |
  282.       |  Returns:                                          |
  283.       |  Purpose:                                          |
  284.       |____________________________________________________|
  285.       */
  286.       public void setCentimeter(double centimeter)
  287.           {
  288.             //   method code;
  289.             this.centimeter = centimeter;
  290.  
  291.           }
  292.          
  293.          
  294.       /*
  295.       ______________________________________________________
  296.       |  Method:  setMillimeter()                          |
  297.       |  Author:  Dustin Tucker                            |
  298.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  299.       |  Params:                                           |
  300.       |  Returns:                                          |
  301.       |  Purpose:                                          |
  302.       |____________________________________________________|
  303.       */
  304.       public void setMillimeter(double millimeter)
  305.           {
  306.             //   method code;
  307.             this.millimeter = millimeter;
  308.  
  309.           }
  310.          
  311.          
  312.       /*
  313.       ______________________________________________________
  314.       |  Method:  getMeter()                               |
  315.       |  Author:  Dustin Tucker                            |
  316.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  317.       |  Params:                                           |
  318.       |  Returns:                                          |
  319.       |  Purpose:                                          |
  320.       |____________________________________________________|
  321.       */
  322.       public double getMeter()
  323.           {
  324.             //   method code;
  325.             return meter;
  326.           }
  327.          
  328.          
  329.       /*
  330.       ______________________________________________________
  331.       |  Method:  getCentimeter()                          |
  332.       |  Author:  Dustin Tucker                            |
  333.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  334.       |  Params:                                           |
  335.       |  Returns:                                          |
  336.       |  Purpose:                                          |
  337.       |____________________________________________________|
  338.       */
  339.       public double getCentimeter()
  340.           {
  341.             //   method code;
  342.             return centimeter;
  343.           }
  344.          
  345.          
  346.       /*
  347.       ______________________________________________________
  348.       |  Method:  getMillimeter()                          |
  349.       |  Author:  Dustin Tucker                            |
  350.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  351.       |  Params:                                           |
  352.       |  Returns:                                          |
  353.       |  Purpose:                                          |
  354.       |____________________________________________________|
  355.       */
  356.       public double getMillimeter()
  357.           {
  358.             //   method code;
  359.             return millimeter;
  360.           }
  361.          
  362.          
  363.       /*
  364.       ______________________________________________________
  365.       |  Method:  String toString()                        |
  366.       |  Author:  Dustin Tucker                            |
  367.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  368.       |  Params:                                           |
  369.       |  Returns:                                          |
  370.       |  Purpose:                                          |
  371.       |____________________________________________________|
  372.       */
  373.       public String toString()
  374.           {
  375.             System.out.println("The value set to meter is " + meter + unitMeter);
  376.             System.out.println("The value set to centimeter is " + centimeter + unitCentimeter);
  377.             return("The value set to millimeter is " + millimeter + unitMillimeter);
  378.            
  379.  
  380.           }
  381.          
  382.       /*
  383.       ______________________________________________________
  384.       |  Method:  calcValue()                              |
  385.       |  Author:  Dustin Tucker                            |
  386.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  387.       |  Params:                                           |
  388.       |  Returns:                                          |
  389.       |  Purpose:                                          |
  390.       |____________________________________________________|
  391.       */
  392.       public void setValue(double metric1, String unitMetric1)
  393.           {
  394.                 if (unitMetric1.equals("m"))
  395.                 {
  396.                     this.meter = metric1;
  397.                     this.unitMeter = unitMetric1;
  398.                 }
  399.                 else if (unitMetric1.equals("cm"))
  400.                 {
  401.                     this.centimeter = metric1;
  402.                     this.unitCentimeter = unitMetric1;
  403.                 }
  404.                 else if (unitMetric1.equals("mm"))
  405.                 {
  406.                     this.millimeter = metric1;
  407.                     this.unitMillimeter = unitMetric1;
  408.                 }
  409.                 else
  410.                 {
  411.                     System.out.println("Invalid Entry");
  412.                     System.exit(0);
  413.                 }
  414.           }
  415.  
  416.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement