Question

In: Computer Science

This method will return a double value that equals to the balance + 10% of balance...

This method will return a double value that equals to the balance + 10% of balance

How can I get a 10 percent of a balance in java?

Solutions

Expert Solution


public class TenPercent {
  
   //Since, x % of a value = value* (x /100)
   //So, 10 % of a value = value* (10 /100)
   //that is equal to value* 0.1
  
   // this function assumes the balance value is double
   // it takes the balance and adds 10% of balance to it as follows
  
   public static double addTenPercent(double balance) {
       return balance+balance*0.1;
   }
   // this function does the same assuming balance is integer
   // (double) is used to cast int value.. this converts integer value to double
   public static double addTenPercent(int balance) {
       return (double)balance+(double)balance*0.1;
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       int balance1=1000;
       double balance2 =1000;
       System.out.println("10% added to the balance is ->" +addTenPercent(balance1));
       System.out.println("10% added to the balance is ->" +addTenPercent(balance2));

   }

}

========================================================

Above code contains two functions, one assumes balance to be integer and the other double.

Basic idea remains the same.

Percentage of a value is given as ..

Let's say x % of y = y * ( x/100)

So, 10% of y = y * (10/100)

                     = y*0.1

Below is the output of the above code..

thanks


Related Solutions

4) Double-declining-balance depreciation: A) is an accelerated depreciation method. B) ignores the residual value in computing...
4) Double-declining-balance depreciation: A) is an accelerated depreciation method. B) ignores the residual value in computing depreciation, except during the last year. C) is based on the book value of the plant asset. D) is all of the above. 5) All of the following are needed to measure depreciation, EXCEPT for: A) cost. B) market value. C) estimated useful life. D) estimated residual value. 6) A depreciation method in which an equal amount of depreciation expense is assigned to each...
The method of depreciation was changed from the double-declining-balance method to the straight-line method in fiscal...
The method of depreciation was changed from the double-declining-balance method to the straight-line method in fiscal 2015. A machine was purchased on January 1, 2014 at a cost of $150,000. The machine has an estimated useful life of 10 years and a residual value of $9,000. What should have been booked as depreciation expense in fiscal 2015?
Write a method named area with one double parameter name radius. The method needs to return...
Write a method named area with one double parameter name radius. The method needs to return a double value that represents the area of a circle. If the parameter radius is negative , then return -1.0 to present an invalid value Write another overload method with 2 parameters side1 and side2 (both double) where side1 and side2 represent the sides of a rectangle. The method needs to return an area of a rectangle . If either or both parameters is/...
Write a method named area with one double parameter name radius, the method needs to return...
Write a method named area with one double parameter name radius, the method needs to return a double value that represents the area of a circle. If the parameter radius is negative, then return -1.0 to represents an invalid value write another overload method with 2 parameter side 1 and side 2 (double) where side 1 and side 2 represents the sides of a rectangle. The method needs to return an area of a rectangle. If either or both parameters...
Question #10: Perry Inc. uses the Net Present Value method and requires a return of 11%....
Question #10: Perry Inc. uses the Net Present Value method and requires a return of 11%. Perry Inc. is considering the following 2 mutually exclusive projects: Cash Flow for Year Project A Project B 0 -$77,500 -$77,500 1 $43,000 $21,000 2 $29,000 $28,000 3 $23,000 $34,000 4 $21,000 $41,000 Required: Using the Net Present Value method, should Perry accept or reject Project A? Project B? why?
Write a method that, given an array of grades stored as double values, computes and return...
Write a method that, given an array of grades stored as double values, computes and return their mean.    Write another method that will return an array of the mean grade obtained by an arbitrary number of student.    This method will take a 2-dimensional array of double values in which each row corresponds to the grade vector    for a different student. You can compute the mean for each row as you did before...    Once you are done,...
Which is NOT a valid return type for a method declaration Select one: a. double b....
Which is NOT a valid return type for a method declaration Select one: a. double b. char c. null d. String e. boolean f. float g. int h. void Statements that allow a program to choose, based on a boolean expression, between alternative blocks of code are known as: Select one: a. Selection statements or Conditionals b. Declarations c. Methods d. Repetition Statements or Loops e. Composition
The beta on Stock A equals 0.75, and the expected return equals 8.625%. The risk free...
The beta on Stock A equals 0.75, and the expected return equals 8.625%. The risk free rate equals 3%. Calculate the expected return on the market. (Enter percentages as decimals and round to 4 decimals)
1. Assuming A equals the binary value 10101010 and B equals the binary value 11110000, the...
1. Assuming A equals the binary value 10101010 and B equals the binary value 11110000, the result of the bitwise-OR of A with B is? Just enter the 8-bit binary number that represents the result of the operation. Do not add any spaces, decimal points, commas, or base-2 subscript. Do not delete leading zeros. 2. Assuming A equals the binary value 10101010 and B equals the binary value 11110000, the result of the bitwise-XOR of A with B is? Just...
how to switch from straight line to double-declining-balance method? give an example.
how to switch from straight line to double-declining-balance method? give an example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT