Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment: a - means private and and a + means public For attributes, - ID: String means a private String attribute with the

In this assignment:

  • a - means private and and a + means public
  • For attributes, - ID: String means a private String attribute with the name ID.
  • A {read only: 3} attribute is a constant and its value is 3
  • For methods, - calcDis(double,int): double means a private method that receives an integer and a double as its inputs and return a String and the name of the method is calcDis.

Create a Converter class with the below characteristics:

  • + POUND _ TO _ KG: double {read only: 0.45} (please remove the spaces in the name)
  • + FOOT _ TO _ METER: double {read only: 0.3048} (please remove the spaces in the name)
  • - doubleVal: double
    • And a set method
  • - stringVal: String
    • And a set method
  • - intVal: int
    • And a set method
  • + intToChar: char
    • Converts the intVal to character and returns it
  • + doubleToInt(): int
    • Converts the doubleVal to int and returns it
  • + stringToDouble(): double
    • Converts the stringVal to double and returns it
  • + poundToKG(double): double
    • Converts the input parameter to kilograms and returns it
    • For doing this, uses the POUNDTOKG constant
  • + footToMeter(double): double
    • Converts the input parameter to meters and returns it
    • For doing this, uses the FOOTTOMETER constant

Below is the code: I keep on getting an error message that says : error: incompatible types: possible lossy conversion from double to int int i = c1.doubleToInt(); ^ 1 error

import java.text.DecimalFormat; import java.util.Scanner;

class Converter { public static final double POUND_TO_KG = 0.45; public static final double FOOT_TO_METER = 0.3048; private double doubleVal; private String stringVal; private int intVal; public int i; public char intToChar() { return (char) intVal; } public double doubleToInt() { return i = (int) Math.round(doubleVal);

}

public double stringToDouble() { return Double.parseDouble(stringVal); }

public double poundToKG(double pounds) { return pounds * POUND_TO_KG; }

public double footToMeter(double foot) { return foot * FOOT_TO_METER; }

public void setDoubleVal(double doubleVal) { this.doubleVal = doubleVal;

}

public void setStringVal(String stringVal) { this.stringVal = stringVal;

}

public void setIntVal(int intVal) { this.intVal = intVal;

}

}

public class Main {

public static void main(String[] args) { // // DecimalFormat df = new DecimalFormat("0.00"); // // Scanner scnr = new Scanner(System.in); //Converter c1= new Converter(); //int pounds = c1.doubleToInt();

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions