PROGRAM:
import java.util.Scanner;
class exp1a
{
public static void main(String arg[])
{
Scanner s = new Scanner(System.in);
int nod=0;
String month=" ";
System.out.print("Input a month number: ");
int mon = s.nextInt();
System.out.print("Input a year: ");
int year = s.nextInt();
switch (mon)
{
case 1:
month = "January";
nod = 31;
break;
case 2:
month = "February";
if (year % 4 == 0)
{
nod = 29;
}
else
{
nod = 28;
}
break;
case 3:
month = "March";
nod = 31;
break;
case 4:
month = "April";
nod = 30;
break;
case 5:
month = "May";
nod = 31;
break;
case 6:
month = "June";
nod = 30;
break;
case 7:
month = "July";
nod = 31;
break;
case 8:
month = "August";
nod = 31;
break;
case 9:
month = "September";
nod = 30;
break;
case 10:
month = "October";
nod = 31;
break;
case 11:
month = "November";
nod = 30;
break;
case 12:
month = "December";
nod = 31;
}
System.out.println(month + " " + year + " has " + nod + " days");
}
}
OUTPUT:
C:\jp>javac exp1a.java
C:\jp>java exp1a
Input a month number: 5
Input a year: 2023
May 2023 has 31 days
PROGRAM:
public class exp1b
{
public static void main(String args[])
{
int count=args.length;
String temp;
System.out.println("Input Strings...");
for(int i = 0; i < count; i++)
{
System.out.println(args[i]);
}
String str[] = new String[count];
for(int i = 0; i < count; i++)
{
str[i]=args[i];
}
//Sorting the strings
for (int i = 0; i < count-1; i++) // i=0 to 4
{
for (int j = i + 1; j < count; j++) // j=1 to 5
{
if (str[i].compareTo(str[j]) > 0) // hello-hai//101-97=4
{
temp = str[i]; // hello
str[i] = str[j]; // hai
str[j] = temp; // hello
}
}
}
//Displaying the strings after sorting them based on alphabetical order
System.out.println("Output Strings in Alphabetical order...");
for(int i = 0; i < count; i++)
{
System.out.println(str[i]);
}
}
}
OUTPUT:
C:\jp>javac exp1b.java
C:\jp>java exp1b Ruby Ariana Jane
Input Strings...
Ruby
Ariana
Jane
Output Strings in Alphabetical order...
Ariana
Jane
Ruby
PROGRAM:
import java.util.Scanner;
class tneb
{
long cno;
int pmr, cmr;
String cname,type;
public void input()
{
Scanner s= new Scanner(System.in);
System.out.println("Enter Customer Name");
cname=s.nextLine();
System.out.println("Enter Type of connection Domestic or Commercial");
type=s.nextLine();
System.out.println("Enter Customer Number");
cno=s.nextLong();
System.out.println("Enter Previous Month Reading");
pmr=s.nextInt();
System.out.println("Enter Current Month Reading");
cmr=s.nextInt();
}
public void billcal()
{
int d;
double amount=0;
d=cmr-pmr;
System.out.println("EB Bill");
System.out.println("Customer Name \t" +cname);
System.out.println("Customer Number\t" +cno);
System.out.println("Connection type\t" +type);
System.out.println("Consumption\t" +d);
if(type.equalsIgnoreCase("domestic"))
{
if(d<=100)
{
amount=0;
}
if(d>100 && d<=200)
{
amount=(d-100)*2.5;
}
if(d>200 && d<=500)
{
amount=250+(d-200)*4;
}
if(d>500)
{
amount=250+1200+(d-500)*6;
}
System.out.println("EB amount\tRs. " +amount);
}
if(type.equalsIgnoreCase("commercial"))
{
if(d<=100)
{
amount=0;
}
if(d>100 && d<=200)
{
amount=(d-100)*4.5;
}
if(d>200 && d<=500)
{
amount=450+(d-200)*6;
}
if(d>500)
{
amount=450+1800+(d-500)*7;
}
System.out.println("EB amount \tRs. " +amount);
}
}
}
class exp2
{
public static void main(String arg[])
{
tneb t = new tneb();
t.input();
t.billcal();
}
}
OUTPUT:
C:\jp>javac exp2.java
C:\jp>java exp2
Enter Customer Name
Marie
Enter Type of connection Domestic or Commercial
Domestic
Enter Customer Number
33893
Enter Previous Month Reading
250
Enter Current Month Reading
350
EB Bill
Customer Name Marie
Customer Number 33893
Connection type Domestic
Consumption 100
EB amount Rs. 0.0
PROGRAM:
import java.util.Scanner;
class exp3a
{
public static void main(String arg[])
{
int a,b,c;
Scanner s= new Scanner(System.in);
System.out.println("Enter three integer inputs");
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
System.out.println("Max of " +a +" and " +b +" is " +max(a,b));
System.out.println("Max of " +a +", " +b + " and " +c +" is " +max(a,b,c));
}
public static int max(int x, int y)
{
if(x>y)
return x;
else
return y;
}
public static int max(int x, int y, int z)
{
if(x>y)
{
if(x>z)
return x;
else
return z;
}
else
{
if(y>z)
return y;
else
return z;
}
}
}
OUTPUT:
C:\jp>javac exp3a.java
C:\jp>java exp3a
Enter three integer inputs
30 45 19
Max of 30 and 45 is 45
Max of 30, 45 and 19 is 45
PROGRAM:
import java.util.Scanner;
class Big
{
int a,b,c;
Big(int a, int b )
{
this.a=a;
this.b=b;
if(a>b)
System.out.println("Max of " +a +" and " +b +" is " +a);
else
System.out.println("Max of " +a +" and " +b +" is " +b);
}
Big(int a, int b, int c )
{
this.a=a;
this.b=b;
this.c=c;
if(a>b)
{
if(a>c)
System.out.println("Max of " +a +", " +b + " and " +c +" is " +a);
else
System.out.println("Max of " +a +", " +b + " and " +c +" is " +c);
}
else
{
if(b>c)
System.out.println("Max of " +a +", " +b + " and " +c +" is " +b);
else
System.out.println("Max of " +a +", " +b + " and " +c +" is " +c);
}
}
}
class exp3b
{
public static void main(String arg[])
{
int a,b,c;
Scanner s= new Scanner(System.in);
System.out.println("Enter three integer inputs");
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
Big b1 = new Big(a,b);
Big b2 = new Big(a,b,c);
}
}
OUTPUT:
C:\jp>javac exp3b.java
C:\jp>java exp3b
Enter three integer inputs
18 77 49
Max of 18 and 77 is 77
Max of 18, 77 and 49 is 77
PROGRAM:
import java.util.Scanner;
class Employee
{
protected String Emp_name, Address, Mail_id;
protected long Mobile_no;
protected int Emp_id;
public void input()
{
Scanner s = new Scanner(System.in);
System.out.println("Enter Employee name");
Emp_name =s.nextLine();
System.out.println("Enter Address");
Address = s.nextLine();
System.out.println("Enter Mail Id");
Mail_id = s.nextLine();
System.out.println("Enter Mobile Number");
Mobile_no = s.nextLong();
System.out.println("Enter Employee id");
Emp_id=s.nextInt();
}
public void output()
{
System.out.print(Emp_name +'\t' +Address +'\t' +Mail_id +'\t' +Mobile_no +'\t');
System.out.print(+Emp_id +'\t');
}
}
class Programmer extends Employee
{
double Basic_Pay, DA, HRA, PF, staffclub,GS,NS;
public void input1()
{
input();
Scanner s1 = new Scanner(System.in);
System.out.println("Enter Basic Pay");
Basic_Pay =s1.nextDouble();
DA = 0.97*Basic_Pay;
HRA = 0.10*Basic_Pay;
PF = 0.12*Basic_Pay;
staffclub=0.001*Basic_Pay;
GS = Basic_Pay+DA+HRA;
NS = GS-PF-staffclub;
}
public void output1()
{
output();
System.out.println(Basic_Pay +"\t" +DA +"\t"+HRA +"\t" +GS +"\t" +PF +"\t");
System.out.println(+staffclub +"\t"+NS);
}
}
class AsstProfessor extends Employee
{
double Basic_Pay, DA, HRA, PF, staffclub,GS,NS;
public void input1()
{
input();
Scanner s1 = new Scanner(System.in);
System.out.println("Enter Basic Pay");
Basic_Pay =s1.nextDouble();
DA = 0.97*Basic_Pay;
HRA = 0.10*Basic_Pay;
PF = 0.12*Basic_Pay;
staffclub=0.001*Basic_Pay;
GS = Basic_Pay+DA+HRA;
NS = GS-PF-staffclub;
}
public void output1()
{
output();
System.out.println(Basic_Pay +"\t" +DA +"\t"+HRA +"\t" +GS +"\t" +PF
+"\t"+staffclub +"\t"+NS);
}
}
class AssoProfessor extends Employee
{
double Basic_Pay, DA, HRA, PF, staffclub,GS,NS;
public void input1()
{
input();
Scanner s1 = new Scanner(System.in);
System.out.println("Enter Basic Pay");
Basic_Pay =s1.nextDouble();
DA = 0.97*Basic_Pay;
HRA = 0.10*Basic_Pay;
PF = 0.12*Basic_Pay;
staffclub=0.001*Basic_Pay;
GS = Basic_Pay+DA+HRA;
NS = GS-PF-staffclub;
}
public void output1()
{
output();
System.out.println(Basic_Pay +"\t" +DA +"\t"+HRA +"\t" +GS +"\t" +PF
+"\t"+staffclub +"\t"+NS);
}
}
class Professor extends Employee
{
double Basic_Pay, DA, HRA, PF, staffclub,GS,NS;
public void input1()
{
input();
Scanner s1 = new Scanner(System.in);
System.out.println("Enter Basic Pay");
Basic_Pay =s1.nextDouble();
DA = 0.97*Basic_Pay;
HRA = 0.10*Basic_Pay;
PF = 0.12*Basic_Pay;
staffclub=0.001*Basic_Pay;
GS = Basic_Pay+DA+HRA;
NS = GS-PF-staffclub;
}
public void output1()
{
output();
System.out.println(Basic_Pay +"\t" +DA +"\t"+HRA +"\t" +GS +"\t" +PF
+"\t"+staffclub +"\t"+NS);
}
}
class exp4
{
public static void main(String args[])
{
Programmer p = new Programmer();
System.out.println("Input for Programmer");
p.input1();
AsstProfessor p1 = new AsstProfessor();
System.out.println("Input for AsstProfessor");
p1.input1();
AssoProfessor p2 = new AssoProfessor();
System.out.println("Input for AssoProfessor");
p2.input1();
Professor p3 = new Professor();
System.out.println("Input for Professor");
p3.input1();
System.out.println("Payslip for Programmer");
System.out.print("Empname\tAddress\tMail_id\t MobileNo\tEmpid\t");
System.out.println("Basic_Pay\t DA\t HRA\t GS\t PF\tstaffclub\tNS");
p.output1();
System.out.println("Payslip for AsstProfessor");
System.out.print("Empname\tAddress\tMail_id\t MobileNo\tEmpid\t");
System.out.println("Basic_Pay\t DA\t HRA\t GS\t PF\tstaffclub\tNS");
p1.output1();
System.out.println("Payslip for AssoProfessor");
System.out.print("Empname\tAddress\tMail_id\t MobileNo\tEmpid\t");
System.out.println("Basic_Pay\t DA\t HRA\t GS\t PF\tstaffclub\tNS");
p2.output1();
System.out.println("Payslip for Professor");
System.out.print("Empname\tAddress\tMail_id\t MobileNo\tEmpid\t");
System.out.println("Basic_Pay\t DA\t HRA\t GS\t PF\tstaffclub\tNS");
p3.output1();
}
}
OUTPUT:
C:\jp>javac exp4.java
C:\jp>java exp4
Input for Programmer
Enter Employee name
Stacy
Enter Address
3rd street, vincent avenue
Enter Mail Id
[email protected]
Enter Mobile Number
9695958990
Enter Employee id
12345
Enter Basic Pay
20000
Input for AsstProfessor
Enter Employee name
Tom
Enter Address
parker street, california
Enter Mail Id
[email protected]
Enter Mobile Number
9345992010
Enter Employee id
12346
Enter Basic Pay
25000
Input for AssoProfessor
Enter Employee name
Jake
Enter Address
12 A Mary apartments
Enter Mail Id
[email protected]
Enter Mobile Number
9495784997
Enter Employee id
12347
Enter Basic Pay
30000
Input for Professor
Enter Employee name
Danny
Enter Address
Seafront villas, florida
Enter Mail Id
[email protected]
Enter Mobile Number
8425682459
Enter Employee id
12340
Enter Basic Pay
40000
Payslip for Programmer
Empname Address Mail_id MobileNo Empid Basic_Pay DA HRA GS PF
staffclub NS
Stacy 3rd street, vincent avenue [email protected] 9695958990
1235420000.0 19400.0 2000.0 41400.02400.0
20.0 38980.0
Payslip for AsstProfessor
Empname Address Mail_id MobileNo Empid Basic_Pay DA HRA GS PF
staffclub NS
Tom parker street, california [email protected] 9345992010 1235525000.0
24250.0 2500.0 51750.03000.0 25.0 48725.0
Payslip for AssoProfessor
Empname Address Mail_id MobileNo Empid Basic_Pay DA HRA GS PF
staffclub NS
Jake 12 A Mary apartments [email protected] 9495784997 1235630000.0
29100.0 3000.0 62100.0 3600.0 30.0 58470.0
Payslip for Professor
Empname Address Mail_id MobileNo Empid Basic_Pay DA HRA GS PF
staffclub NS
Danny Seafront villas, florida [email protected] 8425682459 1234940000.0
38800.0 4000.0 82800.04800.0 40.0 77960.0
PROGRAM:
import java.util.Scanner;
interface CreditCardInterface
{
void viewCreditAmount();
void viewPin();
void changePin();
void payBalance();
}
class Customer implements CreditCardInterface
{
String name;
long cardnumber;
int pin;
double creditAmount;
void input()
{
Scanner s = new Scanner(System.in);
System.out.println("Enter your name");
name=s.nextLine();
System.out.println("Enter your card number");
cardnumber=s.nextLong();
System.out.println("Enter your card pin");
pin=s.nextInt();
creditAmount=0;
}
public void viewCreditAmount()
{
int ch;
double amt;
System.out.println("Your Credit Amount is " +creditAmount);
System.out.println("Do you want to purchase?\n1.Yes \n2.No");
Scanner s = new Scanner(System.in);
ch=s.nextInt();
if (ch==1)
{
System.out.println("Enter your bill amount");
amt=s.nextDouble();
System.out.println("Amount transferred from your credit card");
creditAmount = creditAmount + amt;
System.out.println("Your Credit Amount is " +creditAmount);
}
if (ch==2)
{
System.out.println("Your Credit Amount is " +creditAmount);
}
}
public void viewPin()
{
System.out.println("Your Pin Number is " +pin);
}
public void changePin()
{
int tp;
viewPin();
Scanner s = new Scanner(System.in);
System.out.println("Enter new Pin Number ");
pin=s.nextInt();
System.out.println("New Pin Number is " +pin);
}
public void payBalance()
{
viewCreditAmount();
double t;
Scanner s = new Scanner(System.in);
if (creditAmount>0)
{
System.out.println("Enter the amount to be tranferred from your account");
System.out.println("It should be less than or equal to " +creditAmount);
t=s.nextDouble();
creditAmount = creditAmount - t;
System.out.println("Credit Amount is " +creditAmount);
}
}
}
class exp5
{
public static void main(String args[])
{
int choice;
Scanner s = new Scanner(System.in);
Customer c = new Customer();
System.out.println("Welcome to Credit Card Application");
c.input();
do
{
System.out.println("Enter your choice \n 1.PayBalance \n 2.Pinchange \n 3.Exit");
choice = s.nextInt();
switch(choice)
{
case 1 :
c.payBalance();
break;
case 2: c.changePin();
}
}while(choice<=2);
}
}
OUTPUT:
C:\jp>javac exp5.java
C:\jp>java exp5
Welcome to Credit Card Application
Enter your name
samantha
Enter your card number
4536363756473857
Enter your card pin
7890
Enter your choice
1.PayBalance
2.Pinchange
3.Exit
1
Your Credit Amount is 0.0
Do you want to purchase?
1.Yes
2.No
1
Enter your bill amount
2500
Amount transferred from your credit card
Your Credit Amount is 2500.0
Enter the amount to be tranferred from your account
It should be less than or equal to 2500.0
1000
Credit Amount is 1500.0
Enter your choice
1.PayBalance
2.Pinchange
3.Exit
2
Your Pin Number is 7890
Enter new Pin Number
1234
New Pin Number is 1234
Enter your choice
1.PayBalance
2.Pinchange
3.Exit
3
PROGRAM:
import java.util.Scanner;
abstract class Shape
{
int a,b;
abstract void printarea();
}
class Rectangle extends Shape
{
void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("Enter 2 Inputs for Rectangle");
a=s.nextInt();
b=s.nextInt();
System.out.println("Area of Rectangle:"+(a*b));
}
}
class Triangle extends Shape
{
void printarea()
{
Scanner s1=new Scanner(System.in);
System.out.println("Enter 2 inputs for Triangle");
a=s1.nextInt();
b=s1.nextInt();
System.out.println("Area of TRiangle:"+(0.5*a*b));
}
}
class Circle extends Shape
{
void printarea()
{
Scanner s2=new Scanner(System.in);
System.out.println("Enter one input for Circle");
a=s2.nextInt();
System.out.println("Area of Circle:"+(Math.PI*a*a));
}
}
class exp6
{
public static void main(String[] args) {
Shape s1=new Rectangle();
s1.printarea();
Triangle s2=new Triangle();
s2.printarea();
Circle s3=new Circle();
s3.printarea();
}
}
OUTPUT:
C:\jp>javac exp6.java
C:\jp>java exp6
Enter 2 Inputs for Rectangle
54
Area of Rectangle:20
Enter 2 inputs for Triangle
32
Area of TRiangle:3.0
Enter one input for Circle
4
Area of Circle:50.26548245743669
PROGRAM:
import java.util.Scanner;
class Customer
{
String name;
int accNo;
int balance;
public Customer(String name, int accNo)
{
this.name = name;
this.accNo = accNo;
this.balance = 0;
}
public void creditTransaction(int amount)
{
Scanner input=new Scanner(System.in);
try
{
if (amount < 0)
throw new InvalidCredit();
else
balance = balance + amount;
}
catch (InvalidCredit e)
{
amount = input.nextInt();
creditTransaction(amount);
}
}
public void debitTransaction(int amount)
{
Scanner input=new Scanner(System.in);
try
{
if (amount > balance)
throw new InvalidDebit();
else
balance = balance - amount;
}
catch (InvalidDebit e)
{
amount = input.nextInt();
debitTransaction(amount);
}
}
public void displayDetails()
{
System.out.println("Customer Details");
System.out.println("****************");
System.out.println("Customer Name : "+this.name);
System.out.println("Customer AccNo : "+this.accNo);
System.out.println("Customer Current Balance : "+this.balance);
}
}
class InvalidCredit extends Exception
{
public InvalidCredit()
{
System.out.print("Please enter valid credit amount");
}
}
class InvalidDebit extends Exception
{
public InvalidDebit()
{
System.out.print("Please enter valid debit amount");
}
}
class exp7
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
String name;
int acc_no;
System.out.println("Enter Customer Name");
name = input.next();
System.out.println("Enter account number");
acc_no = input.nextInt();
Customer s1=new Customer(name,acc_no);
int ch = 0;
while(ch != 4)
{
System.out.println("\n1.Deposit\n2.Withdrawal\n3.Details\n4.Exit");
ch = input.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the amount");
s1.creditTransaction(input.nextInt());
break;
case 2:
System.out.println("Enter the amount");
s1.debitTransaction(input.nextInt());
break;
case 3:
s1.displayDetails();
break;
case 4:
System.out.println("Thank You !!!");
}
}
}
}
OUTPUT:
C:\jp>javac exp7.java
C:\jp>java exp7
Enter Customer Name
Tara
Enter account number
7857849
1.Deposit
2.Withdrawal
3.Details
4.Exit
1
Enter the amount
4500
1.Deposit
2.Withdrawal
3.Details
4.Exit
2
Enter the amount
1000
1.Deposit
2.Withdrawal
3.Details
4.Exit
3
Customer Details
****************
Customer Name : Tara
Customer AccNo : 7857849
Customer Current Balance : 3500
1.Deposit
2.Withdrawal
3.Details
4.Exit
4
Thank You !!!