Solved

IF Else Statement Help

Posted on 2009-03-30
16
256 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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