التخطي إلى المحتوى الرئيسي

المشاركات

عرض الرسائل ذات التصنيف Java Program

What is Singleton class in Java?

  What is Singleton class in Java? It is a special class in java that is used to provide restriction to create multiple objects, it provides only a single object creation of class using the static reference method. static block and underclass using the final modifier. It is used to implement the Singleton design pattern in Java Application. Rules of Singleton class:- 1)  Singleton class constructor should be private to restrict create a new object from any external method or main() 2)  create a static reference type  method and create an object when static reference is null It is used to provide a Singleton design pattern in a project where we want to create only a single object for all business class that is used in the project. CODE OF SINGLETON DESIGN PATTERN:- class Singletion {     private static Singletion obj;     static String s="";     private Singletion()     {     }     public static Singletion ge...

WAP to calculate age where the son is 20 years younger than ...?

  WAP to calculate age where the son is 20 years younger than the father and 18 years younger than the mother what will be the age of the son, father, and mother, calculation start year will be entered by the user? year=2002 son age  18 father age 38 mother age 36 Program Answer:- import java.util.Scanner; class CalculateAge {    public static void main(String args[])    {         int year,fage,mage,sage;                  Scanner sc = new Scanner(System.in);         System.out.println("Enter year");         year = sc.nextInt();         sage = 2020-year;         fage = sage + 20;         mage = sage + 18;         System.out.println("Son Age is "+sage);         System.out.println("Father Age is "+fage);         System.out.println("Mother ...

Program to calculate Compound Interest in Java?

 Program to calculate Compound Interest in Java? This is a common program that will be asked by multiple interviewers from freshers and experienced both. most of the students work on SI but they not comfortable with SI Calculation but not know Compound Interest Calculation easily. We will use Math.pow() function to calculate CI. Math.pow() has two parameters, the first parameters will be base and the second parameters will be an exponent. Math.pow(base,exponent) Formula will be  = principal * (Math.pow(1+(r/100),n*t) Complete program to calculate compound interest? import java.util.Scanner; class CI { public static void main(String args[])    {        float p,r,t,n,a;        double total;        Scanner sc = new Scanner(System.in);        System.out.println("Enter p");        p=sc.nextFloat();        System.out.println("Enter r");     ...