Question: Java Coding Question using Enum class scales.java: Finish the following money converter class. This class will use negative money values as well. The conversion between
Java Coding Question using Enum class scales.java:
Finish the following money converter class. This class will use negative money values as well. The conversion between the currencies will not be real but based on celsius, farenheit and kelvin.
Dollars = Celsius. Euros = farenheit. Pound = kelvin.
The default price is dollars. the calculations for conversion are:
Dollars --> Euros =(Dollars amount 9/5) + 32
Dollars --> Pound =(Dollars amount + 273.15)
we will use D for dollars, E for euros, and P for pounds
public class Money{
//Creates a Money object with given value in dollars
//If the initial money is less than -270.5D then the money
//object will be created with -270.5D.
//The mon parameter is the initial money amount in dollars
public Money(double mon){
}
//Creates a money object with given value using the specified scale parameter
//if the money amount is lower than -270.5 than set money amount to -270.5 in the provided scale
//Exemplar: new Money(14.1, Scale.pound)
//"mon" parameter is the initial money amount
//"scale" parameter is the scale of the initial money amount and must be a constant and must be defined properly in the enum Scale type
public Money(double mon, Scale scale){
}
//Creates a money object with given value using the given scale
//if the money amount is lower than -270.5 than set money amount to -270.5 in the provided scale
//Exemplar: all of the following should create the same Money 7.7P
// new Money(7.7, "Pounds")
// New Money(7.7, "Pound")
// new Money(7.7, "P")
// new Money(7.7, "POUnd")
//"mon" parameter is the initial money amount.
//"scale" parameter is the scale of the initial money amount. It should be able to identify abreviations aswell as lower case and upper case and a mix of them
public Money(double mon, String scale){
}
//getter method for the scale. Output must always be an enum object from the Scale
//returns the current scale of the object.
public Scale getScale(){
return Scale.NONE;
}
//getter method for the money amount
//returns the money amount of the object using the latest scale
public double getMon(){
return -Double.MAX_VALUE;
}
//setter method for the scale
// "scale" parameter is the new scale of the money amount and must be a constant always of the enum scale type
public void setScale(Scale scale){
}
// setter method for money
// if the money amount is lower than -270.5 than set money amount to -270.5 in the provided scale
//"mon" parameter is the new money amount
//"scale" parameter is the new scale of the money amount and must be a constant always of the enum scale type
public void setMon(double mon, Scale scale){
}
//WARNING: dont change under this any code
//WARNING: dont change under this any code
//WARNING: dont change under this any code
//WARNING: dont change under this any code
public String toString(){
return "" + this.getMon() + this.getScale().name().charAt(0);
}
}
Here is a tester class. Please use it to test the code
public class MoneyTester{
public static void main(String[] args){
Scale s = Scale.dollars; // a variable of an enum type
Money m1 = new Money(65.1, s);
Money m2 = new Money(32.2, Scale.euros);
boolean x = Scale.dollars== s; // will be true! can compare with ==
System.out.println("Create Money amount object")
Money m = new Money(178.3);
System.out.println(" m.getScale() " + m.getScale()); // outputs Scale.dollars.toString()
System.out.println("m.toString() " + m); // outputs 178.3D
System.out.println("m.setScale(Scale.euros)");
m.setScale(Scale.euros); // changes scale
System.out.println("m.toString() " + m); // outputs 352.94E
System.out.println(">> m.getScale() " + m.getScale()); // outputs Scale.euros.toString()
m = new Money(11.11, "Poun"); // must recognize short form
System.out.println("m.toString() " + m); // outputs 11.11P
}
}
Thanks in advance. I will make sure to thumbs up correct answer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
