• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

data-type mismatch

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me first say thanks in advance for any help you can provide.

I keep getting this error
/*
incompatible types found : double
required: java.lang.Double
*/

heres my newbie code:

public class Package
{
double weight;
char shippingMethod;
double shippingCost;




public Package(int wgt,char shpMthd)
{
weight=(int)Math.ceil(wgt/16);

shippingMethod=shpMthd;

calculateCost();
}


public Double calculateCost()
{

switch(shippingMethod)
{

case 'A':
if(weight<9)
{
return (double)weight*2.00;break;
}
else if(weight>8 && weight<17)
{
return weight*3.00;break;
}
else
{
return weight*4.50;break;
}


case 'T':
if(weight<9)
{
return weight*1.50;break;
}
else if(weight>8 && weight<17)
{
return weight*2.35;break;
}
else
{
return weight*3.25;break;
}
break;

case 'M':
if(weight<9)
{
return weight*1.50;break;
}
else if(weight>8 && weight<17)
{
return weight*2.35;break;
}
else
{
return weight*3.25;break;
}
break;
default:
System.out.println("No shipping method provided!!!");
}
}





}
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public Double calculateCost()
probably should be
public double calculateCost()
(small d)
 
Mike MacDonald
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AWESOME it worked!!! OK here is another quickie:

this error:
<identifier> expected
System.out.println("Enter youre the weight of your package. ex.3.1");


this code:

//Weight
System.out.println("Enter youre the weight of your package. ex.3.1");

weight=System.in.read();
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<identifier> expected
often caused by mis-matched curly braces { and }
leaving the statement outside of a method
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic