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.