IPA - Practice Question and Ans
IPA - Practice Question and Ans
Sample input2:
100
200
300
400
500
100
500
Output:
300
import java.util.*;
public class MyClass{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
for(int i = 0; i < 5; i++){
arr[i] = sc.nextInt();
}
int limit1 = sc.nextInt();
int limit2 = sc.nextInt();
int sum = 0, count = 0;
for(int a : arr){
if(a > limit1 && a < limit2){
sum += a;
count++;
}
}
System.out.println(sum / count);
}
}
TCS IPA QUESTION ANSWER
The above attributes should be private, write getters, setters and parameterized constructor as required.
findPlayerWithLowestRuns method:
This method will take array of Player objects and a String value as input parameters.
The method will return the least runs of the Player from array of Player objects for the given player type.
(String parameter passed). If no Player with the above condition are present in array of Player objects,
then the method should return 0.
findPlayerByMatchType method:
This method will take array of Player objects and String value as input parameters and return the array of Player objects
belonging to the match type passed as input parameter in Descending order of playerId.
If no Player with the above condition are present in the array of Player objects, then the method should return null.
Note : No two Players will have the same playerId and runs.
All the searches should be case insensitive.
The above mentioned static methods should be called from the main method.
For findPlayerWithLowestRuns method - The main method should print the returned runs as it is
if the returned value is greater than 0 or it should print "No such player".
Eg: 25
where 25 is the lowest runs of the Player.
For findPlayerByMatchType method - The main method should print the playerId from the returned Player array for each
Player if the returned value is not null.
If the returned value is null then it should print "No Player with given matchType".
Eg:
13
11
where 13 and 11 are the playerId's.
Before calling these static methods in main, use Scanner object to read the values of four Player
objects referring attributes in the above mentioned attribute sequence.
Next, read the value of two String parameter for capturing player type and match Type.
Input1:
11
Sachin
100
TCS IPA QUESTION ANSWER
International
One day
12
Shewag
133
International
Test
13
Varun
78
State
Test
14
Ashwin
67
State
One day
State
One day
Output:
67
14
11
Input2:
11
Sachin
100
International
One day
12
Shewag
133
International
Test
13
Varun
78
State
Test
14
Ashwin
67
State
One day
District
T20
Output:
No such player
No Player with given matchType
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Player[] arr = new Player[4];
for (int i = 0; i < arr.length; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
sc.nextLine();
String d = sc.nextLine();
String e = sc.nextLine();
arr[i] = new Player(a,b,c,d,e);
}
String q1 = sc.nextLine();
String q2 = sc.nextLine();
int answer1 = findPlayerWithLowestRuns(arr, q1);
if(answer1 > 0){
System.out.println(answer1);
}else{
System.out.println("No such player");
}
Player[] answer2 = findPlayerByMatchType(arr, q2);
if(answer2 != null){
for (int i = 0; i < answer2.length; i++) {
for (int j = i; j < answer2.length; j++) {
if(answer2[i].getid() < answer2[j].getid()){
Player temp = answer2[i];
answer2[i] = answer2[j];
answer2[j] = temp;
}
}
}
for(Player a: answer2){
System.out.println(a.getid());
}
}else{
System.out.println("No Player with given matchType");
}
}
public static int findPlayerWithLowestRuns(Player[] arr, String q1){
int[] ans = new int[0];
for (int i = 0; i < arr.length; i++) {
if(arr[i].getptype().equalsIgnoreCase(q1)){
ans = Arrays.copyOf(ans, ans.length + 1);
ans[ans.length - 1] = arr[i].getrun();
}
}
Arrays.sort(ans);
TCS IPA QUESTION ANSWER
class Player{
private int id;
private String name;
private int run;
private String ptype;
private String mtype;
public Player(int id, String name, int run, String ptype, String mtype){
this.id = id;
this.name = name;
this.run = run;
this.ptype = ptype;
this.mtype = mtype;
}
}
TCS IPA QUESTION ANSWER
int sum = 0;
while(num > 0){
sum += num % 10;
num /= 10;
}
if(sum % 3 == 0){
System.out.println("TRUE");
}else{
System.out.println("FALSE");
}
}
}
}else{
for(int i = ans2.length - 1; i >= 0 ; i--) {
if(ans2[i] != -1){
System.out.println(arr[ans2[i]].getid());
System.out.println(arr[ans2[i]].getrating());
}
}
}
}
static boolean check(int[]arr){
for (int i = 0; i < arr.length; i++) {
if(arr[i] != -1){
return false;
}
}
return true;
}
public static int countbybrand(Laptop[]arr, String qbrand){
int count = 0;
for (int i = 0; i < arr.length; i++) {
if(arr[i].getbrand().equalsIgnoreCase(qbrand) && arr[i].getrating() > 3){
count++;
}
}
return count;
}
public static int[] countbyos(Laptop[] arr, String qos){
int[] ans = {-1,-1,-1,-1};
for (int i = 0; i < arr.length; i++) {
if(arr[i].getos().equalsIgnoreCase(qos)){
ans[i] = i;
}
}
return ans;
}
}
class Laptop{
private int id;
private String brand;
private String os;
private double price;
private int rating;
public Laptop(int id, String brand, String os, double price, int rating){
this.id = id;
this.brand = brand;
this.os = os;
this.price = price;
this.rating = rating;
}
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
int sum = 0;
for(int i = 0; i < arr.length; i++){
arr[i] = sc.nextInt();
if(arr[i] % 2 != 0){
sum += arr[i];
}
}
if(sum > 8 && sum < 50){
System.out.println("Sum of odd numbers:"+sum);
}else{
System.out.println("NA");
}
}
}
TCS IPA QUESTION ANSWER
sc.nextLine();
hotels[i] = new Hotel(hId, hName, dBook, noRoom, wifi, tBill);
}
String month = sc.next();
String wifiOption = sc.next();
int roomBook = noRoomBook(hotels, month);
Hotel hotelSecond = searchWifi(hotels, wifiOption);
if (roomBook > 0) {
System.out.println(roomBook);
} else {
System.out.println("No rooms booked in the given month");
}
if (hotelSecond != null) {
System.out.println(hotelSecond.gethId());
} else {
System.out.println("No such option available");
}
sc.close();
}
public static int noRoomBook(Hotel[] hotels, String month) {
int tRoombook = 0;
for (Hotel hotel: hotels) {
if (hotel.getdBook().toLowerCase().contains(month.toLowerCase())) {
tRoombook += hotel.getnoRoom();
}
}
return tRoombook;
}
public static Hotel searchWifi(Hotel[] hotels, String wifiOption) {
Hotel hBill = null;
Hotel secondhbill = null;
for (Hotel hotel: hotels) {
if (hotel.getwifi().equalsIgnoreCase(wifiOption)) {
if (hBill == null || hotel.gettbill() > hBill.gettbill()) {
secondhbill = hBill;
hBill = hotel;
} else if (secondhbill == null || hotel.gettbill() > secondhbill.gettbill()) {
secondhbill = hotel;
}
}
}
return secondhbill;
}
}
TCS IPA QUESTION ANSWER
In the main method, write code to read a numeric digit(without any alphabets or special characters) using
Scanner and print it in the reverse sequence as they appear in the input.
Java Question 2
Write main method in Solution class.
In the main method, read a String (which may have alphabets along with numeric digits) and print the number
of vowel and consonants (any alphabet apart from vowel is a consonant) present in the given String.
Note: The output should be printed in the same format as mentioned in the sample output.
Input:
Welcome123
Output:
Number of Vowels: 3
Number of Consonants: 4
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String num = sc.next();
int v = 0, c = 0;
String n = num.toLowerCase();
for (int i = 0; i < n.length(); i++) {
if (Character.isLetter(n.charAt(i))) {
if (n.charAt(i) == 'a' || n.charAt(i) == 'e' || n.charAt(i) == 'i' || n.charAt(i)
== 'o' || n.charAt(i) == 'u') {
v++;
} else {
c++;
}
}
}
if (v > 0 || c > 0) {
System.out.println("Number of Vowels: " + v);
System.out.println("Number of Consonants: " + c);
} else {
System.out.println("NA");
}
}
}
TCS IPA QUESTION ANSWER
Java Question 3
Write main method in Solution class.
In the main method, read a String and print all consonants characters (in lower case) in the sequence as they
appear in the input value. Please note: The consonants are characters that are not vowels.
Sample input:
DATABase
Output:
dtbs
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
String ans = n.toLowerCase();
for (int i = 0; i < ans.length(); i++) {
if (ans.charAt(i) == 'a' || ans.charAt(i) == 'e' || ans.charAt(i) == 'i' ||
ans.charAt(i) == 'o' || ans.charAt(i) == 'u') {
continue;
} else {
System.out.print(ans.charAt(i));
}
}
}
}
TCS IPA QUESTION ANSWER
Java Question 4
Write main method in Solution class.
In the main method, write code to read a String value using Scanner and print the smallest vowel. Assume all
input values are in lower case.
E.g If the input value is "matrix" then output will be a (since there are two vowels a and i where a is smaller as
per ASCII sequence).
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String ans = sc.nextLine();
String result = "";
for (int i = 0; i < ans.length(); i++) {
if (ans.charAt(i) == 'a' || ans.charAt(i) == 'e' || ans.charAt(i) == 'i' ||
ans.charAt(i) == 'o' || ans.charAt(i) == 'u') {
result += ans.charAt(i);
}
}
char[] arr = result.toCharArray();
Arrays.sort(arr);
System.out.println(arr[0]);
}
}
Java Question 5
In the main method, write code to read a String value using Scanner and print characters at odd position as
single String (Not index but position. Refer below example).
E.g If the input value is "Matrix". Then we have total 6 characters with 'M'at first position and 'x' at 6th position.
Hence the characters at odd position will be 1st, 3rd and 5th character which is "Mti".
If the input value has space or any other special character then the same should be conuted as usual.
E.g if the input value is "Hi There" then the output will be "H hr"
Note that the output is printed in same line with all characters together. ("Mti" and "H hr").
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.nextLine();
for (int i = 0; i < n.length(); i += 2) {
System.out.print(n.charAt(i));
}
}
}
TCS IPA QUESTION ANSWER
Java Question 6
Create a Class Medicine with the below attributes:
medicineName - String
batchNo - String
disease - String
price - int
This method will take a String parameter named disease along with the other parameter as array of
Medicine objects.
The method will return an array of Integer containing the price of the medicines in ascending order, if the
given input(disease) matches the disease attribute of the medicine objects in the Array.
This method should be called from the main method and display the prices.
Main method mentioned above already has Scanner code to read values, create objects and test above
methods. Hence do not modify it.
Input:
Hyadry
FHW0602
EyeDryness
140
Dolo
FHW0603
Fever
10
OpsionHA
P5011
EyeDryness
435
Mucinex
C0011
Cold
15
EyeDryness
Output:
140
435
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Med[] arr = new Med[4];
for (int i = 0; i < arr.length; i++) {
String a = sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();
sc.nextLine();
arr[i] = new Med(a, b, c, d);
}
String q = sc.nextLine();
int[] ans1 = find(arr, q);
for (int a: ans1) {
System.out.println(a);
}
}
public static int[] find(Med[] arr, String q) {
int[] ans = new int[0];
for (int i = 0; i < arr.length; i++) {
if (arr[i].getdis().equalsIgnoreCase(q)) {
ans = Arrays.copyOf(ans, ans.length + 1);
ans[ans.length - 1] = arr[i].getprice();
}
}
Arrays.sort(ans);
return ans;
}
}
class Med {
private String name;
private String batch;
private String dis;
private int price;
public String getdis() {
return dis;
}
public int getprice() {
return price;
}
public Med(String name, String batch, String dis, int price) {
this.name = name;
this.batch = batch;
this.dis = dis;
this.price = price;
}
}
TCS IPA QUESTION ANSWER
Java - Question 7
Create a Class Player with below attributes:
playerId - int
playerName - String
iccRank - int
noOfMatchesPlayed - int
totalRunsScored - int
Write getters, setters and parameterized constructor as required. Create class Solution with main method.
Implement static method - findAverageScoreOfPlayers in Solution class. This method will take an int
parameter named target along with the other parameter as array of Player objects. The method will
calculate the average runrate of the player based on totalRunsScored and noOfMatchesPlayed and return the
same in a double array where the noOfMatchesPlayed attribute is greater than or equal to the int parameter
target passed.
This method should be called from the main method and display the Grade of the players. If the
averageRunRate is greater than or equal to 80 then it should print "Grade A Player". If the averageRunRate is
between 50 to 79 then it should print "Grade B Player", else it should print "Grade C Player" .
Before calling this method(findAverageScoreOfPlayers) in the main method, use Scanner object to read
values for four Player objects referring the attributes in the above sequence. then, read the value for
noOfMatchesPlayed parameter. Next call the method findAverageScoreOfPlayers, write the logic to display
the Grade(in the main method) and display the result.
Output:
Grade A Player
Grade A Player
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Player[] arr = new Player[4];
for (int i = 0; i < arr.length; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
sc.nextLine();
int d = sc.nextInt();
sc.nextLine();
int e = sc.nextInt();
sc.nextLine();
arr[i] = new Player(a, b, c, d, e);
}
int target = sc.nextInt();
int[] ans = findavg(arr, target);
for (int i = 0; i < ans.length; i++) {
if (ans[i] >= 80) {
System.out.println("Grade A Player");
} else if (ans[i] >= 50 && ans[i] < arr.length; i++) {
if (arr[i].getmatch() >= n) {
ans = Arrays.copyOf(ans, ans.length + 1);
ans[ans.length - 1] = arr[i].getrun() / arr[i].getmatch();
}
}
return ans;
}
}
class Player {
private int id;
private String name;
private int rank;
private int match;
private int run;
public Player(int id, String name, int rank, int match, int run) {
this.id = id;
this.name = name;
this.rank = rank;
this.match = match;
this.run = run;
}
public int getmatch() {
return match;
}
public int getrun() {
return run;
} }
TCS IPA QUESTION ANSWER
Java - Question 8
Create a Class Player with below attributes:
id - int
country - String
side - String
price - double
This method will take a String parameter along with the other parameter as array of Player objects.
The method will return array of Player where the String parameter appears in the side attribute (with case
insensitive search).
This method should be called from main method and display the id of returned objects in ascending order.
Before calling this method(searchPlayerForMatch) in the main method, use Scanner object to read values for
four Player objects referring the attributes in the above sequence.
then, read the value for search parameter.
Next call the method searchPlayerForMatch, write the logic to sort the id in ascending order (in main method)
and display the result.
Input:
1
India
Batting
2500000
2
Australia
Batting
1000000
3
Srilanka
Bowling
1700000
4
England
Bowling
2000000
Batting
Output:
1
2
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Player[] arr = new Player[4];
for (int i = 0; i < arr.length; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
double d = sc.nextDouble();
sc.nextLine();
arr[i] = new Player(a, b, c, d);
}
String q = sc.nextLine();
int[] ans = find(arr, q);
for (int a: ans) {
System.out.println(a);
}
}
public static int[] find(Player[] arr, String q) {
int[] ans = new int[0];
for (int i = 0; i < arr.length; i++) {
if (arr[i].getside().equalsIgnoreCase(q)) {
ans = Arrays.copyOf(ans, ans.length + 1);
ans[ans.length - 1] = arr[i].getid();
}
}
Arrays.sort(ans);
return ans;
}
}
class Player {
private int id;
private String country;
private String side;
private double price;
public int getid() {
return id;
}
public String getside() {
return side;
}
public Player(int id, String country, String side, double price) {
this.id = id;
this.country = country;
this.side = side;
this.price = price;
}
}
TCS IPA QUESTION ANSWER
Java - Question 9
Create a class Sim with below attributes:
simId - int
customerName - String
balance - double
ratePerSecond - double
circle – String
Write getters, setters and parameterized constructor as required. Public class Solution is already created
with main method. Code inside main method should not be altered else your solution might be scored as
zero. You may copy the code from main method in eclipse to verify your implementation.
Implement static method - transferCustomerCircle in Solution class. This method will take first parameter as
array of Sim class objects, second parameter as circle to be transferred (which is String parameter circle1)
and third parameter as new circle (which is String parameter circle2). Method will transfer the customer to
new circle (circle2), where the circle attribute would match second parameter (circle1). Method will return
array of Sim objects for which circle is transferred. Return array should be sorted in descending order of
ratePerSecond (assuming ratePerSecond is not same for any of the Sim objects). This method should be
called from main method and display the simId,customerName,circle and ratePerSecond of returned objects
(as per sample output). Main method mentioned above already has Scanner code to read values, create
objects and test above methods. Hence do not modify it.
Consider below sample input and output:
Input:
1
raj
100
1.5
KOL
2
chetan
200
1.6
AHD
3
asha
150
1.7
MUM
4
kiran
50
2.2
AHD
5
vijay
130
1.8
AHD
AHD
KOL
Output:
4 kiran KOL 2.2
5 vijay KOL 1.8
2 chetan KOL 1.6
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Sim[] sim = new Sim[5];
for (int i = 0; i < 5; i++) {
int simId = sc.nextInt();
sc.nextLine();
String customerName = sc.nextLine();
double balance = sc.nextDouble();
double ratePerSecond = sc.nextDouble();
sc.nextLine();
String circle = sc.nextLine();
sim[i] = new Sim(simId, customerName, balance, ratePerSecond, circle);
}
String circle1 = sc.nextLine();
String circle2 = sc.nextLine();
sc.close();
Sim[] result = transferCircle(sim, circle1, circle2);
for (int i = 0; i < result.length; i++) {
System.out.println(result[i].getSimId() + " " + result[i].getCustomerName() + " " +
result[i].getCircle() + " " + result[i].getRatePerSecond());
}
}
public static Sim[] transferCircle(Sim[] sim, String circle1, String circle2) {
Sim[] refined = new Sim[0];
for (int i = 0; i < refined[j + 1].getRatePerSecond()) {
Sim temp = refined[j];
refined[j] = refined[j + 1];
refined[j + 1] = temp;
}
}
}
return refined;
}
}
class Sim {
int simId;
String customerName;
double balance;
double ratePerSecond;
String circle;
public int getSimId() {
return simId;
}
public String getCustomerName() {
return customerName;
}
TCS IPA QUESTION ANSWER
Java Question 10
Create a Class Inventory with below attributes:
inventoryId - String
maximumQuantity - int
currentQuantity - int
threshold - int
Write getters, setters and parameterized constructor as required. Create class Solution with main method.
Implement static method - replenish in Solution class. This method will take an int parameter named limit
along with the other parameter as array of Inventory objects.
The method will return array of Inventory where the threshold attribute is less than or equal to the int
parameter passed.
This method should be called from main method and display the id of returned objects along with Filling
status.
if the threshold is greater than or equal to 75 then it should print "Critical Filling" as Filling Status. If the
threshold is between 74 to 50 then Filling status should be "Moderate Filling", else should be "Non-Critical
Filling" .
Before calling this method(replenish) in the main method, use Scanner object to read values for four
Inventory objects referring the attributes in the above sequence.
then, read the value for limit parameter.
Next call the method replenish and display the result.
Input:
1
100
50
40
2
100
50
50
3
100
40
45
4
100
80
25
45
Output:
1 Non-Critical Filling
3 Non-Critical Filling
4 Non-Critical Filling
TCS IPA QUESTION ANSWER
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Inv[] arr = new Inv[4];
for (int i = 0; i < 4; i++) {
String a = sc.nextLine();
int b = sc.nextInt();
sc.nextLine();
int c = sc.nextInt();
sc.nextLine();
int d = sc.nextInt();
sc.nextLine();
arr[i] = new Inv(a, b, c, d);
}
int limit = sc.nextInt();
Inv[] ans1 = find(arr, limit);
for (Inv a: ans1) {
if (a.hold >= 75) {
System.out.println(a.id + " Critical Filling");
} else if (a.hold >= 50 && a.hold < arr.length; i++) {
if (arr[i].hold <= n) {
ans = Arrays.copyOf(ans, ans.length + 1);
ans[ans.length - 1] = arr[i];
}
}
return ans;
}
}
class Inv {
String id;
int max;
int curr;
int hold;
public Inv(String id, int max, int curr, int hold) {
this.id = id;
this.max = max;
this.curr = curr;
this.hold = hold;
}
}
TCS IPA QUESTION ANSWER
Java - Question 12
Create a class Bill with below attributes:
billNo- int
name - String
typeOfConnection - String
billAmount - double
status – boolean
where billNo is the bill number, name is the name of the customer, typeOfConnection is the type of the
connection (prepaid, postpaid), billAmount is the bill amount and status is whether the bill is paid or not (if
paid then value is TRUE else value is FALSE).
The above attributes should be private, write getters, setters and parameterized constructor as required.
This method will take an array of Bill objects and a boolean parameter as parameters.
The method will return bill object array in ascending order of their bill number from the array of Bill objects
whose bill Amount is maximum in the array with the status attribute that matches with the input parameter.
If no Bill with the given status is present in the array of Bill objects, then the method should return null.
getCountWithTypeOfConnection method:
This method will take two input parameters - array of Bill objects and string parameter ( for type of
connection).
The method will return the count of bills from array of bill objects for the given type of connection.
If no bill with the given type of connection is present in the array of bill objects, then the method should
return 0.
Note :
The above mentioned static methods should be called from the main method.
For findBillWithMaxBillAmountBasedOnStatus method - The main method should print the billNo followed
by # and name from the returned Bill object array if the returned value is not null.
If the returned value is null then it should print "There are no bill with the given status".
For getCountWithTypeOfConnection method - The main method should print the count of bills as it is, if the
returned value is greater than 0, otherwise it should print "There are no bills with given type of connection".
Before calling these static methods in main, use Scanner to read the number of object and objects to read the
TCS IPA QUESTION ANSWER
values of Bill objects referring attributes in the above mentioned attribute sequence.
4
111
Aman Mittal
Prepaid
914.25
true
222
Rekha Kumar
Prepaid
1425.75
false
333
Samyra Gupta
Prepaid
1305.00
true
444
Mohit Saxena
Postpaid
1300.50
false
false
Prepaid
Output:
222#Rekha Kumar
3
import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
Bill[] arr = new Bill[num];
for (int i = 0; i < arr.length; i++) {
int a = sc.nextInt();
sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
double d = sc.nextDouble();
boolean e = sc.nextBoolean();
sc.nextLine();
arr[i] = new Bill(a, b, c, d, e);
}
TCS IPA QUESTION ANSWER
ans[j] = x;
break;
}
}
}
if (ans.length > 0) {
double x = 0;
Bill[] temp = new Bill[0];
for (int i = 0; i < ans.length; i++) {
if (ans[i].getamount() >= x) {
x = ans[i].getamount();
temp = Arrays.copyOf(temp, temp.length + 1);
temp[temp.length - 1] = ans[i];
}
}
return temp;
}
return null;
}
}
class Bill {
private int id;
private String name, type;
private double amount;
private boolean status;
public int getid() {
return id;
}
public String getname() {
return name;
}
public String gettype() {
return type;
}
public double getamount() {
return amount;
}
public boolean getstatus() {
return status;
}
public Bill(int id, String name, String type, double amount, boolean status) {
this.id = id;
this.name = name;
this.type = type;
this.amount = amount;
this.status = status;
}
}