Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ________________________________________________________________
- | Class: Metric |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Purpose: |
- | Create a OOP to display metric units of measurement in |
- | meters, centimeters, and millimeters in standard form. |
- | The program should allow for the user to create the |
- | object with all initial values, with one value and unit|
- | or with 2 values and units. The program should also be|
- | able to create the object with zeroed values. The |
- | program should allow the user to set or get any of the |
- | values. The program should normalize the values so |
- | they can be displayed in standard form. |
- |--------------------------------------------------------------|
- | Member Data: |
- | - double meter; |
- | - String unitMeter; |
- | - double centimeter; |
- | - String unitCentimeter; |
- | - double millimeter; |
- | - String unitMillimeter; |
- |--------------------------------------------------------------|
- | Methods: |
- | + String toString(); |
- | + Metric(double metric1, String unitMetric1, |
- | double metric2, String unitMetric2, |
- | double metric3, String unitMetric3); |
- | + Metric(double metric1, String unitMetric1, |
- | double metric2, String unitMetric2); |
- | + Metric(double metric1, String unitMetric1); |
- | + MetricConversion(); |
- | + void setMeter(double meter); |
- | + void setCentimeter(double centimeter); |
- | + void setMillimeter(double millimeter); |
- | + double getMeter(); |
- | + double getCentimeter(); |
- | + double getMillimeter(); |
- |______________________________________________________________|
- */
- public class Metric
- {
- // member data
- private double meter = 0;
- private String unitMeter = "m";
- private double centimeter = 0;
- private String unitCentimeter = "cm";
- private double millimeter = 0;
- private String unitMillimeter = "mm";
- /*
- ______________________________________________________
- | Method: Metric() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public Metric(double metric1, String unitMetric1, double metric2, String unitMetric2, double metric3, String unitMetric3)
- {
- {
- if (unitMetric1.equalsIgnoreCase("m"))
- {
- this.meter = metric1;
- this.unitMeter = unitMetric1;
- }
- else if (unitMetric1.equalsIgnoreCase("cm"))
- {
- this.centimeter = metric1;
- this.unitCentimeter = unitMetric1;
- }
- else if (unitMetric1.equalsIgnoreCase("mm"))
- {
- this.millimeter = metric1;
- this.unitMillimeter = unitMetric1;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- {
- if (unitMetric2.equalsIgnoreCase("m"))
- {
- this.meter = metric2;
- this.unitMeter = unitMetric2;
- }
- else if (unitMetric2.equalsIgnoreCase("cm"))
- {
- this.centimeter = metric2;
- this.unitCentimeter = unitMetric2;
- }
- else if (unitMetric2.equalsIgnoreCase("mm"))
- {
- this.millimeter = metric2;
- this.unitMillimeter = unitMetric2;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- {
- if (unitMetric3.equalsIgnoreCase("m"))
- {
- this.meter = metric3;
- this.unitMeter = unitMetric3;
- }
- else if (unitMetric3.equalsIgnoreCase("cm"))
- {
- this.centimeter = metric3;
- this.unitCentimeter = unitMetric3;
- }
- else if (unitMetric3.equalsIgnoreCase("mm"))
- {
- this.millimeter = metric3;
- this.unitMillimeter = unitMetric3;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- }
- /*
- ______________________________________________________
- | Method: Metric() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public Metric(double metric1, String unitMetric1, double metric2, String unitMetric2)
- {
- {
- if (unitMetric1.equals("m"))
- {
- this.meter = metric1;
- this.unitMeter = unitMetric1;
- }
- else if (unitMetric1.equals("cm"))
- {
- this.centimeter = metric1;
- this.unitCentimeter = unitMetric1;
- }
- else if (unitMetric1.equals("mm"))
- {
- this.millimeter = metric1;
- this.unitMillimeter = unitMetric1;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- {
- if (unitMetric2.equals("m"))
- {
- this.meter = metric2;
- this.unitMeter = unitMetric2;
- }
- else if (unitMetric2.equals("cm"))
- {
- this.centimeter = metric2;
- this.unitCentimeter = unitMetric2;
- }
- else if (unitMetric2.equals("mm"))
- {
- this.millimeter = metric2;
- this.unitMillimeter = unitMetric2;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- }
- /*
- ______________________________________________________
- | Method: Metric() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public Metric (double metric1, String unitMetric1)
- {
- {
- if (unitMetric1.equalsIgnoreCase("m"))
- {
- this.meter = metric1;
- this.unitMeter = unitMetric1;
- }
- else if (unitMetric1.equalsIgnoreCase("cm"))
- {
- this.centimeter = metric1;
- this.unitCentimeter = unitMetric1;
- }
- else if (unitMetric1.equalsIgnoreCase("mm"))
- {
- this.millimeter = metric1;
- this.unitMillimeter = unitMetric1;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- }
- /*
- ______________________________________________________
- | Method: Metric() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public Metric()
- {
- // blank;
- }
- /*
- ______________________________________________________
- | Method: setMeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public void setMeter(double meter)
- {
- // method code;
- this.meter = meter;
- }
- /*
- ______________________________________________________
- | Method: setCentimeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public void setCentimeter(double centimeter)
- {
- // method code;
- this.centimeter = centimeter;
- }
- /*
- ______________________________________________________
- | Method: setMillimeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public void setMillimeter(double millimeter)
- {
- // method code;
- this.millimeter = millimeter;
- }
- /*
- ______________________________________________________
- | Method: getMeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public double getMeter()
- {
- // method code;
- return meter;
- }
- /*
- ______________________________________________________
- | Method: getCentimeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public double getCentimeter()
- {
- // method code;
- return centimeter;
- }
- /*
- ______________________________________________________
- | Method: getMillimeter() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public double getMillimeter()
- {
- // method code;
- return millimeter;
- }
- /*
- ______________________________________________________
- | Method: String toString() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public String toString()
- {
- System.out.println("The value set to meter is " + meter + unitMeter);
- System.out.println("The value set to centimeter is " + centimeter + unitCentimeter);
- return("The value set to millimeter is " + millimeter + unitMillimeter);
- }
- /*
- ______________________________________________________
- | Method: calcValue() |
- | Author: Dustin Tucker |
- | Date: Mon Oct 25 22:03:32 EDT 2010 |
- | Params: |
- | Returns: |
- | Purpose: |
- |____________________________________________________|
- */
- public void setValue(double metric1, String unitMetric1)
- {
- if (unitMetric1.equals("m"))
- {
- this.meter = metric1;
- this.unitMeter = unitMetric1;
- }
- else if (unitMetric1.equals("cm"))
- {
- this.centimeter = metric1;
- this.unitCentimeter = unitMetric1;
- }
- else if (unitMetric1.equals("mm"))
- {
- this.millimeter = metric1;
- this.unitMillimeter = unitMetric1;
- }
- else
- {
- System.out.println("Invalid Entry");
- System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement