1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NemiM [27]
3 years ago
11

Complete the GiftCard class shown below. A GiftCard keeps track of the current balance on the card. A gift card starts with a be

ginning balance. A GiftCard can be used to make a purchase, funds can be added to a GiftCard, and the balance can be checked at any time. The balance can never be negative. If the amount added to the card is $100 or more, a bonus of $10 is also added.
public class GiftCard
{
// declare instance variables

// precondition: the starting balance is not negative
// postcondition: all instance variables are initialized
public GiftCard(double startBal)
{

}

// postcondition: amount is subtracted from balance
// if there are insufficient funds, the balance is set to zero and a message
// is displayed to indicate how much of the transaction is still owed
public void spendFunds(double amount)
{

}
// postcondition: amount is added to balance, if the amount is at least 100 dollars,
// 10 dollars is added
public void addFunds(double amount)
{

}

// postcondition: the current balance is returned
public double checkBalance()
{

}
}

Computers and Technology
1 answer:
Aleonysh [2.5K]3 years ago
3 0

Answer:

I solved this program using C# and Visual Studio. The output of this program is given attached image. I initialized the start balance with 300$.

the code of this program is given in explanation section

Explanation:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace GiftCard

{

   class Program

   {

       static void Main(string[] args)

       {

           Program a = new Program();

            //Console.WriteLine("Please enter the starting balance");// you can uncomment this statement if you enter startbalance at run time

            //double startingBalance = Convert.ToDouble(Console.ReadLine());//initializing starting balance at run time

           double startingBalance = 300; //let suppose we enter 300

           a.GiftCard(startingBalance);//balance is set to starting blance value i.e. enter by user

           Console.ReadLine();// here we pause, and check variables values from GiftCard constructor

           a.spendFunds(100);// here we assume to spend 100$

           Console.ReadLine();//here we check the spendFund function and about its values

          a.addFunds(600);// here we enter fund 600$

           Console.ReadLine();

           a.checkBalance(); //here we are checking balance;    

       }

       // declare instance variables

       // precondition: the starting balance is not negative

       // postcondition: all instance variables are initialized

       private double balance=0;// keep the balance

       private double purchase;//how much you spend or purchasing value

       

       public void GiftCard(double startBal)

       {

           

           balance = startBal;

           if (balance < 0)

           {

               Console.WriteLine("Balance is negative, Please enter positive balance");

               balance = 0;

           }

           else

           {

               balance = startBal;

               Console.WriteLine(balance);

           }

       }

       // postcondition: amount is subtracted from balance

       // if there are insufficient funds, the balance is set to zero and a message

       // is displayed to indicate how much of the transaction is still owed

       public void spendFunds(double amount)

       {

             purchase = balance - amount;// suppose you spend 300 that mean you have purchased of 300

           if (purchase <0) //if your spending is more than your balance

           {

               

               double owed = amount - balance;// how much amount you need more for this transaction

               balance = 0;

               Console.WriteLine("The transaction is still owed "+owed+"$");

           }

           else if(purchase==0) // if after doing purchase, your balance is equal to zero

           {

               Console.WriteLine("you have no balance after this transaction");

           }

           else

           {

               balance = balance - amount;// if your purchase is less than the balance

               Console.WriteLine("your balance after spending " + amount +"$ is " + balance+"$");

           }

       }

       // postcondition: amount is added to balance, if the amount is at least 100 dollars,

       // 10 dollars is added

       public void addFunds(double amount)

       {

           if (amount >= 100)// if you add fund more than 100$

           {

               balance = balance + amount + 10; //then add the amount + 10$ as bonus into already existing balance

               Console.WriteLine("balance is after adding funds i.e " + amount +"$  is "+ balance+"$");

           }

           else// if added fund is less than 100$

           {

               balance = balance + amount;

           }

       }

// postcondition: the current balance is returned

       public double checkBalance()//check balance anytime

       {

           

           Console.WriteLine("balance is "+balance+"$");

           Console.ReadLine();

           return balance;

       }

   }

}

   

You might be interested in
Why are medical coders using encoded software
EastWind [94]
To keep the medical records confidential otherwise, hackers would take advantage of them and sell them to the highest bidder 
3 0
3 years ago
PLEASE HELP!!!
mezya [45]

Answer:

I'm not exactly sure on what the question is, but from reading it, I determined that you'll be creating 2 different designs using Inkscape/Photoshop. I'm leaving 2 of my designs in here for you to use on your project. Unknown on what to do about the design that wasn't created in an image-editing program.

4 0
3 years ago
How do you create a algorithm?
aksik [14]
Make sure that each box has an arrow going to it or leading from it, if it needs one. Select “Insert,” then “Shapes,” and choose the Text Box option: Page 2 [Algorithm how-to procedure] 2 Drag the cursor across the document to customize the size of the text box. Click inside the box to begin typing.
brainliest pls
6 0
3 years ago
Read 2 more answers
How ICT has helped education to grow through progression?
Vsevolod [243]

Answer:

Hey there!

Explanation:

This is ur answer...

<em>ICTs can enhance the quality of education in several ways: by increasing learner motivation and engagement, by facilitating the acquisition of basic skills, and by enhancing teacher training. ICTs are also transformational tools which, when used appropriately, can promote the shift to a learner-centered </em><em>environment.</em>

Hope it helps!

Brainliest pls!

Have a good day!^^

6 0
2 years ago
1. If Earth's plates are constantly moving, why don't we need to update the locations of -
Dmitriy789 [7]

Answer:

Because the tectonic plates are moving so slowly in such small incraments that it would take a while before there was any noticable change.

Explanation:

4 0
3 years ago
Other questions:
  • A brick weighs 26 N. Measured underwater, it weighs 11 N.
    10·1 answer
  • What does nntp stand for?
    12·2 answers
  • Which is worse: Fast charging (Due to heat) or unplugging before reaching full capacity (On a normal charge)?
    9·1 answer
  • Drag each tile to the correct box.
    8·2 answers
  • Which of these is a requirement for developing game applications on devices running Apple’s iOS operating system?
    6·2 answers
  • Please help please I will count your answer brainiest if you help!
    8·1 answer
  • Which examples demonstrate common education and qualifications for Manufacturing Production Process Development careers? Check a
    12·2 answers
  • Choose the type of collection described.
    9·1 answer
  • What do macOS and Windows use to prevent us from accidentally deleting files?
    15·1 answer
  • Operating systems move code and data, as necessary, to a portion of the disk that is used as if it were memory, not just disk st
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!