Untitled

 avatar
unknown
java
3 years ago
5.3 kB
5
Indexable
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rectanglearea;

import java.util.Scanner;

/**
 *
 * @author For Students
 */
public class RectangleArea {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        
//        Scanner input = new Scanner(System.in);
//        Rectangle rectangle = new Rectangle();
//        System.out.println("Enter Rectangle Length:");
//        double length = input.nextDouble();
//        System.out.println("Enter Rectangle Width:");
//        double width = input.nextDouble();
//        rectangle.setLength(length);
//        rectangle.setWidth(width);
//        System.out.println("Area Of Rectange Is:" + rectangle.getArea());
//        System.out.println("Permeter Of Rectange Is:" + rectangle.getPerimeter());
//        
//        System.out.println("------------------------------------------------");
//        System.out.println("Pass Two Array and Sum");
//        System.out.println("------------------------------------------------");
//        
//        int[][] m = PassTwoDimensionalArray.getArray();
//        int sum = PassTwoDimensionalArray.sum(m);
//        System.out.println("Sum of all element is : " + sum);
        
        
        System.out.println("------------------------------------------------");
        System.out.println("Savings Account");
        System.out.println("------------------------------------------------");
        
        SavingsAccount saver1 = new SavingsAccount(2000);
        SavingsAccount saver2 = new SavingsAccount(3000);
        System.out.println("Set Interest Rate 4%");
        SavingsAccount.modifyInterestRate(4);
        System.out.println("Saver 1 Monthly Interest is : " + saver1.calculateMonthlyInterest());
        System.out.println("Saver 2 Monthly Interest is : " + saver2.calculateMonthlyInterest());
        System.out.println("Set Interest Rate 5%");
        SavingsAccount.modifyInterestRate(5);
        System.out.println("Saver 1 Monthly Interest is : " + saver1.calculateMonthlyInterest());
        System.out.println("Saver 2 Monthly Interest is : " + saver2.calculateMonthlyInterest());
    }
    
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rectanglearea;

/**
 *
 * @author For Students
 */
public class Rectangle {
    double length = 1;
    double width = 1;
    
    void Rectangle() {}
    void Rectangle(double length , double width)
    {
        this.length = length;
        this.width = width;
    }
    
    void setLength(double length)
    {
        if(length > 0.00 && length < 20.00 ) {
          this.length = length;  
        }
        
    }
    
    double getLength()
    {
        return this.length;
    }
    
    void setWidth(double width)
    {
        if(width > 0.00 && width < 20.00 ) {
          this.width = width;  
        }
    }
    
    double getWidth()
    {
        return this.width;
    }
    
    double getPerimeter()
    {
        return (2 * this.length) + (2 * this.width);
    }
    
    double getArea()
    {
        return this.length * this.width;
    }
    
    
    
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rectanglearea;

import java.util.Scanner;

/**
 *
 * @author For Students
 */
public class PassTwoDimensionalArray {
    public static int[][] getArray()
    {
        Scanner input = new Scanner(System.in);
        int[][] m = new int[3][4];
        System.out.println("Enter" + m.length + " rows and " + m[0].length + " column");
        for (int i =0; i < m.length ; i++) {
            for(int j =0; j< m[i].length ; j++) {
                m[i][j] = input.nextInt();
            }
        }
        return m;
    }
    
    public static int sum(int[][] m) 
    {
        int total = 0;
         for (int i =0; i < m.length ; i++) {
            for(int j =0; j< m[i].length ; j++) {
                total += m[i][j];
            }
        }
         return total;
    }
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rectanglearea;

/**
 *
 * @author For Students
 */
public class SavingsAccount {
    static double annualInterestRate;
    private int savingsBalance;

    void SavingsAccount() {}
    
    SavingsAccount(int i) {
       this.savingsBalance = i;
    }
    
    double calculateMonthlyInterest()
    {
        return (this.savingsBalance * annualInterestRate) / 12;
    }
    
    static void modifyInterestRate(double rate)
    {
        annualInterestRate = rate;
    }
}
Editor is loading...