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
zhuklara [117]
2 years ago
5

Can you debug the following code using the given test code?public class SavingAccount{ // interest rate for all accounts private

static double annualInterestRate = 0; private final double savingsBalance; // balance for currrent account // constructor, creates a new account with the specified balance public void SavingAccount( double savingsBalance ) { savingsBalance = savingsBalance; } // end constructor // get monthly interest public void calculateMonthlyInterest() { savingsBalance += savingsBalance * ( annualInterestRate / 12.0 ); } // end method calculateMonthlyInterest // modify interest rate public static void modifyInterestRate( double newRate ) { annualInterestRate = ( newRate >= 0 && newRate <= 1.0 ) ? newRate : 0.04; } // end method modifyInterestRate // get string representation of SavingAccount public String toString() { return String.format( "$%.2f", savingsBalance ); } // end method toSavingAccountString} // end class SavingAccount Using this test codepublic class SavingAccountTest{ public static void main(String[] args) { SavingAccount s1 = new SavingAccount(400); SavingAccount s2 = new SavingAccount(1000); SavingAccount.modifyInterestRate(0.05); System.out.printf("SavingAccount 1 is: %s\nSavingAccount 2 is: %s\n", s1, s2); s1.calculateMonthlyInterest(); s2.calculateMonthlyInterest(); System.out.printf("\nSavingAccount 1 after the interest is: %s\nSavingAccount 2 after the interest is: %s\n", s1, s2); SavingAccount.modifyInterestRate(.025); s1.calculateMonthlyInterest(); s2.calculateMonthlyInterest(); System.out.printf("\nSavingAccount 1 after the new interest is: %s\nSavingAccount 2 after the new interest is: %s\n", s1, s2); }}
Computers and Technology
1 answer:
Lyrx [107]2 years ago
6 0

Answer:

Explanation:

The reason the code was not working was due to a couple of errors. First, the SavingAccount class needed to be public so that it can be accessed within the same file. Secondly, the savingsBalance variable was set to final and therefore could not be modified, the final keyword needed to be removed. Lastly, the constructor for the SavingAccount class was incorrect. Constructors do not use the keyword void and instance class variables need to be referenced using the this keyword.

class SavingAccount{

   // interest rate for all accounts

    private static double annualInterestRate = 0;

    private double savingsBalance;

   public SavingAccount(double savingsBalance) {

       this.savingsBalance = savingsBalance;

   }

   public void calculateMonthlyInterest() {

        savingsBalance += savingsBalance * ( annualInterestRate / 12.0 );

    }// end method calculateMonthlyInterest

   // modify interest rate

   public static void modifyInterestRate( double newRate ) {

        annualInterestRate = ( newRate >= 0 && newRate <= 1.0 ) ? newRate : 0.04;

    } // end method modifyInterestRate

   // get string representation of SavingAccount

   public String toString() { return String.format( "$%.2f", savingsBalance );

    } // end method toSavingAccountString

}// end class SavingAccount

// Using this test codepublic

//

class SavingAccountTest{

   public static void main(String[] args) {

       SavingAccount s1 = new SavingAccount(400);

       SavingAccount s2 = new SavingAccount(1000);

       SavingAccount.modifyInterestRate(0.05);

       System.out.printf("SavingAccount 1 is: %s\nSavingAccount 2 is: %s", s1, s2);

       s1.calculateMonthlyInterest(); s2.calculateMonthlyInterest();

       System.out.printf("\nSavingAccount 1 after the interest is: %s\nSavingAccount 2 after the interest is: %s", s1, s2);

       SavingAccount.modifyInterestRate(.025);

       s1.calculateMonthlyInterest();

       s2.calculateMonthlyInterest();

       System.out.printf("\nSavingAccount 1 after the new interest is: %s\nSavingAccount 2 after the new interest is: %s", s1, s2); }}

You might be interested in
6.An organization wants to implement a remote dial-in server to ensure that personnel can connect to the organization's network
Sauron [17]

Answer:

Challenge-Handshake Authentication Protocol (CHAP).

Explanation:

In Computer technology, authentication can be defined as the process of verifying the identity of an individual or electronic device. Authentication work based on the principle (framework) of matching an incoming request from a user or electronic device to a set of uniquely defined credentials.

Basically, authentication ensures a user is truly who he or she claims to be, as well as confirm that an electronic device is valid through the process of verification.

In this scenario, an organization wants to implement a remote dial-in server to ensure that personnel can connect to the organization's network from remote locations. The authentication protocol must include encryption to prevent hackers from accessing the network.

Hence, the protocol which should be used is Challenge-Handshake Authentication Protocol (CHAP).

A Challenge-Handshake Authentication Protocol (CHAP) can be defined as a standard network access control protocol in which a client program dials in to a network access server to receive a random value and identification number that can only be used once.

5 0
3 years ago
Which term refers to a shorthand method for identifying network and host bits in an ip address?
zloy xaker [14]

A CIDR Notation is known as the term that refers to a shorthand method for identifying network and host bits in an ip address.

<h3>What is CIDR Notation?</h3>

This is known to be a term that was devised in 1993 by the IETF. The  CIDR is said to be a  shorthand method for knowing network and host bits in an IP address.

Therefore, one can say that A CIDR Notation is known as the term that refers to a shorthand method for identifying network and host bits in an ip address.

Learn more about CIDR Notation from

brainly.com/question/14985928

#SPJ12

7 0
1 year ago
A family member who hasn’t worked with computers before has decided to change jobs. You’ve been asked to explain some of the bas
Olin [163]

Answer: That due to the specific tasks that needs to be accomplished by each program to make an all encompassing program would be inefficient and full  of bugs

Explanation: try to do something along those lines ex why would MySQL be used to check your essay for grammar  the tasks are on opposite spectrums

8 0
2 years ago
________ refers to the ability to model components and show how the components' inputs and outputs relate to one another.
Black_prince [1.1K]

Answer:

Central Processing Unit

Explanation:

When the CPU puts the address of a peripheral onto the address bus, the input–output interface decodes the address and identifies the unique computer peripheral with which a data transfer operation is to be executed.

5 0
2 years ago
I need answer poooo<br>​
Fiesta28 [93]

Answer:

what is this?Are yhere any options for this question ❓

7 0
2 years ago
Other questions:
  • If you want the date in your document to update each time the document is opened, _____.
    9·2 answers
  • Which one of the following is NOT true about energy conversion devices? Group of answer choices Total Energy Input = Energy Diss
    8·1 answer
  • The Chart below from Google Trends shows the prevelance of some search terms in the United States between 2004 and the present.
    8·1 answer
  • A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
    12·1 answer
  • Copyright laws protect:This task contains the radio buttons and checkboxes for options. The shortcut keys to perform this task a
    6·1 answer
  • Unlike radio frequency identification (RFID) tags, bar codes: Question 30 options: require a reader that tunes into a specific f
    14·1 answer
  • In cell K8, create a formula using the SUM function that calculates the total of range D17:D20 and subtracts it from the value i
    7·1 answer
  • Choose the best answer from the drop-down menu. A ______ allows multiple connections to a single signal. Without a ______, conne
    7·2 answers
  • Who plays Pokemon Go if you do put your code in your answer so I can friend you.<br><br><br> o_o
    5·2 answers
  • What can you do to make sure no one outside your company can gain access to its wireless network?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!