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
Knowing the meaning of the acronym WYSIWYG can be most helpful to you when you
Lady_Fox [76]
<span>Knowing the meaning of the acronym WYSIWYG can be most helpful to you when you are trying to buy something. The acronym stand for "what you see is what you get" which could mean in purchase contexts that you don't get tricked in any way, you buy what you saw.</span>
6 0
3 years ago
Please solve this in JAVA<br><br> Please see the attachment
Alina [70]

Answer:

I'm going to do it but you should try these things for yourself or else you won't learn.

Explanation:

-First create a project (I'm using Netbeans 14 and the project is a Maven, but the code should work on any IDE)


-Name the project 'ShoppingCartPrinter' and leave the package name as it is. This is the main class so the main method is gonna be there already.

-Then you will create a second class named 'ItemToPurchase'. So I'll leave the code in the attachment (at the bottom of my answer it's written 'Download txt') or else brainly will think it's some sort of redirection to another websites because of the 'dots' and won't let me post it.






Download txt
3 0
1 year ago
Osing Commands
Sedaia [141]

Answer:

Beggin the perfume and I Can Do B the work done ✅ you are the instances of a marriage license pa bili kami ulam namin pwede po ma'am pwede the too much talking to the work done na na lang sa pag you po sir I will be solemnized

5 0
2 years ago
Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
kotegsom [21]
Hello, I am charlespierce576! I believe I might have the answer! Simple policies such as turning of off devices not in use. Also unplugging devices during a storm.
4 0
3 years ago
The layer of the ISO/OSI responsible for source to destination delivery.
Andrej [43]

Answer:

(b) network

Explanation:

The Network Layer is the OSI Model's third layer. It is in charge of packet transport from source to destination or host to host across various networks. The layer receives data from the transport layer, adds a header to it, and sends it to the data link layer.

7 0
1 year ago
Other questions:
  • If your DTP document contains watermarks on every page, where can you place them?
    13·2 answers
  • Uma organização pode ser entendida como uma instituição ou associação com objetivos predefinidos. Qual é um dos primeiros concei
    10·1 answer
  • Assume that the following variables have been defined in a program: int x = 10; int y = 20; int z = 30; Write a cout statement t
    11·1 answer
  • Is it important for a writer to include voice and point of view in writing because...<br> Plz help
    10·1 answer
  • A reference parameter differs from an output parameter in that a reference parameter ______________________ but an output parame
    5·1 answer
  • Explain motherboard in detail
    14·2 answers
  • Alfred works in the human resources department, and he uses a management information system to find applicants' résumés on the w
    7·1 answer
  • What is Digital Citizen? It's one of my classes.
    5·1 answer
  • The following Python statement instructs the program to open a file for input.
    9·1 answer
  • Q.3.1 Explain why devices on a network need addresses. (5)​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!