Converting Decimal point string to Double or any other way?

Joined
Aug 5, 2007
Messages
1
Reaction score
0
Hey there , i am new to java for 3 weeks ryte now and i have assignment to Finish it up overall i am ok with java though, my problem is that how do i limit decimal point to #.## or 0.00 which is the same am i right?



My assignment was to do a shopping cart i using switch cases instead of loops with if else.. but its come to the same ..

the price is 0.02 per grams (paper) provided in the .class given


before that here's is the class diagram:
which name ShoppingCart.class


ShoppingCart(name: String) <-- i name it as FishCart
calculateTotalAmount(): double
displayItemsInCart()
printReceipt()



case 4:

System.out.println("Dear Customer Please enter 'T'(PrintReceipt) or 'F'(Discard Items) : ");
String print = sc.next();
sc.nextLine();

if(print.equalsIgnoreCase("T"))
{
DecimalFormat df = new DecimalFormat("#.##");
String a = df.format(FishCart.calculateTotalAmount());


//not sure how minimise the decimal format on printreceipt and implement it.

FishCart.printReceipt();

System.out.println("Thank you for Shopping :)");
System.out.println("System is exiting ...........");


System.exit(0);

}

else if (print.equalsIgnoreCase("F"))
{
double RemovedGramz = 0.00;
double RemovedLengthz = 0.00;

/* cant seem to remove it. it show the display but the value is not cleared.
how to check the think is removed?*/


FishCart.removePaper(RemovedGramz);
FishCart.removeRibbon(RemovedLengthz);
System.out.println("Items Discarded");
FishCart.displayItemsInCart();

System.out.println("Thank you for Shopping :)");
System.out.println("System is exiting ...........");

System.exit(0);

}
break;





this the preview :

ptlR.jpg


I hope you guys can help me in this ..

Thanks in Advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top