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 4 of 4

Thread: Point of sale

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

    Default Point of sale

    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:
    1. A man apart by author1, priced at $20
    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:
    5 1
    1 2
    end

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

    Example input 2:
    1 1
    1 1
    0 1
    End

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

    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,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Point of sale

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    Be sure the code is properly indented.

    Please let me know if my logic is correct
    Does the code generate the correct output? That would be one requirement.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Point of sale

    yes it does.I would really appreciate it if your could code another alternative to the method i have started using as per the question above.The are to possible outputs outlined above.Thanks so very much.

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

    Default Re: Point of sale

    Sorry, I don't do much coding here.

    The posted code needs to be formatted. Nested statements should not start in the first column.
    }s should not be in the same column.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Point of sale in Java
    By kreek in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 1st, 2012, 01:52 PM
  2. regarding floating point
    By deependeroracle in forum Java Theory & Questions
    Replies: 3
    Last Post: January 10th, 2012, 11:18 AM
  3. [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
  4. Point constructor
    By upad in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 5th, 2010, 07:34 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