Programming Practice Set 2
Programming Practice Set 2
Write a program in java to calculate a transpose of a 2D matrix of all positive integers and also replaces all
values greater than one into zero.
Which of the below generates a compile-time error? State the reason.
int[] n1 = new int[0];
boolean[] n2 = new boolean[-200];
double[] n3 = new double[2241423798];
char[] ch = new char[20];
Write a program in java to sort a list of decimal numbers in decreasing order and display the result as the sum
of all even numbers using abstraction.
Create a Java program with two classes 'Bank' and 'Bank Account' and Methods like deposit(), withdraw(),
and displayAccountDetails() in BankAccount class are accessible only within the class itself.
Write a Java program to create an abstract class named Shape that contains two integers
and an empty method named print Area (). Overload the method of print area - for calculating the area of
rectangle and area of square
Create a program to model different types of animals in a zoo. There are three types of animals: Lions,
Elephants, and Monkeys. All animals have common properties such as name and age, and common behaviors
such as eating and sleeping. However, each type of animal has its own specific behavior: Lions roar, Elephants
trumpet, and Monkeys chatter.
Implement the Employee class with attributes such as name, age, and salary. Then, implement the Manager
and Clerk classes inheriting from Employee with additional attributes such as department for Manager and
hoursWorked for Clerk.
Design a vehicle hierarchy using class Vehicle with methods like start(), stop(), and accelerate(). Implement
concrete subclasses such as Car, Motorcycle, and Truck. Write java code to solve it.
Create a java program to make a simple calculator using static methods ('+','-",'*','/')and non static method for
finding factorial of an integer number.
Create a java program to manage different types of employees in an organization. There are three types of
employees: Managers, Developers, and Salespersons. All employees have a common behavior of displaying
their role and salary. However, each type of employee has its own specific behavior: Managers manage teams,
Developers develop software, and Salespersons handle sales.
Given are two one dimensional array A and B which are sorted in ascending order. Write a program to merge
them into single sorted array C that contain every item arrays A and B in ascending order.
Design a Java program to check whether a number is prime or not.
Write a java program to generate all permutations of a given string. For example, given the input "abc", the
output should be "abc", "acb", "bac", "bca", "cab", and "cba".
Write a Java program to print the word "Galgotias University" in reverse order but without using any pre-
defined string function.
Suppose in a school there are 80 students and they have to design a program to calculate students' grade.
Rules are as follows:
marks>=90, Grade - 'O'
marks=>80 to 89, Grade -'E'
marks=>70- 79, Grade-'A'
marks=>60-69, Grade-'B'
marks=>50-59, Grade-'C'
marks<50-'F'
write a Java program to show the grade acquired by a certain student.
Can a constructor be overloaded in Java? Show a Java program to explain the use of a constructor for
inheritance.
Suppose "Amitabh" is a string. Write a program to calculate the length of a string and Compare the string with
another string "Samit" .
Write a java program to store the marks of 10 students.. Also, throw a user defined exception whenever
entered marks are less than 0 or greater than 100.
Design a Java program to model given scenario using inheritance. Consider the following scenario for a
university:
a) There are different types of staff members in the university, including teaching staff and administrative
staff.
b) All staff members have a name and an employee ID.
c) Teaching staff members have additional attributes such as qualification and subject they teach.
d) Administrative staff members have additional attributes such as department and position.