Cash Register - Using BigDecimal Instead Of Double
Jul 1, 2014
I wrote this one all by myself (AND it works!!), but I know that to get really accurate results I need to use BigDecimal instead of Double. The problem is that I can't quite figure out how to do that. How to switch those out?
import java.util.Scanner;
public class CashReg
{
public static void main( String[] args )
{
Scanner userInput = new Scanner(System.in);
String due;
String tend;
I have to make cash register system for saloon. it will look like this but I dont know how to do it.
Example : if customer come to make a hair cut. I will click on c button and choose her hair length then the price will come out. Each hair length will have different price. The customer will give the money and the total will show the customer money and the balance will come out after the total is deduct with the price.
I'm writing this super simple code as I follow along in this java textbook, and I don't know why it's giving me an error in my tester program!
CashRegister.java
public class CashRegister //a cash register totals up sales and computes change due { private double purchase; private double payment; /**establishes instance variables "purchase" and "payment" and assigns them as doubles to store the two amounts later on. the assignment as private makes it so ONLY methods in this class can access these instance variables*/
We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:
1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png
2. Receipt - at the end of every transaction.
3. Daily Sales Report where it shows all receipts then grand total like:
Transaction 1
-subtotal
Transaction 2
-subtotal
and so on then,
GRAND TOTAL
4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.
Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.
int userQty1 = Integer.parseInt(JOptionPane.showInputDialog( "Product ID Product Name Product Quantity Product Price" +prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 " " + and so on until prod5));
I am trying to create a slightly modified cash register. The user will enter the amount of the item, the payment received, calculate the change/refund, and then allow the user to choose the preferred bills.
import java.util.Scanner; public class Register { private static Scanner input; public static void main(String[] args) { input = new Scanner(System.in); System.out.println("*****CASH REGISTER*****" ); System.out.print("Item Amount: " ); int amount = input.nextInt();
[Code] ....
I will try to clarify the code, to make things a little easier to interpret. in the refund method, I have set up a 2-d array to exist and function as an excel sheet. The refund amount is passed to the method and compared to each bill of the array. Once the refund is determined to be greater than a bill, the user is prompted to enter the preferred bill type. This is where my problem is...I would like the program to then calculate the number of bills and keep a tally of those bills in the 2nd column and then determine the new refund amount at which point the user will be prompted again to determine the desired bill.
Then print out the array of bills that are not equal to 0.
So I have to make a cash register class that can be used with a RetailItem class that I did in another assignment. It should simulate the sale of an item. It should have a constructor that accepts a RetailItem object as an argument, and the constructor should also accept an integer that represents the quantity of the items being purchased.
I have no errors but here is the output I am getting:
How many candy bars are you buying? 5 Subtotal : $0.00 Sales tax : $0.06 Total : $0.06 BUILD SUCCESSFUL (total time: 3 seconds)
The code I have so far below:
CashRegister Class package cashregisterdemo; public class CashRegister { private RetailItem retailItem; private int quantityItems; private final double SALES_TAX = .06; private int subTotal;
How to convert the equation below for bigDecimal objects. I have already tried this, and this and the output is really weird once I call the method. The first block of code is what I'm trying to convert into BigDecimal arithmetic.
public static double calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { double futureValue = 0; for (int i = 1; i <= months; i++) {
[Code] ....
My attempt at this is as follows:
public static BigDecimal calculateFutureValue(double monthlyInvestment, double monthlyInterestRate, int months) { BigDecimal futureValue = new BigDecimal(0.0); BigDecimal montlyInvestmentDecimal = new BigDecimal(monthlyInvestment);
[Code] ....
Output: Welcome to the Future Value Calculator
DATA ENTRY Enter monthly investment: 1 Enter yearly interest rate: .01 Enter number of years: 3 Month: 1 FutureValue: 0E-66 Month: 2 FutureValue: 0E-132 Month: 3 FutureValue: 0E-198 Month: 4 FutureValue: 0E-264 Month: 5 FutureValue: 0E-330
[Code] ....
FORMATTED RESULTS Monthly investment: $1.00 Yearly interest rate: 0.0% Number of years: 3 Future value: 0E-2376
I have to make a cash register class that can be used with a RetailItem class that I did in another assignment. It should simulate the sale of an item. It should have a constructor that accepts a RetailItem object as an argument, and the constructor should also accept an integer that represents the quantity of the items being purchased.
I have no errors but here is the output I am getting:
How many candy bars are you buying? 5 Subtotal : $0.00 Sales tax : $0.06 Total : $0.06 BUILD SUCCESSFUL (total time: 3 seconds)
The code I have so far below:
CashRegister Class package cashregisterdemo; public class CashRegister { private RetailItem retailItem; private int quantityItems; private final double SALES_TAX = .06; private int Subtotal; public CashRegister()
I'm having some trouble with a code I am writing for class. I had an 2 errors like this before this one and fixed it by changing int avgRe, avgMiles =0; to double. Now I am getting this error and am stuck on what I need to change. Here is the code:
import java.io.*; import java.util.*; import java.text.*; public class Reimbursement_3_09 { static Toolkit tools = new Toolkit(); public static void main (String [] args) throws Exception {
[Code] ....
This is my error:
[code=Java] Reimbursement_3_09.java:33: error: incompatible types: possible lossy conversion from double to int summary (outFile, totalAmount, ctrMiles, ctrMilesgt0, avgRe, avgMiles); ^ Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error
My question is how do I configure this so that when / if I need to change the discount value, it automatically adjusts the % discount off of the Full or Compact?
All I can get to work is simply hardcoding it and assigning the discount value, i'm probably just messing up the syntax.
I am trying to convert the double 4270571936.0000000000d to a hex string using Double.toHexString() and the answer I'm getting is 0x1.fd17834p31, what does p stands for?
The answer I'm expecting to get is 0x41efd17834000000 so not sure why it won't give me the correct answer?
The following floating point Double to hex calculator shows the write answer right Floating Point to Hex Converter
I have a jsf page.i need to confirm one filed only contain double value.how to validate this? I checked and found there is a validateDoubleRange,but its not suitable for this.
//Students Full Name firstName = JOptionPane.showInputDialog("Enter student " + "first name."); lastName = JOptionPane.showInputDialog("Enter student " + "last name."); // Get test grade (numbers) [b]test1 = JOptionPane.showInputDialog("Enter test1 grade")[/b];
The line in bold is where that error comes up. I know it something simple but I can't remember. I declared both firstName and lastName as Strings and then the test1 I declared as double. I had a similar error in a previous assignment where I had a integer(age) input and then i had an output statement asking for a name all I needed to do was put keyboard.nextLine(); after my age input and I was fine.
I have a char[] containing ASCII characters that need to be converted into int value and double value.
The int value are always stored in 1 char size like 'j'. I extracted it succesffully by converting the char in a ascii bytearray and then used: Integer.parseInt(sb.toString().replace("0x", ""), 16);
How can I get the Value as double when i used the char[] with size 2 or 4 ?
Example : final char[] charValue = { 'u', ' ', '}','+' }; what is the associate Double value ?
Example : final char[] charValue = { 'T', ' ' }; what is the associate Double value ?
Example : final char[] charValue = { 'T', ' ' }; what is the associate int value ?
I am making a program where the user types in how many students, the student name and the student result. My problem is typing in a dobule name for instance: Tom Tom.
I have tried both:
String name = input.Next(); -> Only works with one name. and String name = input.nextLine(); -> Skips right trough and ask me to type result again.
Here is my code:
Java Code:
import java.util.Scanner; public class c5e8 { public static void main(String[]args){ Scanner input = new Scanner (System.in); int highestResult = 0; String highestName = " ";
R2 (x,y) -- Make the Point class code that implements a corresponding abstraction to a given point in R2. You should explicitly provide the manufacturer's code P (double x, double y) for the Point class. And code for the methods, whose definitions are:
- public double getXCoordinate (); - public double getYCoordinate (); - public setXYCoordinates (double x, double y); - public moveTo (double x, double y); - public printAtts ();