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
Give me 3 companies that utilize audio/video technology
mestny [16]

Answer: I think Harman International. Bose.

Sennheiser, that ultilize audio And Zendesk

New Relic That ultilize video technology.

Explanation:

3 0
4 years ago
What did Moore's Law explain?A.The power of microprocessors will double every two years.B.The power of microprocessors will incr
Maru [420]

A.The power of microprocessors will double every two years.

3 0
3 years ago
Select the correct statement(s) regarding Frame Relay (FR). a. FR is a connection-oriented standard that operates at the OSI lay
DedPeter [7]

Answer:

d. all of the statements are correct

Explanation:

Frame Relay is a high-performance WAN protocol that operates at the physical and data link layers of the OSI reference model. i.e Layers 1 and 2 They are designed to cope with bursty traffic. Frame relay is also a form of data networking based on packet switching in which the packets are variable in length and experience packet delays.

Based on the above definition the correct statement is option d as all of the statements define in the other option correctly defines the function of frame relay.

7 0
3 years ago
Have you ever tried using such a camera?​
guapka [62]

Answer: yeah i mean i use my canon camera

Explanation:

7 0
3 years ago
2. Media sharing websites let you post photos and videos to share with other people. What are the benefits and drawbacks of usin
LuckyWell [14K]

Answer:

You get to learn about the world and you get catch up on daily news

Explanation:

5 0
3 years ago
Other questions:
  • PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
    7·1 answer
  • A number used to encrypt data is called a(n ________. signature key cookie escrow
    10·1 answer
  • Write a program to calculate how much to tip a waiter person based on the quality of service. The script file should ask for the
    12·1 answer
  • Maggie is preparing a document.she wants to open the help menu to sort out a formatting problem.which key should she press to op
    15·2 answers
  • g What field in the IPv4 datagram header can be used to ensure that a packet is forwarded through no more than N routers? When a
    10·1 answer
  • You realize your computer has been infected with malware. The program has been copying itself repeatedly, using up resources. Wh
    10·1 answer
  • Can you see it now ivy97? I've posted it again.
    8·1 answer
  • Implement (in Java) the radixSort algorithm to sort in increasing order an array of integer positive keys. public void radixSort
    13·1 answer
  • A Personal Fitness Tracker is a wearable device that tracks your physical activity, calories burned, heart rate, sleeping patter
    13·1 answer
  • What makes a recipe for a meal an example of an algorithm?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!