Solved

IF Else Statement Help

Posted on 2009-03-30
16
257 Views
Last Modified: 2012-05-06
Hi, i'm working on a practice excercise and i'm totally frustrated and stuck.
I'm trying to write codes for the attached practice excercise and I'm totally lost.
See Attachment :  
You help would be gladly appriciated !!!!


Thanks,
- T
namespace CUSTOMER
{
    class Customer
    {
        static void Main(string[] args)
        {
 
            // Attributes
            String customerName;
            int customerId;
            double accountBalance;
            double processDeposit;
        }
 
 
            // Methods
 
           public string getName()
           {
               return customerName;
           }
         
           public int getId()
           {
               return customerId;
           }
 
           public double getbalance()
           {
               return accountBalance;
           
           }
 
           public double depositAmount()
           {
               return depositAmount;
           }
           
           public double processWithdrawal()
           {
               //return double Withdrawal;
           }
 
          // Constructors 
 
           public Customer()
           {
 
           Console.WriteLine("Please Enter Your Name : ");
           Console.ReadLine();
           Console.WriteLine("Your Name is :{0},customerName");
 
           Console.WriteLine("Please Enter Your Customer ID : ");
           customerId = Convert.ToInt32(Console.ReadLine());
           Console.writeLine("Your Cusotmer ID is :{0},cusotmerId");
 
           Console.WriteLine("Please Enter Your Account Balance");
           accountBalance = Convert.ToDouble(Console.ReadLine());
           Console.WriteLine("Your Account Balance is :{0},accountBalance");
 
           
           }
    }
    class testCustomer
    {
           public static void Main(string[] args)
           {
           double startingBalance,deposit,withDrawal;
           bool validWithdrawal;
           Customer = new Customer();
           console.writLine ("startingBalance is :{0},accountBalance");
 
 
           }

Open in new window

IF-Statement-Exercise-1-.doc
0
Comment
Question by:neverenough
  • 9
  • 5
  • 2
16 Comments
 
LVL 31

Assisted Solution

by:RiteshShah
RiteshShah earned 40 total points
ID: 24025274
first. you can't have "static void Main(string[] args)" in two class. Main method is an entry point and you are confusing compiler by giving two Main method.

Second, you have declare following variables in Main Class, how will it be reachable in other method?

 String customerName;
        int customerId;
        double accountBalance;
        double processDeposit;

you should declare it as class level.

there are also few logical mistakes I am seeing, what is your purpose for this script? let me know, I can modify it for you.
0
 
LVL 31

Assisted Solution

by:RiteshShah
RiteshShah earned 40 total points
ID: 24025283
sorry, my above answer was based on the script you provided, I didn't see your attached document.
0
 

Author Comment

by:neverenough
ID: 24025328
It's a practice excercise i've got for a class. I understand a lot of the stuff, -- technically, I understand what's being asked by the program, but when it's time to put the codes together i always get totally get stuck.
It's an excellerated class, so it's going really quick and i'm falling behind.
That would be great if you can rewrite it for me.

Reagards,
- T
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24028967
Hello

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer testCustom = new Customer();
            Console.WriteLine(testCustom.ToString());
            Console.WriteLine("Customer name = {0}", testCustom.CustomerName);  //proerties
            Console.WriteLine("Customer account {0}", testCustom.AccoutBalance()); //methode must have ()
        }
    }
 
 
    class Customer
    {
        // Attributes
        String customerName;
        int customerId;
        double accountBalance;
        //double processDeposit;
        double depositAmount;
 
        // Properties
        public string CustomerName
        {
            get
            {
                return customerName;
            }
 
            set
            {
                customerName = value;
            }
        }
 
        // Methods
        public int CustomerID()
        {
            return customerId;
        }
 
        public double AccoutBalance()
        {
            return accountBalance;
        }
 
        public double DepositAmount()
        {
            return depositAmount;
        }
 
        // Constructors 
        public Customer()
        {
            Console.WriteLine("Please Enter Your Name : ");
            customerName = Console.ReadLine();
            Console.WriteLine("Your Name is :{0},customerName");
 
            Console.WriteLine("Please Enter Your Customer ID : ");
            customerId = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Your Cusotmer ID is :{0},cusotmerId");
 
            Console.WriteLine("Please Enter Your Account Balance");
            accountBalance = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Your Account Balance is :{0},accountBalance");
 
            depositAmount = 0;
        }
 
        public override string ToString()
        {
            return "Name: " + customerName + ", Account: " + accountBalance.ToString();
        }
    }
 
    
}

Open in new window

0
 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24029027
ups... few mistakes..
this one is checked..

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer testCustom = new Customer();
            
            Console.WriteLine("\n\n"+ testCustom.ToString());
            Console.WriteLine("Customer name: {0}", testCustom.CustomerName);  //proerties
            Console.WriteLine("Customer account: {0}", testCustom.AccoutBalance()); //methode must have ()
 
            Console.ReadLine();
        }
    }
 
 
    class Customer
    {
        // Attributes
        String customerName;
        int customerId;
        double accountBalance;
        //double processDeposit;
        double depositAmount;
 
        // Properties
        public string CustomerName
        {
            get
            {
                return customerName;
            }
 
            set
            {
                customerName = value;
            }
        }
 
        // Methods
        public int CustomerID()
        {
            return customerId;
        }
 
        public double AccoutBalance()
        {
            return accountBalance;
        }
 
        public double DepositAmount()
        {
            return depositAmount;
        }
 
        // Constructors 
        public Customer()
        {
            Console.Write("Please Enter Your Name: ");
            customerName = Console.ReadLine();
            Console.WriteLine("Your Name is: {0}", customerName);
 
            Console.Write("\nPlease Enter Your Customer ID: ");
            customerId = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Your Cusotmer ID is: {0}", customerId);
 
            Console.Write("\nPlease Enter Your Account Balance: ");
            accountBalance = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Your Account Balance is: {0}" ,accountBalance);
 
            depositAmount = 0;
        }
 
        public override string ToString()
        {
            return "Name: " + customerName + ", Account: " + accountBalance.ToString();
        }
    }
 
    
}

Open in new window

0
 

Author Comment

by:neverenough
ID: 24029454
Thanks Cebik !!!
I just tested it and got the following error:

Error      1      The type or namespace name 'String' could not be found (are you missing a using directive or an assembly reference?)
0
 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24029486
why ??
do you have this?

using System;
using System.Collections.Generic;
using System.Text;
0
 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24029499
try "string" but it's the same
0
 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24033734
is it working now?
acceot my solution if I helped you..
best regards
Cebik
0
 

Accepted Solution

by:
neverenough earned 0 total points
ID: 24034519
Thanks DUDE !   I REALLY APPRICIATE IT !!!!!!!!!!!!!!!!!!!
WISH I COULD GIVE YOU AN ADDITIONAL 500 POINTS !
Soultion accepted !
0
 
LVL 6

Assisted Solution

by:Cebik
Cebik earned 450 total points
ID: 24034536
Click on button Solution Accepted in my post with code :)
0
 
LVL 6

Expert Comment

by:Cebik
ID: 24034729
It isn't normal way to accept solution even if you want split points...
Read help..
Good luck ;)
0
 

Author Comment

by:neverenough
ID: 24049671
I'm kind of new to this.
I wanted to award all of the points to you because you really helped me out, but the instructions said i had to distribute a mimimum of 20 points to each input or something like that.
I'll read help to see how it can be done differently next time.

Thanks !




0
 
LVL 6

Expert Comment

by:Cebik
ID: 24050503
In this way... I've got smaller number of points..
normaly 500 points * multiplier if A then 500 * 4 = 2000
or 400 * 4  for me
other 100 * 4 for other person..

You welcome..
Bye again
0
 

Author Comment

by:neverenough
ID: 24053694
I just reviewed it again and found that you missed out some stuff.
There are some calculation missing for processing the withdrawal etc.
I'll try to figure it out.


* Define three double fields (within the main) called startingBalance, deposit and withdrawal and a bool field called validWithdrawal.
* Instantiate a Customer object.
* Populate the startingBalance field with the accountBalance field from the Customer class.
* Ask the user for, and accept a deposit amount.
* Invoke the processDeposit() method of the Customer class to update the customers balance.
*  Ask the user for and accept a withdrawal amount.
*  Invoke the processWithdrawal() method of the Customer class to update the customers balance and assign the bool value that is returned to the field validWithdrawal.
*  Print out the following activity summary. If processWithdrawal() returns a false value be sure to print out a zero Withdrawal Amount.

0
 
LVL 6

Expert Comment

by:Cebik
ID: 24053829
I show you example based on your code..
So if will haveing problem than write.. i'll help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question