Question

CSC110 EXAM06A Objects NAME: class meters2feet private double meters; public void setMeters (double m) {meters=m ; } public d
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// meters2feet.java

public class meters2feet {
   private double meters;
   public void setMeters(double m)
   {
       meters=m;
   }
   public double getMeters()
   {
       return meters;
   }
   public double convert2feet()
   {
       return meters*3.2808;
   }  
}

____________________________

// meters2inches.java

public class meters2inches {
   private double meters;
   public void setMeters(double m)
   {
       meters=m;
   }
   public double getMeters()
   {
       return meters;
   }
   public double convert2inches()
   {
       return meters*39.3701;
   }  
}
___________________________

//Test.java

package org.students;

import java.util.Scanner;

public class Test {

   public static void main(String[] args) {

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
      
   double meters,inches,feet;
       meters2feet mf=new meters2feet();
       meters2inches mi=new meters2inches();
      

       System.out.print("Enter meters (-1 to exit):");
       meters=sc.nextDouble();
       mf.setMeters(meters);
       mi.setMeters(meters);
      
       while(meters!=-1)
       {
       System.out.println(meters+" meters is "+mi.convert2inches()+" inches");  
       System.out.println(meters+" meters is "+mf.convert2feet()+" feet");
      
       System.out.print("Enter meters (-1 to exit):");
       meters=sc.nextDouble();
       mf.setMeters(meters);
       mi.setMeters(meters);  
       }
         

   }

}
___________________________

Output:

Enter meters (-1 to exit):34.5
34.5 meters is 1358.26845 inches
34.5 meters is 113.1876 feet
Enter meters (-1 to exit):32.3
32.3 meters is 1271.6542299999999 inches
32.3 meters is 105.96983999999999 feet
Enter meters (-1 to exit):-1

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
CSC110 EXAM06A Objects NAME: class meters2feet private double meters; public void setMeters (double m) {meters=m ;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class Item implements Comparable { private String name; private double price; /** * Constructor for...

    public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; }    /** * gets the name * @return name name of item */ public String getName() { return name; }    /** * gets price of item * @return price price of item */...

  • class Circle { private double radius; public Circle(double radius) { radius = radius; } } public...

    class Circle { private double radius; public Circle(double radius) { radius = radius; } } public Circle(double radius) { radius = radius; } } The program does not compile because Circle does not have a default constructor. The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0. The program has a compilation error because it does not have a main method. The program has a compile error...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • C++ class derivedFromTemp: public temp; {public:    void print();    void setZ(double);    double getZ();   ...

    C++ class derivedFromTemp: public temp; {public:    void print();    void setZ(double);    double getZ();    double power() const; //return X to power of Z assume getX and setX in temp class.       drivedFromTemp();    derivedFromTemp (string, double, double); Private:    double z; }; A. Correct errors, if any, after that write difinition of the member function of the class derivedFromTemp.

  • public class CylindricalTank {    private String idTag;           // Unique String identifying the tank...

    public class CylindricalTank {    private String idTag;           // Unique String identifying the tank    private double radius;           // The non-negative radius of the base of the tank in meters    private double height;           // The non-negative height of the tank in meters    private double liquidLevel;       // The current height of the liquid in the tank in meters    /**    * CylindricalTank General Constructor    */    public CylindricalTank(String tag, double...

  • import java.util.Scanner; public class Cat { private String name; private Breed breed; private double weight; public...

    import java.util.Scanner; public class Cat { private String name; private Breed breed; private double weight; public Cat(String name, Breed breed, double weigth) { this.name = name; this.breed = breed; this.weight = weight; } public Breed getBreed() { return breed; } public double getWeight() { return weight; } //other accessors and mutators ...... } public class Breed { private String name; private double averageWgt; public Breed(String name,double averageWgt) { this.name = name; this.averageWgt= averageWgt; } public double getWeight() { return averageWgt;...

  • Homework-2 – Working with a class. Problem: Attached with this homework is code for a class...

    Homework-2 – Working with a class. Problem: Attached with this homework is code for a class called DroppedObject. This class is used to to store the state of a falling object. The problem this class/object can be used to solve is detailed below. Your task for this homework is to read and understand the attached class. Note this class is formatted like all classes should be with private variables, constructors, a toString method, getter and setter methods, and other relevant...

  • Java. What is the output of this code? Ace.java public class Ace { private double a;...

    Java. What is the output of this code? Ace.java public class Ace { private double a; public Ace ( double x) {       a = x; } public void multiply (double f) {       a *= x;         } public String toString () {       return String.format ("%.3f", x); AceDem.java public class AceDemo { public static void main(String args[]) {    Ace card = new Ace (2.133); card.multiply (.5); System.out.println (card); } }

  • Provided code Animal.java: public class Animal {    private String type;    private double age;   ...

    Provided code Animal.java: public class Animal {    private String type;    private double age;       public Animal(String aT, double anA)    {        this.type = aT;        if(anA >= 0)        {            this.age = anA;        }    }    public String getType()    {        return this.type;    }    public double getAge()    {        return this.age;    } } Provided code Zoo.java: public class Zoo {...

  • I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[]...

    I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[] = new double[ch.length]; int p = 0; for (int i = 0; i < ch.length; i += 3) { p = i + 1; for(int j = 0;j } } error message:items.java:16: error: cannot find symbol for(int j = 0;j ^ symbol: variable length location: class Object items.java:17: error: array required, but Object found salePrice[j] = (double full program import java.io.File; import java.util.Scanner; import...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT