LeeHoward's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Just Registered
Active Posts:
6 (0.01 per day)
Joined:
19-October 12
Profile Views:
282
Last Active:
User is offline Jan 06 2013 10:33 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   LeeHoward has not set their status

Posts I've Made

  1. In Topic: How to make a window in CSS that will display information from a DB

    Posted 30 Nov 2012

    View PostAtli, on 29 November 2012 - 09:48 AM, said:

    Moved to the HTML/CSS help forum. Please try not to post questions in the Tutorials sections.


    Sorry, I was looking for a tutorial that could help me learn how to accomplish something like I described in one tab and another searching around in the HMTML/CSS forums. *facepalm*

    Thanks for the tip about lightbox, I looked up shadow box but because I'm doing it for a friends company and since I'm doing it for free it just wouldn't be worth it.

    If I can I'll use lightbox to display the main background image and CSS to position the pulled data appropriately. (Hopefully that'll work) :)

    Thanks again.
  2. In Topic: Change return program not carrying across information :S

    Posted 31 Oct 2012

    @pbl

    Yep, you have a good point, using maths to solve a currency problem? Surely not!

    I finished the application:

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package change.pkgreturn.program;
    
    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Scanner;
    
        
    /**
     *
     * @author User
     */
    public class ChangeReturnApp {
       public BigDecimal cost;
       public BigDecimal changeGiven;
       public BigDecimal changeReturned;
        int fiftyNote;
        int twentyNote;
        int tenNote;
        int fiveNote;
        int twoPoundCoin;
        int onePoundCoin;
        int fiftyPenceCoin;
        int twentyPenceCoin;
        int tenPenceCoin;
        int fivePenceCoin;
        int twoPenceCoin;
        int onePenceCoin;
        
        public void start() {
            
            takeCost();
            takeChangeGiven();
            afterCost(cost, changeGiven);
            changeSummary(changeReturned);
        }
        
        public BigDecimal takeCost() {
            System.out.println("Please input a cost: £");
                
            Scanner costInput = new Scanner(System.in);
            
            while (!costInput.hasNextBigDecimal()) {
                System.out.println("Invalid format - valid example: £13.70, please try again: ");
                costInput.next();
            }
            cost = costInput.nextBigDecimal();
            cost = cost.setScale(2, RoundingMode.DOWN);
            return (BigDecimal) cost;
        }
            
        public BigDecimal takeChangeGiven() {
            
            
            System.out.println("Please input the amount given: £");
                
            Scanner changeGivenInput = new Scanner(System.in);
            while (!changeGivenInput.hasNextBigDecimal()) {
                System.out.println("Invalid format - valid example: £13.70, please try again.");
                changeGivenInput.next();
            }
            
            changeGiven = changeGivenInput.nextBigDecimal();
            changeGiven = changeGiven.setScale(2, RoundingMode.DOWN);
            return (BigDecimal) changeGiven;
        }
        
        private BigDecimal afterCost(BigDecimal cost, BigDecimal changeGiven) {
            int compare = cost.compareTo(changeGiven);
            
            if (compare == 1) {
                System.out.println("Error - Change given is less than cost.");
                System.exit(0);
            }
            
            System.out.println("cost = " + cost);
            System.out.println("changeGiven = " + changeGiven);
            changeReturned = changeGiven.subtract(cost);
            changeReturned = changeReturned.setScale(2, RoundingMode.DOWN);
    
            return (BigDecimal) changeReturned;
        }    
        
        private void changeSummary(BigDecimal changeReturned) {
    
            double changeRet = changeReturned.doubleValue();
            
            System.out.println("ChangeReturned converted to double: " + changeReturned);
                
                do {
                    if (changeRet >= 50.00) {
                        changeRet = changeRet - 50.00;
                        fiftyNote = fiftyNote + 1;
                    } 
                    
                } while (changeRet >= 50);
              
                do {
                    if (changeRet >= 20.00) {
                        changeRet = changeRet - 20.00;
                        twentyNote = twentyNote + 1;
                    } 
                    
                } while (changeRet >= 20);
                
                do {
                    if (changeRet >= 10.00) {
                        changeRet = changeRet - 10.00;
                        tenNote = tenNote + 1;
                    } 
                    
                } while (changeRet >= 10);
                
                do {
                    if (changeRet >= 5.00) {
                        changeRet = changeRet - 5.00;
                        fiveNote = fiveNote + 1;
                    } 
                    
                } while (changeRet >= 5.00);
                
                do {
                    if (changeRet >= 2.00) {
                        changeRet = changeRet - 2.00;
                        twoPoundCoin = twoPoundCoin + 1;
                    } 
                    
                } while (changeRet >= 2.00);
                
                do {
                    if (changeRet >= 1.00) {
                        changeRet = changeRet - 1.00;
                        onePoundCoin = onePoundCoin + 1;
                    } 
                    
                } while (changeRet >= 1.00);
                
                do {
                    if (changeRet >= 0.50) {
                        changeRet = changeRet - 0.50;
                        fiftyPenceCoin = fiftyPenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.50);
                
                do {
                    if (changeRet >= 0.20) {
                        changeRet = changeRet - 0.20;
                        twentyPenceCoin = twentyPenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.20);
                
                do {
                    if (changeRet >= 0.10) {
                        changeRet = changeRet - 0.10;
                        tenPenceCoin = tenPenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.10);
                
                do {
                    if (changeRet >= 0.05) {
                        changeRet = changeRet - 0.05;
                        fivePenceCoin = fivePenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.05);
                
                do {
                    if (changeRet >= 0.02) {
                        changeRet = changeRet - 0.02;
                        twoPenceCoin = twoPenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.02);
                
                do {
                    if (changeRet >= 0.01) {
                        changeRet = changeRet - 0.01;
                        onePenceCoin = onePenceCoin + 1;
                    } 
                    
                } while (changeRet >= 0.01);
                
                System.out.println("\n\nChange Summary:\n"
                        + fiftyNote + " x FiftyNotes\n"
                        + twentyNote + " x TwentyNotes\n"
                        + tenNote + " x TenNotes\n"
                        + fiveNote + " x FiveNotes\n"
                        + twoPoundCoin + " x Two Pound Coin\n"
                        + onePoundCoin + " x One Pound Coin\n"
                        + fiftyPenceCoin + " x Fifty Pence Coin\n"
                        + twentyPenceCoin + " x Twenty Pence Coin\n"
                        + tenPenceCoin + " x Ten Pence Coin\n"
                        + fivePenceCoin + " x Five Pence Coin\n"
                        + twoPenceCoin + " x Two Pence Coin\n"
                        + onePenceCoin + " x One Pence Coin\n");
        }
    
    }
    
    
    


    It appears to work flawlessly, honestly, I think I prefer plb's suggestion to mine but both work. I used BigDecimal over double since many have mentioned that they've experienced problems with using doubles with currency projects, though saying that they do get converted to doubles at the end.

    Thank you PBL for the advice/suggestions :)
  3. In Topic: Change return program not carrying across information :S

    Posted 23 Oct 2012

    I also fixed the loop problem, instead of using for loops I used do while loops:

    do {
                    if (changeReturned >= 50.00) {
                        changeReturned = changeReturned - 50.00;
                        fiftyNote = fiftyNote + 1;
                    }
    
    
  4. In Topic: Change return program not carrying across information :S

    Posted 22 Oct 2012

    ....oh dear god.

      System.out.println("Please input a cost: ");
                
            Scanner costInput = new Scanner(System.in);
            while (!costInput.hasNextDouble()) {
                System.out.println("Invalid format - valid example: 13.70, please try again.");
                cost = costInput.nextDouble();
            }
            cost = costInput.nextDouble();
            System.out.println("Test: " + cost);
            return (double) cost;
    
    


    Soooo....the reason that it wouldn't carry across the information was because although I've assigned cost to the scanner input in the while loop when someone enters a value that ISN'T a double, cost isn't actually assigned a value when someone enters a value that IS a double first time around.

    Thanks for looking at the problem, really appreciate it, I'm going to take what's left of my pride and power on lol.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

LeeHoward hasn't added any friends yet.

Comments

LeeHoward has no profile comments yet. Why not say hello?