Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.34 KB | None | 0 0
  1. /*
  2. ________________________________________________________________
  3. |  Class: Metric                                               |
  4. |  Author:                                        |
  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;
  48.       private String unitMeter;
  49.       private double centimeter;
  50.       private String unitCentimeter;
  51.       private double millimeter;
  52.       private String unitMillimeter;
  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.             meter = 0;
  68.             unitMeter = "m";
  69.             centimeter = 0;
  70.             unitCentimeter = "cm";
  71.             millimeter = 0;
  72.             unitMillimeter = "mm";
  73.             {
  74.                 if (unitMetric1.equalsIgnoreCase("m"))
  75.                 {
  76.                     this.meter = metric1;
  77.                     this.unitMeter = unitMetric1;
  78.                 }
  79.                 else if (unitMetric1.equalsIgnoreCase("cm"))
  80.                 {
  81.                     this.centimeter = metric1;
  82.                     this.unitCentimeter = unitMetric1;
  83.                 }
  84.                 else if (unitMetric1.equalsIgnoreCase("mm"))
  85.                 {
  86.                     this.millimeter = metric1;
  87.                     this.unitMillimeter = unitMetric1;
  88.                 }
  89.                 else
  90.                 {
  91.                     System.out.println("Invalid Entry");
  92.                     System.exit(0);
  93.                 }
  94.             }
  95.            
  96.             {
  97.                 if (unitMetric2.equalsIgnoreCase("m"))
  98.                 {
  99.                     this.meter = metric2;
  100.                     this.unitMeter = unitMetric2;
  101.                 }
  102.                 else if (unitMetric2.equalsIgnoreCase("cm"))
  103.                 {
  104.                     this.centimeter = metric2;
  105.                     this.unitCentimeter = unitMetric2;
  106.                 }
  107.                 else if (unitMetric2.equalsIgnoreCase("mm"))
  108.                 {
  109.                     this.millimeter = metric2;
  110.                     this.unitMillimeter = unitMetric2;
  111.                 }
  112.                 else
  113.                 {
  114.                     System.out.println("Invalid Entry");
  115.                     System.exit(0);
  116.                 }
  117.             }
  118.            
  119.             {
  120.                 if (unitMetric3.equalsIgnoreCase("m"))
  121.                 {
  122.                     this.meter = metric3;
  123.                     this.unitMeter = unitMetric3;
  124.                 }
  125.                 else if (unitMetric3.equalsIgnoreCase("cm"))
  126.                 {
  127.                     this.centimeter = metric3;
  128.                     this.unitCentimeter = unitMetric3;
  129.                 }
  130.                 else if (unitMetric3.equalsIgnoreCase("mm"))
  131.                 {
  132.                     this.millimeter = metric3;
  133.                     this.unitMillimeter = unitMetric3;
  134.                 }
  135.                 else
  136.                 {
  137.                     System.out.println("Invalid Entry");
  138.                     System.exit(0);
  139.                 }
  140.             }
  141.           }
  142.          
  143.  
  144.       /*
  145.       ______________________________________________________
  146.       |  Method: Metric()                                  |
  147.       |  Author:  Dustin Tucker                            |
  148.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  149.       |  Params:                                           |
  150.       |  Returns:                                          |
  151.       |  Purpose:                                          |
  152.       |____________________________________________________|
  153.       */
  154.       public Metric(double metric1, String unitMetric1,  double metric2, String unitMetric2)
  155.           {
  156.             meter = 0;
  157.             unitMeter = "m";
  158.             centimeter = 0;
  159.             unitCentimeter = "cm";
  160.             millimeter = 0;
  161.             unitMillimeter = "mm";
  162.            
  163.             {
  164.                 if (unitMetric1.equals("m"))
  165.                 {
  166.                     this.meter = metric1;
  167.                     this.unitMeter = unitMetric1;
  168.                 }
  169.                 else if (unitMetric1.equals("cm"))
  170.                 {
  171.                     this.centimeter = metric1;
  172.                     this.unitCentimeter = unitMetric1;
  173.                 }
  174.                 else if (unitMetric1.equals("mm"))
  175.                 {
  176.                     this.millimeter = metric1;
  177.                     this.unitMillimeter = unitMetric1;
  178.                 }
  179.                 else
  180.                 {
  181.                     System.out.println("Invalid Entry");
  182.                     System.exit(0);
  183.                 }
  184.             }
  185.            
  186.             {
  187.                 if (unitMetric2.equals("m"))
  188.                 {
  189.                     this.meter = metric2;
  190.                     this.unitMeter = unitMetric2;
  191.                 }
  192.                 else if (unitMetric2.equals("cm"))
  193.                 {
  194.                     this.centimeter = metric2;
  195.                     this.unitCentimeter = unitMetric2;
  196.                 }
  197.                 else if (unitMetric2.equals("mm"))
  198.                 {
  199.                     this.millimeter = metric2;
  200.                     this.unitMillimeter = unitMetric2;
  201.                 }
  202.                 else
  203.                 {
  204.                     System.out.println("Invalid Entry");
  205.                     System.exit(0);
  206.                 }
  207.             }
  208.  
  209.           }
  210.          
  211.          
  212.       /*
  213.       ______________________________________________________
  214.       |  Method:  Metric()                                 |
  215.       |  Author:  Dustin Tucker                            |
  216.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  217.       |  Params:                                           |
  218.       |  Returns:                                          |
  219.       |  Purpose:                                          |
  220.       |____________________________________________________|
  221.       */
  222.       public Metric (double metric1, String unitMetric1)
  223.          {
  224.             meter = 0;
  225.             unitMeter = "m";
  226.             centimeter = 0;
  227.             unitCentimeter = "cm";
  228.             millimeter = 0;
  229.             unitMillimeter = "mm";
  230.            
  231.             {
  232.                 if (unitMetric1.equalsIgnoreCase("m"))
  233.                 {
  234.                     this.meter = metric1;
  235.                     this.unitMeter = unitMetric1;
  236.                 }
  237.                 else if (unitMetric1.equalsIgnoreCase("cm"))
  238.                 {
  239.                     this.centimeter = metric1;
  240.                     this.unitCentimeter = unitMetric1;
  241.                 }
  242.                 else if (unitMetric1.equalsIgnoreCase("mm"))
  243.                 {
  244.                     this.millimeter = metric1;
  245.                     this.unitMillimeter = unitMetric1;
  246.                 }
  247.                 else
  248.                 {
  249.                     System.out.println("Invalid Entry");
  250.                     System.exit(0);
  251.                 }
  252.             }
  253.            
  254.           }
  255.          
  256.          
  257.       /*
  258.       ______________________________________________________
  259.       |  Method:  Metric()                                 |
  260.       |  Author:  Dustin Tucker                            |
  261.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  262.       |  Params:                                           |
  263.       |  Returns:                                          |
  264.       |  Purpose:                                          |
  265.       |____________________________________________________|
  266.       */
  267.       public Metric()
  268.           {
  269.             meter = 0;
  270.             unitMeter = "m";
  271.             centimeter = 0;
  272.             unitCentimeter = "cm";
  273.             millimeter = 0;
  274.             unitMillimeter = "mm";
  275.  
  276.           }
  277.  
  278.          
  279.          
  280.       /*
  281.       ______________________________________________________
  282.       |  Method:  setMeter()                               |
  283.       |  Author:  Dustin Tucker                            |
  284.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  285.       |  Params:                                           |
  286.       |  Returns:                                          |
  287.       |  Purpose:                                          |
  288.       |____________________________________________________|
  289.       */
  290.       public void setMeter(double meter)
  291.           {
  292.             //   method code;
  293.             this.meter = meter;
  294.  
  295.           }
  296.          
  297.          
  298.       /*
  299.       ______________________________________________________
  300.       |  Method:  setCentimeter()                          |
  301.       |  Author:  Dustin Tucker                            |
  302.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  303.       |  Params:                                           |
  304.       |  Returns:                                          |
  305.       |  Purpose:                                          |
  306.       |____________________________________________________|
  307.       */
  308.       public void setCentimeter(double centimeter)
  309.           {
  310.             //   method code;
  311.             this.centimeter = centimeter;
  312.  
  313.           }
  314.          
  315.          
  316.       /*
  317.       ______________________________________________________
  318.       |  Method:  setMillimeter()                          |
  319.       |  Author:  Dustin Tucker                            |
  320.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  321.       |  Params:                                           |
  322.       |  Returns:                                          |
  323.       |  Purpose:                                          |
  324.       |____________________________________________________|
  325.       */
  326.       public void setMillimeter(double millimeter)
  327.           {
  328.             //   method code;
  329.             this.millimeter = millimeter;
  330.  
  331.           }
  332.          
  333.          
  334.       /*
  335.       ______________________________________________________
  336.       |  Method:  getMeter()                               |
  337.       |  Author:  Dustin Tucker                            |
  338.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  339.       |  Params:                                           |
  340.       |  Returns:                                          |
  341.       |  Purpose:                                          |
  342.       |____________________________________________________|
  343.       */
  344.       public double getMeter()
  345.           {
  346.             //   method code;
  347.             return meter;
  348.           }
  349.          
  350.          
  351.       /*
  352.       ______________________________________________________
  353.       |  Method:  getCentimeter()                          |
  354.       |  Author:  Dustin Tucker                            |
  355.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  356.       |  Params:                                           |
  357.       |  Returns:                                          |
  358.       |  Purpose:                                          |
  359.       |____________________________________________________|
  360.       */
  361.       public double getCentimeter()
  362.           {
  363.             //   method code;
  364.             return centimeter;
  365.           }
  366.          
  367.          
  368.       /*
  369.       ______________________________________________________
  370.       |  Method:  getMillimeter()                          |
  371.       |  Author:  Dustin Tucker                            |
  372.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  373.       |  Params:                                           |
  374.       |  Returns:                                          |
  375.       |  Purpose:                                          |
  376.       |____________________________________________________|
  377.       */
  378.       public double getMillimeter()
  379.           {
  380.             //   method code;
  381.             return millimeter;
  382.           }
  383.          
  384.          
  385.       /*
  386.       ______________________________________________________
  387.       |  Method:  String toString()                        |
  388.       |  Author:  Dustin Tucker                            |
  389.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  390.       |  Params:                                           |
  391.       |  Returns:                                          |
  392.       |  Purpose:                                          |
  393.       |____________________________________________________|
  394.       */
  395.       public String toString()
  396.           {
  397.             System.out.println("The value set to meter is " + meter + unitMeter);
  398.             System.out.println("The value set to centimeter is " + centimeter + unitCentimeter);
  399.             return("The value set to millimeter is " + millimeter + unitMillimeter);
  400.            
  401.  
  402.           }
  403.          
  404.       /*
  405.       ______________________________________________________
  406.       |  Method:  calcValue()                              |
  407.       |  Author:  Dustin Tucker                            |
  408.       |  Date: Mon Oct 25 22:03:32 EDT 2010                |
  409.       |  Params:                                           |
  410.       |  Returns:                                          |
  411.       |  Purpose:                                          |
  412.       |____________________________________________________|
  413.       */
  414.       public void setValue(double metric1, String unitMetric1)
  415.           {
  416.                 if (unitMetric1.equals("m"))
  417.                 {
  418.                     this.meter = metric1;
  419.                     this.unitMeter = unitMetric1;
  420.                 }
  421.                 else if (unitMetric1.equals("cm"))
  422.                 {
  423.                     this.centimeter = metric1;
  424.                     this.unitCentimeter = unitMetric1;
  425.                 }
  426.                 else if (unitMetric1.equals("mm"))
  427.                 {
  428.                     this.millimeter = metric1;
  429.                     this.unitMillimeter = unitMetric1;
  430.                 }
  431.                 else
  432.                 {
  433.                     System.out.println("Invalid Entry");
  434.                     System.exit(0);
  435.                 }
  436.           }
  437.  
  438.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement