Solved

IF Else Statement Help

Posted on 2009-03-30
16
253 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now