Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Required Items Wallet ( STORE IN A STRUCT ) For our Wallet struct, we need to store a few things 1 ) We need to
Required Items
Wallet STORE IN A STRUCT
For our Wallet struct, we need to store a few things
We need to store the ticker symbol for the coin ie BTC
We need to store how many coins we currently have
We also need to be able to print the information in the structure out. It will print out the ticker symbol BTC for the coin and the number of coins currently in the wallet.
You should pass the wallet struct to the methods that need it you can think of the buy and sell methods as the setter function to add coins to the wallet and update the cash, and you can think of the getlive function as a getter function to get a simulated live value for bitcoin..
Ledger STORE IN A STRUCT
Inside the structure you can store the history either as an array of strings along with a number n which is the current number of strings in the array that are valid, or as a linked list of strings. I have linked list code in the class notes.
We need a procedure that is going to turn our transactions into a string and store them for our history.
It will store the transaction strings just so we have a record of the buy & sell commands. We are going to use ArrayListJava VectorsC and then List Python for this. Ie: it will be a list of transaction strings. For C you can store transaction strings in an array or in a linked list either is fine.
It will be able to print out the transaction history if requested For example it might print out the following transaction strings::
Bought bitcoin on September ::
Sold bitcoin on September ::
You may want to have a method to add a transaction string. It takes as a parameter a string and adds it to the transaction list. Once you know how many they bought or sold, there are functions available to get the current date and time. So from those pieces of data you make a string using string concatenation and then you send the string to the ledgers add method and it adds it to the ledger
Date IMPLEMENT AS A FUNCTION
This function will call the library routines to get the current date. It will have a function in it that returns that date as a string. We need this for our transaction history
GetLive IMPLEMENT AS A FUNCTION
This is going to fetch the current live value of bitcoin. Most of you will fake it by generating a random number between and k Getting the live value in Python is easy, for other languages you can find libraries to use however it is ok to just approximate the value by generating a random number for example between and k
Putting it all together
Your program will create an instance of the above. Additionally, it will create a variable to track your USD you can use a double or float You can keep your USD variable out in the main, or you can tuck it in with the wallet struction.
Then the program will go into a loop. It will print their menu options and ask what command they want to do They can buy, sell, ask for the balance, the price, and print the history, and exit when they want to
When you buy coins your US dollars go down and the number of bitcoins in your wallet goes up accordingly. When you sell coins your US balance goes up and the number of coins you have goes down. The variable that stores your actual cashUS dollars USD does not really need to be in the wallet structure if you dont want it to be It can be just a double called USD.
Demo the program as follows:
price
price
buy bitcoins
balance
price
sell bitcoins
balance
history
buy bitcoin
balance
history
exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started