Hi,
I have a problem with a code i have done but i just a problem..If u look at what i have attached and try to run it..It gave me a problem as i am meant to have a menu which is meant to show something inside it but the menu is coming up but with nothing inside it..I have tried adding ingredients and saving it but still nothing happens..please could anyone help me out..
I couldnt upload the last two so here they are:
UNITCONVERTER.JAVA
import java.text.DecimalFormat;
import java.util.HashMap;
/*
* The WeightConverter class provides a method to convert a unit to another specified unit
*/
public class UnitConverter
{
private HashMap Units; //The collection which stores the unit objects
private DecimalFormat myFormatter = new DecimalFormat("#.##");
public UnitConverter()
{
Units=new HashMap();
//CAPACITY
Units.put("ml",new Unit("ml",0.001,101));
Units.put("gills",new Unit("gills",0.142,102));
Units.put("pt",new Unit("pt",0.568,103));
Units.put("liter",new Unit("liter",1,104));
Units.put("qt",new Unit("qt",1.136,105));
Units.put("gal",new Unit("gal",4.546,106));
//WEIGHT
Units.put("mg",new Unit("mg",0.001,201));
Units.put("cg",new Unit("cg",0.01,202));
Units.put("gr",new Unit("gr",0.065,203));
Units.put("gram",new Unit("gram",1,204));
Units.put("dr",new Unit("dr",1.77,205));
Units.put("oz",new Unit("oz",28.35,206));
Units.put("kg",new Unit("kg",1000,207));
Units.put("lb",new Unit("lb",454,208));
Units.put("st",new Unit("st",6356,209));
}
/**
* Return a String for new format "number+unit"
* Parameters: value-the quantity of the unit
* unit-the current unit
* format-the specified unit
*/
public String format(double value,String unit,String format)
{
String result=null;
Unit CurrentUnit=(Unit) Units.get(unit.toLowerCase());
Unit TargetUnit=(Unit) Units.get(format.toLowerCase());
if(TargetUnit.getMetricRate()==CurrentUnit.getMetricRate())
{
result=value+""+unit;
}
else
{
double temp=value*CurrentUnit.getMetricRate()/TargetUnit.getMetricRate();
result=myFormatter.format(temp)+""+format;
}
return result;
}
public double convert(double value,String unit,String format)
{
double result=0;
Unit CurrentUnit=(Unit) Units.get(unit.toLowerCase());
Unit TargetUnit=(Unit) Units.get(format.toLowerCase());
if(TargetUnit.getMetricRate()==CurrentUnit.getMetricRate())
{
result=value;
}
else
{
double temp=value*CurrentUnit.getMetricRate()/TargetUnit.getMetricRate();
result=temp;
}
return result;
}
}
UNIT.JAVA
/**
* Write a description of class Unit here.
*
* @author (your name)
* @version (a version number or a date)
*/
/**
* This is the class of Unit instance
* The Unit will have a value which means the rate with 1 metric unit for
* example, 1 litre,1 gram
*/
public class Unit
{
private String name; //The name of the unit
private double MetricRate; //The rate of this unit to metric unit
private int index; //The index of this unit
public Unit(String name,double MetricRate,int index)
{
this.name=name;
this.MetricRate=MetricRate;
this.index=index;
}
public String getName(){return name;}
public double getMetricRate(){return MetricRate;}
public int getIndex(){return index;}
public void setName(String name){this.name=name;}
public void setMetricRate(double MetricRate){this.MetricRate=MetricRate;}
public void setIndex(int index){this.index=index;}}
PLEASE TRY TO RUN EVERYTHING AND SEE WHAT IM TALKING ABOUT...thanx in advance