Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners write java code discount bookstore
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chean
write java code discount bookstore
1 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners



Advertisement
View Answers

November 12, 2009 at 2:35 PM


Hi Friend,

Try the following code:
import java.util.*;
class Books{
public String title;
public String author;
public int isbn;
public double price;
public double discount;
public double total;

public Books(){}
public Books(String title,String author, int isbn,double price,double discount,double total) {
super();
this.title=title;
this.author= author;
this.isbn = isbn;
this.price=price;
this.discount=discount;
this.total=total;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getIsbn() {
return isbn;
}
public double getPrice() {
return price;
}
public double getDiscount() {
return discount;
}
public double getTotal() {
return total;
}
}
public class BookStore {
public static void main(String[] args) throws Exception {
double amount=0.0;
double sum=0.0;
int count=1;
List<Books> list = new ArrayList<Books>();
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("Book Store");
System.out.println();
System.out.println("1. Buy book");
System.out.println("2. Receipt");
System.out.println("3. Receive Payment");
System.out.println("4. Exit");
boolean quit = false;
do{
if(count>5){
System.out.println("You cannot buy more than 5 books at a time.");
}
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();
switch(menu) {
case 1:
count++;
System.out.println("Book Title: ");
String booktitle = scan.next();
System.out.println("Author: ");
String auth = scan.next();
System.out.println("ISBN: ");
int no = scan.nextInt();
System.out.println("Price: ");
double p = scan.nextDouble();
System.out.println("Discount: ");
double dis = scan.nextDouble();
double total=p-(dis*p);
list.add(new Books(booktitle,auth,no,p,dis,total));
break;
case 2:
System.out.println("Title Author ISBN Price Discount Total");
for (Books s : list){
System.out.println(s.getTitle()+" " +s.getAuthor()+" " +s.getIsbn()+" "+s.getPrice()+" " +s.getDiscount()+" " +s.getTotal());
sum+=s.getTotal();
}
System.out.println("Total= "+sum);
break;
case 3:
System.out.println("Customer Pays: ");
amount = scan.nextDouble();
double balance=amount-sum;
System.out.println("Balance is: "+balance);
quit = true;
case 4:
quit = true;

break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}

Thanks


Related Tutorials/Questions & Answers:
write java code discount bookstore - Java Beginners
write java code discount bookstore  The question Cik Mat operates bookstore. During their promotion period, there are books which are sold with special discounts, while others are sold at normal price. Write a program which
the discount system.
the discount system.  hi.. im a beginner here in java. sadly i was asked to code this one. about inheritance. and i absolutely dont know how.. will someone will help me with this? please. i was asked to write a discount system
Advertisements
the discount system.
the discount system.  hi.. im a beginner here in java. sadly i was asked to code this one. about inheritance. and i absolutely dont know how.. will someone will help me with this? please. i was asked to write a discount system
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
help to write java code
help to write java code  write a full code to produce a system will calculate all items to get total carry-marks which are 60 marks. and get sum of assignment 1,assignment 2, midterms-test and lave work to get total marks
discount system.
discount system.   i was asked to write a discount system... receive a discount of 20%, 15%, and 10% respectively, for all services provided. Customers without membership receive no discount. all members receives a flat 10
write simple java code - Java Beginners
write simple java code  Write a program that creates a simple calculator .The user enters two numbers in the text fields, Number 1 and Number 2... the following code: import java.awt.*; import javax.swing.*; import
How to write a session code - Java Beginners
How to write a session code   Once Again Thanks Deepak...Thanks for continuing responce I want using session in my project plz help me how to write a session code plz write a session code and post answer my personal id
How to write a error.jsp code - Java Beginners
How to write a error.jsp code  Thanks once again I have a session code pls help me that how can i write a error.jsp page. why use error.jsp...let me know that hw can i write the error.jsp code. plz send me error.jsp code
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss ... that were ever alive at one time. Write a method to compute this, given the above array of 2n integers. Write one of the following methods: C/C++: int
Java Application for Book Store
Java Bookstore Application In this Java Tutorial section, we have created a Java Bookstore Application through which a customer can buy books and online pay... at a time. Here is the code: import java.util.*; class Books { public
write code in c#
write code in c#  sir I want to write a save and save as code in the c#(windosForm).Please help me
how to write code for this output?
how to write code for this output?   1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Write JQUERY Code
Write JQUERY Code  Hi, Iam swathi.I created the table in the below format.can u please write the jquery code of this table..and my requirement... please send me the code through jquery..? Thank you Swathi
Write JQUERY Code
Write JQUERY Code  Hi, Iam swathi.I created the table in the below format.can u please write the jquery code of this table..and my requirement... please send me the code through jquery..? Thank you Swathi
online bookstore - JSP-Servlet
online bookstore  i want to display some books like online shoping.please send me code for that using jsp and servlets
online bookstore - JSP-Servlet
online bookstore  i want code for online bookshop.please send mo soon..........  Hi Friend, Please specify some details. Thanks
Can i write JavaScript code in AjaxResponse Code ?
Can i write JavaScript code in AjaxResponse Code ?  Hai Every Dynamic's We can't write JavaScript code in Ajax Response Code.Why because it takes only html,json,xml response.I tried a lot to create js form in ajax response.It
How to write jsp/servlet code to integrate LINKDIN?
How to write jsp/servlet code to integrate LINKDIN?  How integrate linkdin api's in java codding
JAVA Write code which converts propositional expressions into clauses using the INOA rules
JAVA Write code which converts propositional expressions into clauses using the INOA rules  Write code which converts propositional expressions... are: or not p q or not p r Turn in: ΓΆβ?¬ΒΆ Printout of your code. ΓΆβ?¬ΒΆ Test
Java write to file
Java write to file  How to write to a file in Java? Is there any good example code here? Thanks   Hi, Java is one of the best... files. You can easily use the the FileWriter and BufferedWriter to write data
How to write the code for date in swings - Struts
How to write the code for date in swings  Hi Friends, I want to code for display the calendar.......technologies use only swing and core java also how to display calendar like that popup window.....please write and send me
How to Write to a File in Java without overwriting
Learn how to Write to a File in Java without overwriting in your Java program This tutorial teaches you how to write to a file in Java without overwriting... In the above program you have learned how to write code to to append the content
write a java program
write a java program  write a program to print '*' in a circular form
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
write a programm using java
write a programm using java  print the following using java programming
write java prgram
write java prgram  write java program to offer a menu which contains 3 choices to make calculation on 3 shapes.use method for each calculation
write the java program?
write the java program?  1 11 121 1331 14641 15101051
write the java program?
write the java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
Advertisements
 

 

 

DMCA.com