Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.oooo AT&T; 7:08 AM 90%-. elearn.tnstate.edu ASSIGNMENT-Week 5 Classes & Objects

ID: 3887650 • Letter: #

Question

.oooo AT&T; 7:08 AM 90%-. elearn.tnstate.edu ASSIGNMENT-Week 5 Classes & Objects Constructors & Instance Variables and Instance Methods the ToString Method Due 09/27 Use Visual Studio to create a console application project with the name of Assignment2 lourLast Name Declare a public class with the name A2Account. Add the following members to the class. L two private instance variables. One is named as owner with the type of String, and the other named as balance with the type of double. 2 two constructors. One takes no parameters and initializes the owner to your last name and the balance to 0; the other takes two parameters to initialize the two instance variables. s a property named Balance with get and set blocks. 4 an instance method Withdraw. This method takes a double parameter a, representing the amount the user wants to withdraw, and returns the new balance if the account has enough money, otherwise it returns -1. s the ToString method, which will return this string: "Account Owner: the Ovver's Name: Balance = nnnnn" &the; Main. In the Main, Create an object myObjl by calling the first constructor, and create an object myObj2 by calling the second constructor with the arguments "Mary Johns" and 5000.0. b. Add 800 dollars to the account myObj1. (use the property Balance) e Withdraw 1000 dollars from myObj1. If it does not have enough money, output "insufficient funds!". Withdraw 1000 dollars from myObj2. If it does not have enough money output "insufficient funds!" d Output the strings returned by the ToString method of the two objects. Print out this page, your program, and running result, put sign on this page, and turn in at the beginning of them together, the class meeting on February 7, 2017.) I understood every line of the C# code for this Print Your Name: Your signature: Date:

Explanation / Answer

//Rextester.A2Account.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
public class A2Account
{
String owner;
double balance;
public A2Account()
{
owner = "abc";
balance =0;
}
public A2Account(String ownerName, double ownerBal)
{
owner = ownerName;
balance = ownerBal;
}
  
public double getBal()
{
return balance;
}
  
public void setBal(double newBal)
{
balance = newBal;
}
  
public double withdraw(double draw_amt)
{
if(balance >= draw_amt)
{
balance = balance - draw_amt;
return balance;
}
else
return -1;
}
  
public String toString()
{
return "Account Owner: "+owner+" Balance = "+ balance;
}
  
public static void Main(string[] args)
{
//Your code goes here
//Console.WriteLine("Hello, world!");
A2Account myobj1 = new A2Account();
A2Account myobj2 = new A2Account("Mary Johns",5000.0);
myobj1.setBal(800);
if(myobj1.withdraw(1000) == -1)
Console.WriteLine("insufficient Funds!");
else
Console.WriteLine(myobj1.balance);
Console.WriteLine(myobj1.owner+" "+ myobj1.getBal());
  
if(myobj2.withdraw(1000) == -1)
Console.WriteLine("insufficient Funds!");
else
Console.WriteLine(myobj1.balance);
Console.WriteLine(myobj1.owner+" "+ myobj1.getBal());
  
Console.WriteLine(myobj1.ToString());
}
}
}

Please comment you you need more details clarification on this. Thanks