Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A Go Card account maintains a balance that may be spent on public transport. Users may request a statement that shows all transactions. The
A Go Card account maintains a balance that may be spent on public transport. Users may request a statement that shows all transactions. The only transactions are to top up the account with some positive number of dollars, and to take a ride costing some dollars and cents. The goal for this exercise is to develop a class for a Go Card Account. The class will be tested by a program that simulates transactions, like this: Creating account. Input initial balance: 100 ? ? ? b 3.50 10.90 Balance $85.60 ? t 20 ? x gghhg Bad command. ? t Bad command. ? 9 Statement: event amount ($) balance ($) Initial balance 100.00 Ride 3.50 96.50 Ride 10.90 85.60 Top up 20.00 105.60 Final balance 105.60 Where: r number simulates a ride costing number dollars; t number simulates a top up of number dollars; b requests the currrent balance; and qends input and prints a statement. Bad inputs are to be reported and ignored. Let us consider the design for a class that represents a Go Card account. To design a class, we consider what services the object(s) must provide (its methods), and what data needs to be stored in the object(s) to support those services. Questions: What is a good name for a class that represents a Go Card account? - Be descriptive of the what the class represents. Don't include the word "class" in the name. What services should be provided? - A constructor (__init__) is required to set up the account with an initial balance. -It needs to record the amount each ride costs. A method that accepts the amount as a parameter is required. - It needs to record the amount for each top-up. A method that accepts the amount as a parameter is required. -It needs to be able to report the current balance at any time. A method that returns this is required. -A method is required print out a statement of all of the transactions. We can see from the output of the proposed program that the class needs to store the details of every transaction in order. What data is required to be stored in the object to enable those services? - So that a method can return the current balance at any time, it would be useful have a field for the current balance. -So that the full statement can be printed, the object must store the amount of each transaction, in order. What data type can grow and keep multiple values in the order they are added? 4.2 Problem 1 (3 marks) Problem: Implement the program descibed above, leaving out the printing of a full statement at the end. 4.3 Problem 2 (2 marks) Problem: Implement the program descibed above, including the printing of a full statement at the end.
Step by Step Solution
★★★★★
3.50 Rating (153 Votes )
There are 3 Steps involved in it
Step: 1
For Problem 1 lets start by designing a class named GoCardAccount that represents a Go Card account ...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