
In this post, we will try to give a solution to an important problem of Capgemini ADAPT 2022. The solution to the Problem is – StackException Problem Solution using Java.
However, the solutions are provided for learning purposes only. Candidates must submit their own code during attending the Sprints.
Table of Contents
- StackException Problem Description – Capgemini ADAPT:
- StackException Problem Solution:
- Top Companies + Batchwise Hiring Drive:
- To Stay Up-to-date, Follow us on Social Media:
- ADAPT Different Coding Solutions:
- Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):
- Capgemini ADAPT Sprint 2 (Bus Reservation System):
- ADAPT Sprint 3 Solutions – Capgemini (Toy Rental A):
- Online Shopping A Solutions Using Java:
StackException Problem Description – Capgemini ADAPT:
Create a class UserStack, the class should have an integer array of size 10 declared within it.
The class should have the following methods:
- push(int data) to add the data to the array, if the array is full the method should throw FullStackException and pass the relevant message to the constructor.
- pop() which removes the last int from the array and returns the same, if the array is empty the method should throw EmptyStackException and pass the relevant message to the constructor.
- display() which displays the contents of the array and if the array is empty the method should throw EmptyStackException and pass the relevant message to the constructor.
StackException Problem Solution:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Source {
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner (System.in);
UserStack us = new UserStack();
int c = sc.nextInt();
try{
if(c==1)
{
while (sc.hasNext()){
int data = sc.nextInt();
us.push(data);
}
}
else if(c == 2){
while(sc.hasNext()){
int data1 = sc.nextInt();
us.push(data1);
}
us.diplay();
for(int i = 0; i < 10; i++)
us.pop();
}
}catch(FullStackException e){
System.out.print(e.getMessage());
}
catch(EmptyStackException e){
System.out.println(e.getMessage());
}
}
}
class UserStack{
public UserStack(){};
int aray1[] = new int[10];
public static int index = 0;
public void push(int data) throws FullStackException{
if(index==9)
throw new FullStackException(“Stack overflow”);
array1[index] = data;
index++;
}
public int pop() throws EmptyStackException
{
if(index == 0)
throw new EmptyStackException(“Stack empty”);
return array1[–index];
}
public void display(){
for(int i = 0; i < index; i++)
System.out.println(array1[i]);
}
}
class EmptyStackException extends Exception{
public EmptyStackException(String message){
super(message);
}
}
class FullStackException extends Exception{
public FullStackException(String msg){
super(msg);
}
}
Top Companies + Batchwise Hiring Drive:
TOP COMPANIES HIRING DRIVE | BATCHWISE HIRING DRIVES |
1. TCS OFF-CAMPUS DRIVES | 1. 2018 BATCH |
2. INFOSYS OFF-CAMPUS DRIVES | 2. 2019 BATCH |
3. COGNIZANT OFF-CAMPUS DRIVES | 3. 2020 BATCH |
4. WIPRO OFF-CAMPUS DRIVES | 4. 2021 BATCH |
5. CAPGEMINI OFF-CAMPUS DRIVES | 5. 2022 BATCH |
To Stay Up-to-date, Follow us on Social Media:
1. Join our Telegram Channel: | Click Here |
2. Like us on Facebook: | Click Here |
3. Follow us on Instagram: | Click Here |
4. Follow us on LinkedIn: | Click Here |
5. Follow us on Google News: | Click Here |
ADAPT Different Coding Solutions:
- Largest Array Solution – Click Here
- Batsman & Bowler Solution – Click Here
- Instruments Problem Solution – Click Here
- Check Two Person Are Same – Click Here
- Medicine App ADAPT Solution – Click Here
- String Combination Capgemini ADAPT Solution – Click Here
- Remove” X”inString Problem Solution – Click Here
- Customer and Invoice ADAPT Problem Solution – Click Here
- Book and Author Problem Solution – Click Here
- Highest Feedback Problem Solution – Click Here
- Registered Customer Problem Solution in Java – Click Here
- Product of Digits Problem Solution – Click Here
- Change Using Minimal Coins/Notes Solution in Java – Click Here
- Contact App 2.0 Problem Solutions using Java – Click Here
- Count Character Frequency Problem Solution using Java – Click Here
Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):
- 1. Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerInAscendingOrder Problem Solution
- 2. Capgemini ADAPT Sprint 1 Bus Reservation System – DisplayCustomerByFirstName Problem Solution
- 3. Capgemini ADAPT Sprint 1 Bus Reservation System – SortByCustomerId Problem Solution
- 4. Capgemini ADAPT Sprint 1 Solution Java | LSAByCustomerName Problem Solution
- 5. Capgemini ADAPT Sprint 1 Case Study Solution Java | BSAByCustomerId Problem Solution
Capgemini ADAPT Sprint 2 (Bus Reservation System):
- 1. Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution | HAS-A-Relationship Solution Java
- 2. Capgemini ADAPT Sprint 2 Case Study (Bus Reservation System) Solution OOPs-Para-Constructor Java
- 3. Capgemini ADAPT Sprint 2 Bus Reservation System (CRUDOperations) Problem Solution
ADAPT Sprint 3 Solutions – Capgemini (Toy Rental A):
- 1. Capgemini Adapt 2022 Toy Rental A Solutions for Sprint 3 Learning Outcome 1
- 2. Capgemini Adapt 2022 Toy Rental A Solutions for Sprint 3 Learning Outcome 2
- 3. Capgemini Adapt 2022 Toy Rental A Solutions for Sprint 3 Learning Outcome 3
- 4. Capgemini Adapt 2022 Toy Rental A Solutions for Sprint 3 Learning Outcome 4
Online Shopping A Solutions Using Java:
- 1. Capgemini ADAPT 2022 Online Shopping A – Display Products Solution using JAVA – Click Here
- 2. Capgemini ADAPT 2022 Online Shopping A – Products by Category Solution using JAVA – Click Here
- 3. Capgemini ADAPT 2022 Online Shopping A – Customer Array Solution using JAVA – Click Here
- 4. Capgemini ADAPT 2022 Online Shopping A – Search Customers by Name Solution using JAVA – Click Here
- 5. Capgemini ADAPT 2022 Online Shopping A – Search Customers by City Solution using JAVA – Click Here
- 6. Online Shopping A – Customer & Address Class Solution | Capgemini ADAPT 2022 Solutions – Click Here