Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming with C# The purpose of this assignment is simply to get you going in case you forgot how to program over the break and

Programming with C#

The purpose of this assignment is simply to get you going in case you forgot how to program over the break and to get you up to speed on using Visual Studio and C#. It should be a review of creating a class, reading input from the user and calling a few methods in the class.

Create a C# application that defines a single class, Account. This class should have an instance variable (double) which represents the starting balance. There should also be a variable indicating the number of transactions. Finally there should be an array of doubles that contains the transactions. You can assume there will be no more than 50 transactions. [If you want to be slightly more professional, you could have a parallel array that keeps track of the type of transactionor an array of a Transaction class that keeps track of both type and amount.] The constructor should accept a single argument, a double, which is the starting balance. In addition to these instance variables, the class should contain the following methods:

deposit adds entry to the transaction array; returns void

withdraw adds negated entry to the transaction array; returns void

addInterest adds entry to the transaction array that increases the current balance by .05%; returns void

getBalance returns the current balance. The method should walk through the array to determine the balance; the class should not have a variable that has the current balance.

showTransactions lists all the transactions that have been entered, including the beginning balance and the current balance.

The main method should do the following in a loop:

ask whether to continue

display a menu that allows the user to choose from the four actions described above: (D)eposit, (W)ithdraw, (C)alculateInterest, (S)howBalance., (Q)uit

The program will perform the appropriate action. If the user is making a deposit or withdrawal, the program will ask for the amount. The user should be expected to enter only positive values.

When the customer chooses to quit, the program will call showTransactions and then exit.

Note: output should only be performed in the main method; your member methods should perform the calculation and return the answer. The only exception to this is ShowTransactions, which is allowed to perform output. Your methods should all be member methods (no statics).

You can enter these numbers in whatever manner is easiest for you. A straight forward way to read a double is:

String s = Console.ReadLine();

double d = Double.Parse(s);

and for a character:

char c = Console.ReadLine()[0];

This is all in C#, which I am very unfamiliar with. I have some code done which I will post below:

using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks;

namespace Program0 { class Account { public double balance { get; set; } public int numberOfTransactions { get; set; } public void Deposit(double d) { this.balance += d; this.numberOfTransactions += 1; } public void Withdrawal(double d) { this.balance -= d; this.numberOfTransactions += 1; } public double GetBalance() { return this.balance; } public int getNumberOfTransactions() { return numberOfTransactions; } class Program { static void Main(string[] args) { Account b = new Account(); b.Deposit(200); b.Withdrawal(50); char input = ' '; while (true) { Console.WriteLine("MENU"); Console.WriteLine("Please enter the letter that you want to do:"); Console.WriteLine("(D)eposit"); Console.WriteLine("(W)ithdraw"); Console.WriteLine("(C)alculateInterest"); Console.WriteLine("(S)howBalance"); Console.WriteLine("(Q)uit"); char menuchoice = char.Parse(Console.ReadLine()); switch (menuchoice) { case 'D': case 'd': double amount = 0; Console.WriteLine("Enter an amount to deposit"); break; case 'W': case 'w': Console.WriteLine("Enter an amount to withdraw"); break; case 'C': case 'c': Console.WriteLine("Calculate the interest"); break; case 'S': case 's': Console.WriteLine("Show all transactions"); break; case 'Q': case 'q': Console.WriteLine("exit"); break; } //Console.WriteLine(b.GetBalance()); Console.WriteLine(b.balance); Console.ReadLine(); } } } } }

The above code is what I have so far, but it is not right. This is what needs to be done:

-The Account object needs an Array of doubles to hold the transactions

-You are not supposed to keep track of the balance, but calculate it anytime it is asked for. This means that I should start with an initial balance, then add up everything in the transaction array.

I don't understand how to code the showTransactions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago