Re: Can anyone help me?? using scanner stdin??

This post is from the topic: Can anyone help me?? using scanner stdin??





s

keyboard_arrow_up
0
keyboard_arrow_down


Post #29746 shadachi
Posted: 2007-07-03 11:10:10
This is the question?.. can anyone help me?? kinda confused..


A wholesale book dealer needs a program to write invoices for book orders that he takes for a customer over the phone. Each order usually consists of multiple copies of several book titles. The program should ask the user if there is an order to process. If the user responses yes, then the program should ask for the price of the first book in the order and the number of such books. The program should then display the cost of these books, including a 7.5% sales tax. Then the program should ask if there is another order. If there is one, the program should process it as just described. If there are no more orders, the program should display the total number of orders processed, the total number of books sold, and the total receipts.



SAmple Output :


Is there an order to process (Y/N)? y

Enter the price for book 1: RM 20.00
Enter the quantity for book 1: 3
Cost for book 1: RM64.50

Is there an order to process (Y/N)? y

Enter the price for book 2: RM 50.00
Enter the quantity for book 2: 2
Cost for book 2: RM 107.50

Is there an order to process (Y/N)? y

Enter the price for book 3: RM 40.00
Enter the quantity for book 3: 2
Cost for book 3: RM 86.00

Is there an order to process (Y/N)? y

Enter the price for book 4: RM 10.00
Enter the quantity for book 4: 3
Cost for book 4: RM 32.25

Is there an order to process (Y/N)? n

Total number of orders processed: 4
Total number of books sold: 10
Total price: RM 290.25



I kinda messed up alot..
here is my codes..


import java.util.*;
import java.text.DecimalFormat;
import java.lang.Double;


public class Book {



public static void main(String args[]){

int process;
double price;
int quantity;
int quantity1=0;
double sum=0.00;
double sum1=0.00;
double cost=0.00;
String Result="";


DecimalFormat twoDigits = new DecimalFormat("0.00");
Scanner stdin= new Scanner(System.in);


System.out.print("Is there an order to process? (Y?N)");

Result= stdin.next();


do

{
System.out.print("Enter the price for book %d: RM ");

price = stdin.nextDouble();

System.out.print("Enter the quantity for book %d: ");

quantity = stdin.nextInt();


quantity1 = quantity1 + quantity;

cost = (double)((price * quantity) * 1.075);

System.out.println("Cost for book %d: %.2lf \n");

sum1 = sum + cost;
count++;

System.out.print("Is there an order to process? (Y?N)");


}while ((Result =='y'));

System.out.println("\nTotal number of orders processed:%d "+count);
System.out.println("\nTotal number of books sold:%d "+quantity1);
System.out.println("\nTotal price:%.2lf \n"+sum1);





}
}



JOIN DEVPPL

It looks like you are new here. If you want to get involved, click on Join below!




MENU
Advertising