B.M.S.
COLLEGE OF ENGINEERING
(Autonomous college under VTU)
Bull Temple Rd, Basavanagudi, Bengaluru, Karnataka
560019 2023-2025
Department of Computer Applications
Report is submitted for fulfillment of AAT work in the subject
“Java
Programming”
By
FAADIL KHALEEL
Under the Guidance
Prof. R.V. Raghavendra Rao
(Associate Professor)
1.Find sum of array elements using recursion
import java.util.Scanner;
public class sumrecursion{
public static int sum(int arr[],int l){
if (l == -1)
{
return 0;
}
return arr[l]+sum(arr,l-1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array size:");
int n = sc.nextInt();
int totalsum = 0;
int arr[]=new int[n];
System.out.println("Enter the array elements");
for (int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
totalsum=sum(arr,n-1);
System.out.println("The total sum of the array is"+ totalsum);
sc.close();
outPut:
2.LCM of two numbers using recursion
3.Define a class Employee and Salary Classes with necessary members and methods. Print the
salary slip of an employee.
class Employee {
private String name;
private String id;
private String department;
private Salary salary;
public Employee(String name, String id, String department, Salary salary) {
this.name = name;
this.id = id;
this.department = department;
this.salary = salary;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public String getDepartment() {
return department;
}
public Salary getSalary() {
return salary;
}
public void printSalarySlip() {
System.out.println("Salary Slip");
System.out.println("-----------");
System.out.println("Name: " + name);
System.out.println("Employee ID: " + id);
System.out.println("Department: " + department);
System.out.println("Basic Salary: " + salary.getBasic());
System.out.println("HRA: " + salary.getHra());
System.out.println("DA: " + salary.getDa());
System.out.println("Gross Salary: " + salary.calculateGrossSalary());
}
}
class Salary {
private double basic;
private double hra;
private double da;
public Salary(double basic, double hra, double da) {
this.basic = basic;
this.hra = hra;
this.da = da;
}
public double getBasic() {
return basic;
}
public double getHra() {
return hra;
}
public double getDa() {
return da;
}
public double calculateGrossSalary() {
return basic + hra + da;
}
}
public class salarySlip {
public static void main(String[] args) {
Salary salary = new Salary(50000, 10000, 5000);
Employee employee = new Employee("Faadil Khaleel", "E103", "Engineering", salary);
employee.printSalarySlip();
}
}
4.Create class to read time in seconds and convert into time in (HH:MM:SS) format
import java.util.Scanner;
class TimeConverter {
private int sec;
public TimeConverter(int sec) {
this.sec = sec;
}
public String convertToHHMMSS() {
int hours = sec / 3600;
int minutes = (sec % 3600) / 60;
int remainingSeconds = sec % 60;
return String.format("%02d:%02d:%02d", hours, minutes, remainingSeconds);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter time in seconds: ");
int inputSeconds = scanner.nextInt();
TimeConverter timeConverter = new TimeConverter(inputSeconds);
String formattedTime = timeConverter.convertToHHMMSS();
System.out.println("Time in HH:MM:SS format: " + formattedTime);
scanner.close();
}
}
5. Check whether the entered character is a vowel or consonant.
import java.io.*;
class vowelorcons {
static void Vowel_Or_Consonant(char y)
{
if (y == 'a' || y == 'e' || y == 'i' || y == 'o'
|| y == 'u' || y == 'A' || y == 'E' || y == 'I'
|| y == 'O' || y == 'U')
System.out.println("It is a Vowel.");
else
System.out.println("It is a Consonant.");
}
static public void main(String[] args)
{
Vowel_Or_Consonant('y');
}
}
6. Check whether entered character is alphabet or not, If yes check whether uppercase or lowercase
import java.util.Scanner;
public class alphabet {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char inputChar = scanner.next().charAt(0);
if ((inputChar >= 'A' && inputChar <= 'Z') || (inputChar >= 'a' && inputChar <= 'z')) {
if (inputChar >= 'A' && inputChar <= 'Z') {
System.out.println("The entered character is an uppercase alphabet.");
} else {
System.out.println("The entered character is a lowercase alphabet.");
}
} else {
System.out.println("The entered character is not an alphabet.");
}
scanner.close();
}
}