Mike MacDonald

Greenhorn
+ Follow
since Jan 24, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike MacDonald

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();
18 years ago
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!!!");
}
}





}
18 years ago

Originally posted by Ray Stojonic:
The good news: your mask is just fine.

The bad news: Your algorithm is not doing what you are expecting it to do. Try outputting the value of percentGirls without formatting it to see what I mean.



//Here is my output without the mask:

Percent Females: 41.66666666666667

//Heres the algorithm:

//percentages by gender
double percentGirls=(((double)totalGirls/totalStudents)*100);

System.out.println("Percent Females:"+" "+percentGirls);
19 years ago

Originally posted by Ray Stojonic:
The good news: your mask is just fine.

The bad news: Your algorithm is not doing what you are expecting it to do. Try outputting the value of percentGirls without formatting it to see what I mean.

19 years ago
//I am trying to output a percent value to look like this:
41.7%

//but my output looks like this:
4166.7%

//here is my attempt at a formatted mask:

DecimalFormat msk1=new DecimalFormat("##.0%");

//and here is my code using the mask:

System.out.println("Percent Females:"+" "+msk1.format(percentGirls));


/*My instructor didn't really explain the ins and out of proper format masking syntax so this is my newbie guess. Any help and insight on proper formatting would be awesome*/
19 years ago