Results 1 to 6 of 6
  1. #1
    happytrails is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    Default Sava data to a text file from an application?

    Hello everyone, excuse my nubness, as I am still a nub in programming, and I have a few questions. I'm just having some fun learning programming, watched a youtube video on a tutorial for java programming which inspired me to make my own class called CoinCounterEnhanced.

    Basically I made this class be able to do a number of different methods all relating to adding/subtracting quarters, dimes, nickles, and pennies. In addition to that, the program is also able to return the amount of coins, value of coins, and thats pretty much all.

    Now, since I took a long time to make this and it was fun! I'm looking for ways to maybe add on to what I have? I was thinking maybe of somehow being able to store the data I create in a text file or something like that. Say I make a CoinCounterEnhanced object named billyBob. I would like to, somehow, be able to store my new billyBob object (kind of like my own personal bank account) in a file like a .txt file I guess? I guess I'm trying to say like any application that needs saving, for example, Microsoft Word-I write the file in the editor, then go to file save. Then I can bring it up easily and add some more to it, save, and so on. How would I do that for my billyBob object? Once again, sorry for my nubness and long wall of text.

    Here is my code:

    Java Code:
    /* My CoinCounterEnhanced class for counting coins! :)
     * 
     */
    package coinsEnhanced;
    
    /**
     * @author Adam
     * This program creates a CoinsCounterEnhanced object that allows the user to keep count of
     * coins.  This includes quarters, dimes, nickels, and pennies.
     */
    public class CoinsCounterEnhanced {
    	private double quarters;
    	private double dimes;
    	private double nickels;
    	private double pennies;
    	private double coins;
    	/**
    	 * Constructor for the CoinsCounterEnhanced object
    	 * It will start with no parameters and a value of 0 quarters, dimes, nickels,
    	 * pennies, and coins.
    	 */
    	public CoinsCounterEnhanced(){
    		quarters = 0;
    		dimes = 0;
    		nickels = 0;
    		pennies = 0;
    		coins = 0;
    	}
    	
    	/**
    	 * Adds quarters to the CoinsCounterEnhanced object.
    	 * @param amount The amount to add.
    	 */
    	public void addQuarters(int amount){
    		quarters = quarters + amount;
    	}
    	/**
    	 * Subtracts quarters from the CoinsCounterEnhanced object.
    	 * @param amount The amount to subtract.
    	 */
    	public void subtractQuarters(int amount){
    		quarters = quarters - amount;
    	}
    	/**
    	 * Adds dimes to the CoinsCounterEnhanced object.
    	 * @param amount The amount to add.
    	 */
    	public void addDimes(int amount){
    		dimes = dimes + amount;
    	}
    	/**
    	 * Subtracts dimes from the CoinsCounterEnhanced object.
    	 * @param amount The amount to subtract.
    	 */
    	public void subtractDimes(int amount){
    		dimes = dimes - amount;
    	}
    	/**
    	 * Adds nickels(aka nickles) to the CoinsCounterEnhanced object.
    	 * @param amount The amount to add.
    	 */
    	public void addNickels(int amount){
    		nickels = nickels + amount;
    	}
    	/**
    	 * Subtracts nickels(aka nickles) from the CoinsCounterEnhanced object.
    	 * @param amount The amount to subtract.
    	 */
    	public void subtractNickels(int amount){
    		nickels = nickels - amount;
    	}
    	/**
    	 * Adds pennies to the CoinsCounterEnhanced object.
    	 * @param amount the amount to add
    	 */
    	public void addPennies(int amount){
    		pennies = pennies + amount;
    	}
    	/**
    	 * Subtracts pennies from the CoinsCounterEnhanced object.
    	 * @param amount the amount to subtract
    	 */
    	public void subtractPennies(int amount){
    		pennies = pennies - amount;
    	}
    	/**
    	 * Returns the amount of quarters in the CoinsCounterEnhanced object.
    	 * @return
    	 */
    	public double getQuarters(){
    		return quarters;
    	}
    	/**
    	 * Returns the amount of dimes in the CoinsCounterEnhanced object.
    	 * @return
    	 */
    	public double getDimes(){
    		return dimes;
    	}
    	/**
    	 * Returns the amount of nickels(aka nickles) in the CoinsCounterEnhanced object.
    	 * @return
    	 */
    	public double getNickels(){
    		return nickels;
    	}
    	/**
    	 * Returns the amount of pennies in the CoinsCounterEnhanced object.
    	 * @return
    	 */
    	public double getPennies(){
    		return pennies;
    	}
    	/**
    	 * Returns the value, in cents, of quarters.
    	 * @return
    	 */
    	public double getQuartersValue(){
    		quarters = quarters * 0.25;
    		return quarters;
    	}
    	/**
    	 * Returns the value, in cents, of dimes.
    	 * @return
    	 */
    	public double getDimesValue(){
    		dimes = dimes * 0.10;
    		return dimes;
    	}
    	/**
    	 * Returns the value, in cents, of nickels(aka nickles).
    	 * @return
    	 */
    	public double getNickelsValue(){
    		nickels = nickels * 0.05;
    		return nickels;
    	}
    	/**
    	 * Returns the value, in cents, of pennies.
    	 * @return
    	 */
    	public double getPenniesValue(){
    		pennies = pennies * 0.01;
    		return pennies;
    	}
    	/**
    	 * Returns the amount of all coins combined.
    	 * @return
    	 */
    	public double getNumberOfCoins(){
    		coins = quarters + dimes + nickels + pennies;
    		System.out.println("The number of coins you have is: ");
    		return coins;
    	}
    	/**
    	 * Returns the value, in cents, of all the coins combined.
    	 * @return
    	 */
    	public double getCoinsValue(){
    		coins =         (quarters * 0.25) + 
    						(dimes    * 0.10) +
    						(nickels  * 0.05) +
    						(pennies  * 0.01);
    		System.out.println("The amount of money your coins add up to is: ");
    		return coins;
    	}
    }

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Didn't you just do this a couple of posts down???
    Who Cares... As Long As It Works...

  3. #3
    happytrails is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    Default

    Hey yea, I researched what you said and decided that the above is what I'd like to try and do. Thanks for the help too btw on other post

  4. #4
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Sorry about that... Then you now want to check out Serialization... I really do not know much about it, so I will check it out too...
    Who Cares... As Long As It Works...

  5. #5
    happytrails is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    Default

    Oh wow, ok great thanks, I'll definately look that up, thanks again :)

  6. #6
    happytrails is offline Member
    Join Date
    Apr 2009
    Posts
    7
    Rep Power
    0

    Default

    Hey I'm going to head to sleep now just fyi in case you wonder why I won't be responding to future forum posts. Thanks again for the help, appreciate it!

Similar Threads

  1. Replies: 4
    Last Post: 04-10-2009, 05:35 AM
  2. reading data from text file .. help plz
    By Thug heart in forum New To Java
    Replies: 7
    Last Post: 02-15-2009, 07:29 PM
  3. Storing data from text file in ArrayList
    By tjhodge in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 01:22 PM
  4. Replies: 40
    Last Post: 07-04-2008, 08:41 AM
  5. [SOLVED] How to Extract Data From this text file?
    By jazz2k8 in forum New To Java
    Replies: 31
    Last Post: 04-18-2008, 10:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •