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

ablouestions: Answer these questionsl on. Use the class below to answer question

ID: 3862918 • Letter: A

Question

ablouestions: Answer these questionsl on. Use the class below to answer questions 1 through 3. public class sample public int attrib1: public double attrib2: private String n ameobjecti private final int PI 3.14; String data2, double data3) f public Sample (int datal attribl datala name object data attrib2 data3: private int ome Method s //This method will return an integer value return attribl public double calcarea //This method does not accept any argunents return PI attrib2 attrib2: public double calcAreawithRad (double rad) i This method accepts one integer argument return PI rad rad 1. Which attributes (class level variables) could be directly accessed from outside the class? 2. Which methods could only be called from inside the class? 3. write a line of code to create an object instance of the sample class using the constructor defined in the class, passing it three appropriate parameter values.

Explanation / Answer

2. private int someMethod() could be called only from inside the class .because this method has private access modifier .

3. Sample obj = new Sample ( 3, “circle” , 8.0 );

-------------------------------------------------------------------------------------------------------------------------------------------------

package programs;

import java.text.NumberFormat;
import java.util.Scanner;

public class Lab8 {

  
   public static void main(String[] args) {
       Scanner keyboard = new Scanner(System.in);
      
       System.out.println("Deposit Amount :");
       double depositAmount = keyboard.nextDouble();
       System.out.println("Withdrawl Amount :");
       double withdrawlAmount = keyboard.nextDouble();
       System.out.println("1interest rate :");
       double interestRate = keyboard.nextDouble();
      
       Account account1 = new Account();
       account1.deposit(depositAmount);
       account1.withdraw(withdrawlAmount);
       account1.addInterest(interestRate);
      
       NumberFormat money = NumberFormat.getCurrencyInstance();
       System.out.println("Balance is :"+ money.format(account1.getBalance()));
      

   }

}

------------------------------------------------------------------------------------------------------------------------------------------

package programs;

public class Account {
   private double balance;
   public Account()
   {
       balance =0;
   }
   public double getBalance()
   {
       return balance;
   }
   public void deposit(double amount)
   {
       balance=balance+amount;
   }
   public void withdraw(double amount)
   {
       balance = balance-amount;
   }
   public void addInterest(double interestRate)
   {
       balance = balance + balance * interestRate;
   }

}