Wrapper Class Methods in Java

Wrapper Class:

It has some of unique methods for handling primitive data type and objects. The wrapper classes contained in the java.lang package. Some wrapper classes for converting simple data types are the following:




Simple Data Type Wrapper Class
booleanBoolean
charCharacter
doubleDouble
floatFloat
intInteger
longLong

Program:

import java.io.*;
class invest
{
public static void main (String args[])
{
Float principal_amount=new Float(0);
Float intest_rate=new Float(0);
int years=0;
try
{
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter Principal Amount:");
System.out.flash();
String principalString=in.readLine();
principal_Amount=Float.valueOf(principalString);
System.out.print("Enter Interest Rate:");
System.out.flash();
String interestString=in.readLine();
interest_rate=Float.valueOf(interestString);
System.out.print("Enter Number of Years:");
System.out.flash();
String yearsString=in.radLine();
years=Integer.parseInt(yearsString);
}
catch(IOException e)
{
System.out.println("I/O Error");
System.exit(1);
}
float value=loan(principal_amount.floatValue(), interestRate.floatValue(), years);
printline();
System.out.println("Final Value="+value);
printline();
}
static float loan (float a, float b, int y)
{
int year=1;
float sum=p;
while(year<=y)
{
sum=sum*(1+r);
year=year+1;
}
return sum;
}
}

enum:

It allows us to use the enumerated type in Java using the enum keyword. It is used for the static final constants in the earlier version of Java (J2SE 5.0).

Program:

public class Temp
{
enum Days
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
public static void main(String args[])
{
for(Days d:Days.values())
{
weekend(d);
}
}
private static void weekend(Days d)
{
if(d.equals(Days.sunday)
System.out.println("Value :"+d+"is a Holiday");
else
System.out.println("Value :"+d+"is a Working day");
}
}

Output:
enum