Assignment PGD-PR-2105
Assignment PGD-PR-2105
USOL-PGDCA
import java.util.Scanner;
public class CalcFactorial {
int number;
System.out.println("Enter the number: ");
Scanner scanner = new Scanner(System.in);
number = scanner.nextInt();
scanner.close();
long fact = 1;
int i = 1;
while(i<=number)
{
fact = fact * i;
i++;
}
System.out.println("Factorial of "+number+" is:
"+fact);
}
}
Output:
Enter the number:
6
Factorial of 6 is: 720
import java.util.Scanner;
Output:
Enter the number:
2
Tuesday
import java.util.*;
public class Circle
{
float radius;
float diameter;
float area;
float circumference;
double calcDiameter(float r)
{
return (2*r);
}
double calcArea(float r)
{
return 3.14*r*r ;
}
double calcCircumference(float r)
{
return 2* 3.14 * r ;
}
public static void main(String args[])
{
Circle ob = new Circle();
Scanner in = new Scanner(System.in);
System.out.print("Enter the radius: ");
ob.radius = in.nextLine().valueOf();
System.out.println("Area of circle is" +
ob.calcArea(ob.radius));
System.out.println("Diameter of circle is" +
ob.calcDiameter(ob.radius));
System.out.println("Circumference of circle is" +
ob.calcCircumference(ob.radius));
}
}
Output:
Enter the radius: Area of circle is78.5
Diameter of circle is10.0
Circumference of circle is31.400000000000002
Output:
1
class Commandstr
{
int len=args.length;
if(len==0)
{
System.out.println("No arguments are given ! ");
return;
}
for(int i=0; i<len; i++){
System.out.println(args[i].charAt(0));
}
}
}
Output:
Enter the number
2
Enter the exponent
3
8
Output:
import java.io.*;
class Curr_acct //CURRENT ACCOUNT CLASS
{
final int max_limit = 20;
final int min_limit = 1;
final double min_bal = 500;
private String name[] = new String[20];
private int accNo[] = new int[20];
private String accType[] = new String[20];
private double balAmt[] = new double[20];
static int totRec = 0;
//Intializing Method
public void initialize() {
for (int i = 0; i < max_limit; i++) {
name[i] = "";
accNo[i] = 0;
accType[i] = "";
balAmt[i] = 0.0;
}
}
//TO ADD NEW RECORD
public void newEntry() {
String str;
int acno;
double amt;
boolean permit;
permit = true;
System.out.println("\n\n\n=====RECORDING NEW
ENTRY=====");
do {
System.out.print("Enter Initial Amount
to be deposited : ");
System.out.flush();
str = obj.readLine();
balAmt[totRec] = Double.parseDouble(str);
} while (balAmt[totRec] < min_bal);
//Validation that minimun amount must be 500
System.out.println("\n\n\n");
} catch (Exception e) {}
}
}
System.out.println("\n\n=====DISPLAYING DETAILS OF
CUSTOMER=====\n");
try {
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter Account number : ");
System.out.flush();
str = obj.readLine();
acno = Integer.parseInt(str);
if (acno < min_limit || acno > totRec) //To check
whether accNo is valid or Not
{
if (valid == true) {
System.out.println("\n\nAccount Number : " +
accNo[acno]);
System.out.println("Name : " + name[acno]);
System.out.println("Account Type : " +
accType[acno]);
System.out.println("Balance Amount : " +
balAmt[acno] + "\n\n\n");
}
} catch (Exception e) {}
}
try {
//Reading deposit value
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
if (valid == true) {
System.out.print("Enter Amount you want to
Deposit : ");
System.out.flush();
str = obj.readLine();
amt = Double.parseDouble(str);
try {
//Reading deposit value
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
if (valid == true) {
System.out.println("Balance is : " +
balAmt[acno]);
System.out.print("Enter Amount you want to
withdraw : ");
System.out.flush();
str = obj.readLine();
amt = Double.parseDouble(str);
}
class Sav_acct //SAVING ACCOUNT CLASS
{
final int max_limit = 20;
final int min_limit = 1;
final double min_bal = 500;
private String name[] = new String[20];
private int accNo[] = new int[20];
private String accType[] = new String[20];
private double balAmt[] = new double[20];
static int totRec = 0;
//Intializing Method
public void initialize() {
for (int i = 0; i < max_limit; i++) {
name[i] = "";
accNo[i] = 0;
accType[i] = "";
balAmt[i] = 0.0;
}
}
System.out.println("\n\n\n=====RECORDING NEW
ENTRY=====");
try {
accNo[totRec] = totRec; //Created AutoNumber
to accNo so no invalid id occurs
System.out.println("Account Number : " +
accNo[totRec]);
do {
System.out.print("Enter Initial Amount
to be deposited : ");
System.out.flush();
str = obj.readLine();
balAmt[totRec] = Double.parseDouble(str);
} while (balAmt[totRec] < min_bal);
//Validation that minimun amount must be 500
System.out.println("\n\n\n");
} catch (Exception e) {}
}
System.out.println("\n\n=====DISPLAYING DETAILS OF
CUSTOMER=====\n");
try {
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter Account number : ");
System.out.flush();
str = obj.readLine();
acno = Integer.parseInt(str);
if (acno < min_limit || acno > totRec) //To check
whether accNo is valid or Not
{
System.out.println("\n\n\nInvalid Account
Number \n\n");
valid = false;
}
if (valid == true) {
System.out.println("\n\nAccount Number : " +
accNo[acno]);
System.out.println("Name : " + name[acno]);
System.out.println("Account Type : " +
accType[acno]);
if (valid == true) {
System.out.print("Enter Amount you want to
Deposit : ");
System.out.flush();
str = obj.readLine();
amt = Double.parseDouble(str);
try {
//Reading deposit value
BufferedReader obj = new BufferedReader(new
if (valid == true) {
System.out.println("Balance is : " +
balAmt[acno]);
System.out.print("Enter Amount you want to
withdraw : ");
System.out.flush();
str = obj.readLine();
amt = Double.parseDouble(str);
class Account {
public static void main(String args[]) {
String str;
int choice, check_acct = 1, quit = 0;
if (check_acct == 1) {
do //For Current Account
{
System.out.println("\n\nChoose Your
Choices ...");
System.out.println("1) New Record Entry
");
System.out.println("2) Display Record
Details ");
System.out.println("3) Deposit...");
System.out.println("4) Withdraw...");
System.out.println("5) Quit");
System.out.print("Enter your choice :
");
System.out.flush();
try {
BufferedReader obj = new
BufferedReader(new InputStreamReader(System.in));
str = obj.readLine();
choice = Integer.parseInt(str);
switch (choice) {
case 1: //New Record Entry
curr_obj.newEntry();
break;
case 2: //Displaying Record
Details
curr_obj.display();
break;
case 3: //Deposit...
switch (choice) {
case 1: //New Record Entry
sav_obj.newEntry();
break;
case 2: //Displaying Record
Details
sav_obj.display();
break;
case 3: //Deposit...
sav_obj.deposit();
break;
case 4: //Withdraw...
try {
BufferedReader obj = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("\nEnter 1 for Exit : ");
System.out.flush();
str = obj.readLine();
quit = Integer.parseInt(str);
} catch (Exception e) {}
}
}
}
class Exception_Demo
{
public static void main(String args[])
{
try {
int a = 30, b = 0;
int c = a/b; // cannot divide by zero
System.out.println ("Result = " + c);
}
catch(ArithmeticException e) {
System.out.println ("Can't divide a number by
0");
System.out.println(num);
} catch(NumberFormatException e) {
System.out.println("Number format
exception");
}
}
}
Output:
Can't divide a number by 0
import java.awt.*;
import java.applet.*;
/*
*/
public class Shapes extends Applet
{
public void paint(Graphics g)
{
/*Squar Inside A Circle*/
g.drawString("(c).Square Inside A
Circle",150,110);
g.drawOval(180,10,80,80);
g.drawRect(192,22,55,55);
/*Circle Inside a Squar*/
g.drawString("(d).Circle Inside a
Squar",290,110);
g.drawRect(290,10,80,80);
g.drawOval(290,10,80,80);
}
}