[SOLVED] Help Again Last Part of my Problem :(

Hey guys.

Find attached the question

Quote:

At a party there are guests and a cake that will be cut into equal slices to give each guest a slice. Code an application (Q3) that, given the number of guests and the radius of the cake in cms, will output the length of each slice’s arc given that it must be an exact whole number of cms. If calculations show that the length of each slice’s arc will be less than a cm, output zero for the length to indicate the cake cannot be cut.

In addition output the cake’s circumference (total arc length), the total length of the arc used by all slices and the length of the arc that remains unused.

e.g. (see p 118-9 of the prescribed text to display only 2 decimal digits)

Enter the radius of the cake (in cms): 10.5

Enter number of guests? 5

total arc (circumference = 65.97

slice arc = 13.00

used arc = 65.00

left over arc = 0.97

Now Please find the code I have done so far.

Code Java:

import java.util.Scanner;
import java.text.DecimalFormat;
public class AS1Q3 {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
double radiusNum, cirCumference, sliceArc, usedArc, leftoverArc;
int numGuests;
System.out.print("Enter the radius of the cake (in cms): ");
radiusNum = scan.nextDouble();
System.out.print("Enter the number of guests?: ");
numGuests = scan.nextInt();
cirCumference = 2 * Math.PI * radiusNum;
//System.out.println(cirCumference);
sliceArc = cirCumference / numGuests;
leftoverArc = (cirCumference) - (sliceArc * numGuests);
DecimalFormat fmt = new DecimalFormat ("0.##");
System.out.println ("\ntotal arc = "+fmt.format(cirCumference)+"\nslice arc = "+fmt.format(sliceArc));
System.out.println (fmt.format(leftoverArc));
}
}

I seem to be having an issue getting the outputs to display properly as well as the maths behind the code to generate the values. well I think ive done my maths right :0

Basically my outputs are meant to show the following as above but I still get numbers being added after the decimal place when they need to be replaced with 0

Any advice is appreciated, I am not after the solution just need to be shown an example or guided in the right path.

Cheers

Matt

Re: Help Again Last Part of my Problem :(

Perhaps you are looking for the Math.round, Math.ceiling, and Math.floor?(assuming i understand the question you have)

Re: Help Again Last Part of my Problem :(

All good, I worked it out yesterday :)