Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8.Open the class ”Account”. Create getter and setter methods for setting and ret

ID: 3598715 • Letter: 8

Question

8.Open the class ”Account”. Create getter and setter methods for setting and retrieving the values of the instance variables name and balance.

9.In class ”Account”, look at the method printNum- bers(int limit). Add a for loop to this method. The for loop should count from 0 to limit-1. For each iteration, you should print the current iteration using System.out.println(variableUsedForInitialValueInForLoop)

10.To compare Strings, remember that you need to call the following method: nameOfSomeString.equals(”String you want to compare”). For example:

String a = ”Hello”;
boolean b = a.equals(”Hello”);

This checks, for string a of value ”Hello”, if the string given to it is also ”Hello”. In class ”Account”, write a method: public void compareToName(String nameToCompare) {}
That prints a message of success if the String given as an argument is equal to the instance variable name, or a failure message otherwise.

Account.java 3 Hw2Driver.java 1 importjava.util.5canner 3 public class Account 4 private double balance; 95private String name 7 11Question 8: add the getters and setters for balance and name here: 9 1/Question 9: add the for loop to the following method: 1 public void printNumbersCint limit) /I Your for loop should go here 12 13 14 15 //Question 10: put your method for comparing a String to name here

Explanation / Answer

Here is the Account class after adding the code for the given questions

Accoutn.java

import java.util.Scanner;

public class Account {

       private double balance;

       private String name;

      

       //Question 8: add the getters and setter for balance and name here:

      

       //getters

       //method that gets the balance

       public double getBalance()

       {

              return balance;

       }

      

       //method that gets name

       public String getName()

       {

              return name;

       }

      

       //setters

       //method that sets balance

       public void setBalance(double dblbalance)

       {

              balance = dblbalance;

       }

      

       //method that sets name

       public void setName(String strName)

       {

              name = strName;

       }

      

       //Question 9: add the for loop to the following method:

       public void printNumbers(int limit)

       {

              //Your for loop should go here

              for(int number = 0; number <= limit-1; number++)

              {

                     System.out.println(number);

              }

       }

      

       //Question 10: put your method for comparing a String to name here

       public void compareToName(String nameToCompare)

       {

              //check the names

              if(name.equals(nameToCompare))

                     //print success message if the names are qual

                     System.out.println("Both the name are equal");

              else

                     //else print failure message

                     System.out.println("Both the name are not equal");

       }     

}

Let me know if you have any concerns

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote