0% found this document useful (0 votes)
10 views3 pages

Java Programs with Switch Case Examples

The document outlines five programming tasks involving Java, each requiring the use of switch cases and methods. Tasks include designing a pattern printer, creating an employee management system, performing arithmetic on large numbers, simulating an ATM, and developing a restaurant ordering system. Each task specifies input formats, operations to be performed, and expected outputs, emphasizing the use of object-oriented programming concepts where applicable.

Uploaded by

ankitpcm1114
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Java Programs with Switch Case Examples

The document outlines five programming tasks involving Java, each requiring the use of switch cases and methods. Tasks include designing a pattern printer, creating an employee management system, performing arithmetic on large numbers, simulating an ATM, and developing a restaurant ordering system. Each task specifies input formats, operations to be performed, and expected outputs, emphasizing the use of object-oriented programming concepts where applicable.

Uploaded by

ankitpcm1114
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program [Link] a switch case to print pattern program.

For each pattern you must create a method and call-in switch cases.

Case 1:

Case 2:

Case 3:

Program 2. Design a class Employee Manager Where you have to create two method

1. void person (String name, String designation, double salary, double baseSalary)

2. void manager (String name, String designation, double salary, double baseSalary)

Create a EmployeeDriver class where you will have main method

Create switch case where you have to display 1. add manager 2. add person

After adding both details you have to find the 8 % of manager salary and 3% of person salary

After this if manager salary is greater than person salary then add manager salary in person salary

And find the 19% of person salary.

In switch case case 3. is to display updated salary of person and display all details

In switch case case 4. is to display updated salary of manager and display all details.

Note: if you will use oops concept that will be advantage or by simple methods is also ok.
Program 3. In this problem, you have to add and multiply huge numbers! These numbers are so big
that you can't contain them in any ordinary data types like a long integer.

Input Format

There will be two lines containing two numbers a and b.


Constraints
a and b are non-negative integers and can have maximum digits.
Output Format
Output two lines. The first line should contain a + b and the second line should contain a*b. Don't
print any leading zeros.
Sample Input
12345
45
Sample Output
12390
555525

Note: from output you must remove all even number and zeros so here your final
output will be:
139
55555

Program 4:
Creating a Java scenario for an ATM (Automated Teller Machine) involves simulating
common ATM actions, such as checking an account balance, making deposits, and
withdrawing money. Here's a simplified Java program using methods to represent an ATM
scenario:

Create a switch case :


[Link] your card with your pin code
[Link]
[Link]
[Link]
[Link] Current balance

Note: After withdrawing money, please update the balance.

This Java program simulates an ATM scenario. Users can check their balance, make
deposits, and withdraw money. The program runs in a loop until the user chooses to exit. It
demonstrates the use of methods for encapsulating ATM actions and provides a simple menu
system for user interaction
Program 5:
Certainly! Let's create a scenario for a simple restaurant ordering system using Java
methods and a switch-case statement. In this scenario, a customer can choose items from a
menu, place their order, and calculate the total bill. Here's the Java code for this restaurant
scenario:

1. add menu details

[Link] menu details:


a. Burger 25 rupees
b. Pizza 150 rupees
c. Salad 10 rupees
d. Chicken biryani 150 rupees
e. Chicken chilli 60 rupees
f. Veg Thali 100 rupees
3. Please order:
You can order a number of items.
4. My order details can be displayed on your console. With final price

Note: above scenario you have to create with java methods:

Common questions

Powered by AI

Switch-case statements enhance the functionality of a simple restaurant ordering system by allowing users to interact with a menu-driven interface where they can view menu details, place orders, and see order details. Each switch-case represents a menu operation, enabling efficient categorization of tasks, reducing complexity, and providing a clear structure for handling user choices .

Encapsulation in the ATM scenario program design allows for each ATM action, such as checking a balance or withdrawing money, to be contained within its own method, thus protecting the integrity of user interactions and data. By restricting direct access to the operations outside of the methods, encapsulation enhances security and modularity, facilitating easier maintenance and potential scalability .

When designing a switch case to print pattern programs, it is important to encapsulate each pattern in a separate method to ensure modularity and reusability. In the switch case, each case should call the corresponding method to print the specific pattern. This design helps in maintaining the code and allows for easy updates or additions of new patterns .

In an ATM simulation scenario, the program requires functionality to check account balances, make deposits, and process withdrawals. Using Java methods, each operation—such as entering a card with a PIN, checking balance, depositing, withdrawing, and displaying current balance—must be represented by a separate method for organization and encapsulation. The switch-case mechanism allows users to select actions in a loop until exit is chosen, ensuring user interaction and operation management .

When designing a restaurant ordering system, it is crucial to ensure the user interface is intuitive, with clear instructions for input operations, such as selecting menu items, and concise, readable output displaying the order details and total bill. Error handling is important for invalid inputs. User feedback mechanisms enhance usability and ensure system reliability .

In the Employee Manager program, conditional logic is used to compare the manager's and person's salaries after respective percentage increases. If the manager's salary is greater, it gets added to the person's salary as an adjustment mechanism to ensure that the person receives a compensatory increase. This logic reflects business rules for compensation and fairness in pay adjustments .

The program for adding and multiplying large numbers overcomes computational limitations by using data structures or techniques that can handle arbitrary digit lengths, as traditional data types like long integers are insufficient. By calculating the sum and product line by line and managing digit-by-digit operations, the program avoids overflow issues. The final output excludes even numbers and zeros, ensuring minimal data processing and storage requirements .

The logic behind removing even numbers and zeros from the output in the large number arithmetic program is to ensure the final result is concise and meets specific output criteria. This modification impacts the result by reducing the number of digits in the final output, which enhances readability and meets the challenge's format requirements without losing the mathematical outcome's significance .

Loop structures, when combined with switch-case mechanisms in an ATM program, allow continuous user interaction by repeatedly presenting the menu until an exit condition is met. This interaction design ensures that ATM users can perform multiple transactions in one session without restarting the program, providing a seamless and efficient user experience .

In the Employee Manager program, an 8% increase is calculated on the manager's salary, and a 3% increase is applied to the person's salary. If the manager's salary is greater than the person's salary after these calculations, the manager's salary is added to the person's salary. Then, a final 19% calculation is applied to the person's updated salary. These calculations account for hierarchical salary adjustments and conditional salary bonuses .

You might also like