Monday, January 30, 2023

Emi calculator in java code

Here's a simple Java code to calculate EMI (Equated Monthly Installment) using the formula:


import java.math.BigDecimal;

import java.math.RoundingMode;


public class EMI_Calculator {

  public static void main(String[] args) {

    double p = 10000;   // Loan amount

    double r = 0.05;    // Interest rate

    int n = 12;         // Loan tenure in months


    double emi = (p * r * Math.pow(1 + r, n)) / (Math.pow(1 + r, n) - 1);


    BigDecimal bd = new BigDecimal(emi).setScale(2, RoundingMode.HALF_UP);

    System.out.println("EMI: $" + bd.doubleValue());

  }

}


This code calculates the EMI for a loan of $10,000 with 5% interest rate for a tenure of 12 months. The output will be rounded to 2 decimal places using BigDecimal class. 

How to upload file in anguar?


You can use the Angular reactive forms module to create a form with a file input control. Here's a basic example of how to do it:


1. Import ReactiveFormsModule in your component's module:


import { ReactiveFormsModule } from '@angular/forms';


@NgModule({

  imports: [

    ReactiveFormsModule,

    ...

  ],

  ...

})

export class AppModule { }



2. In your component, create a form group and add a control for the file input:



import { FormGroup, FormBuilder } from '@angular/forms';


export class FileUploadComponent {

  form: FormGroup;


  constructor(private fb: FormBuilder) {

    this.form = this.fb.group({

      file: [null]

    });

  }

}



3. In your component's template, create a file input and bind it to the form control:


<form [formGroup]="form">

  <input type="file" formControlName="file">

</form>


4. Finally, in your component, you can access the selected file(s) using the value of the form control:


submit() {

  const file = this.form.get('file').value;

  console.log(file);

}

 <form [formGroup]="form"> - This is an Angular template directive that binds a FormGroup instance to the form element. The FormGroup is used to manage the values and validation of form controls.


<input type="file" formControlName="file"> - This is a file input element that is bound to a form control named "file".


<button (click)="submit()">Upload</button> - This is a submit button that triggers the submit() function when clicked.


import { FormGroup, FormBuilder } from '@angular/forms'; - This is an import statement for the FormGroup and FormBuilder classes from the @angular/forms module.


this.form = this.fb.group({ file: [null] }); - This is code that creates a new FormGroup instance using the FormBuilder and adds a single control named "file".


const file = this.form.get('file').value; - This code accesses the value of the "file" form control.


console.log(file) - This code logs the selected file to the console for debugging purposes.


How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...