Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Point of sale in Java

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Point of sale in Java

    Hi guys can u help me do this in java, i am new to java

    command line Point of Sale system that can calculate discounts and totals. The system should be for selling books and it should contain the following products:<br><br>
    1. A man apart by author1, priced at $20<br>
    2. Uncharted by author2, priced at $40

    If you purchase two copies of a book, you get an 8 % discount on those two. If you buy three copies or more, you get 20 % discount on all of them.

    The system accepts input where you specify the number of items and the id of the book and then you press enter. When you are done you type “end” and press enter.

    Example input:<br><br>
    5 1<br>
    1 2<br>
    end

    Example output:<br>
    5 copies of A man apart: $80.00<br>
    1 copy of Uncharted: $40.00<br>
    Total price: $120.00<br>

    Example input 2:<br>
    1 1<br>
    1 1<br>
    0 1<br>
    End

    Example output 2:<br>
    2 copies of A man apart: $36.80<br>
    Total price: $36.80<br><br>

    package pos;

    import java.util.Scanner;


    public class Pos {


    public static void main(String[] args) {
    System.out.print("Please enter the quantity along with a book book code (1,2, etc) "
    + "from the list.Please space you entry.\n ");
    System.out.print("1.A man apart by author1 - Price: $ 20\n "
    + "2.Uncharted by author2 - Price: $ 40\n Quantity and Book Code:\n");

    int bkprice1 = 20;
    int bkprice2 = 40;

    String book1 = "Hunger Games";
    String book2 = "Clean Code by Robert C. Martin";
    float Totalbk1 = 0;
    float Totalbk2 = 0;
    float Totalbk1L1 = 0;
    float Totalbk2L1 = 0;
    float Totalbk2L2 = 0;
    float Totalbk3 = 0;
    float Total;
    float Disc;

    try (Scanner in = new Scanner(System.in)) {

    int qty = in.nextInt();
    int code = in.nextInt();
    int qty2 = in.nextInt();
    int code2 = in.nextInt();
    String tt = in.next();
    int qty3;



    if (qty == 2 && code == 1) {
    Disc = (float) ((float) (qty*bkprice1)*(0.08));
    Totalbk1 = (float) (qty*bkprice1) - Disc;
    System.out.println(qty+" copies of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    } else if (qty > 2 && code == 1) {
    Disc = (float) ((float) (qty*bkprice1)*(0.2));
    Totalbk1 = (float) (qty*bkprice1) - Disc;
    System.out.println(qty+" copies of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    } else if (qty <= 1 && code == 1) {
    Totalbk1 = (float) (qty*bkprice1);
    System.out.println(qty+" copy of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    }

    if (qty2 == 2 && code2 == 1) {
    Disc = (float) ((float) (qty2*bkprice1)*(0.08));
    Totalbk1 = (float) (qty2*bkprice1) - Disc;
    System.out.println(qty2+" copies of "+book1+": GHC "+Totalbk1);
    Total = Totalbk1L1 + Totalbk1;
    System.out.println("Total price: "+Total);
    } else if (qty2 > 2 && code2 == 1) {
    Disc = (float) ((float) (qty2*bkprice1)*(0.2));
    Totalbk1 = (float) (qty2*bkprice1) - Disc;
    System.out.println(qty2+" copies of "+book1+": GHC "+Totalbk1);
    Total = Totalbk1L1 + Totalbk1;
    System.out.println("Total price: "+Total);
    } else if (qty2 <= 1 && code2 == 1) {
    Totalbk1 = (float) (qty2*bkprice1);
    System.out.println(qty2+" copy of "+book1+": GHC "+Totalbk1);
    Total = Totalbk1L1 + Totalbk1;
    System.out.println("Total price: "+Total);
    }




    if (qty == 2 && code == 2) {
    Disc = (float) ((float) (qty*bkprice2)*(0.08));
    Totalbk2 = (float) (qty*bkprice2) - Disc;
    System.out.println(qty+" copies of "+book2+": GHC "+Totalbk2);
    Totalbk2L1 = Totalbk2;

    } else if (qty > 2 && code == 2) {
    Disc = (float) ((float) (qty*bkprice2)*(0.2));
    Totalbk2 = (float) (qty*bkprice2) - Disc;
    System.out.println(qty+" copies of "+book2+": GHC "+Totalbk2);
    Totalbk2L1 = Totalbk2;

    } else if (qty <= 1 && code == 2) {
    Totalbk2 = (float) (qty*bkprice2);
    System.out.println(qty+" copy of "+book2+": GHC "+Totalbk2);
    Totalbk2L1 = Totalbk2;

    }


    if (qty2 == 2 && code2 == 2) {
    Disc = (float) ((float) (qty2*bkprice2)*(0.08));
    Totalbk2 = (float) (qty2*bkprice2) - Disc;
    System.out.println(qty2+" copies of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    } else if (qty2 > 2 && code2 == 2) {
    Disc = (float) ((float) (qty2*bkprice2)*(0.2));
    Totalbk2 = (float) (qty2*bkprice2) - Disc;
    System.out.println(qty2+" copies of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    } else if (qty2 <= 1 && code2 == 2) {
    Totalbk2 = (float) (qty2*bkprice2);
    System.out.println(qty2+" copy of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    }



    if (qty == 2 && code == 1) {
    Disc = (float) ((float) (qty*bkprice1)*(0.08));
    Totalbk1 = (float) (qty*bkprice1) - Disc;
    System.out.println(qty+" copies of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    } else if (qty > 2 && code == 1) {
    Disc = (float) ((float) (qty*bkprice1)*(0.2));
    Totalbk1 = (float) (qty*bkprice1) - Disc;
    System.out.println(qty+" copies of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    } else if (qty <= 1 && code == 1) {
    Totalbk1 = (float) (qty*bkprice1);
    System.out.println(qty+" copy of "+book1+": GHC "+Totalbk1);
    Totalbk1L1 = Totalbk1;

    }


    if (qty2 == 2 && code2 == 2) {
    Disc = (float) ((float) (qty2*bkprice2)*(0.08));
    Totalbk2 = (float) (qty2*bkprice2) - Disc;
    System.out.println(qty2+" copies of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    } else if (qty2 > 2 && code2 == 2) {
    Disc = (float) ((float) (qty2*bkprice2)*(0.2));
    Totalbk2 = (float) (qty2*bkprice2) - Disc;
    System.out.println(qty2+" copies of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    } else if (qty2 <= 1 && code2 == 2) {
    Totalbk2 = (float) (qty2*bkprice2);
    System.out.println(qty2+" copy of "+book2+": GHC "+Totalbk2);
    Total = Totalbk2L1 + Totalbk2;
    System.out.println("Total price: "+Total);
    }



    }
    }
    }


    Please let me know if my logic is correct. I want my code to be as succinct as possible.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Point of sale in Java

    Please don't post the same question in different sections.

    This thread is closed.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Program that plots point on a graph..need some help.
    By neontiger in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 10th, 2012, 07:55 PM
  2. Replies: 2
    Last Post: November 30th, 2011, 07:35 PM
  3. Replies: 3
    Last Post: September 8th, 2011, 02:25 PM
  4. [SOLVED] Someone point me to the right direction..
    By ineedhelp in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: June 30th, 2011, 10:03 PM
  5. how do i use point 3d?
    By antrax in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 05:13 PM

Tags for this Thread