0% found this document useful (0 votes)
17 views89 pages

Project

Uploaded by

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

Project

Uploaded by

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

Program-1

// To print s
import [Link].*;
class P1
{
public static void main (String args[])
{
Scanner sc=new Scanner ([Link]);
[Link] ("*****");
[Link] ("* ");
[Link] ("*****");
[Link] (" *");
[Link] ("*****");
}
}

Output:
Program-2
// To display the given format
import [Link].*;
class P2
{
public static void main (String agrs[])
{
[Link]("******");
[Link]("* *");
[Link]("* *");
[Link]("* *");
[Link]("******");
}
}

Output:
Program-3

//To do arithmetic calculation


import [Link].*;
class P3
{
public static void main(String agrs[])
{
int a=22,b=5
[Link]("The sum="+(a+b));
[Link]("The difference="+(a-b));
[Link]("The product="+(a*b));
[Link]("The quotient="+(a/b));
[Link]("The remainder="+(a%b));
}
}

Output:
Program-4
// A sample program to illustrate relational operator
import [Link].*;
class P4
{
public static void main (String agrs [])
{
int a=22,b=5;
[Link]("Answer when a<b:"+(a<b));
[Link]("Answer when a>b:"+(a>b));
[Link]("Answer when a<=b:"+(a<=b));
[Link]("Answer when a>=b:"+(a>=b));
[Link]("Answer when a==b:"+(a==b));
[Link]("Answer when a!=b:"+(a!=b));
}

Output :
Program – 5
//A program to find area, perimeter and diagonal of a square
class P5
{
public static void main(String args[])
{
int s, ar=0,p=0;
double d=0.0;
s=25;
ar=s*s;
p=4*s;
d=[Link](2)*s;
[Link]("The Area of square="+ar);
[Link]("The perimeter of square="+p);
[Link]("The diagonal of square="+d);

}
}

Output:
Program-6
// A program to display result
import [Link].*;
class P6
{
public static void main (String args[])
{
Scanner in = new Scanner([Link]);
int a,b,res;
[Link]("Enter tens digit:");
a=[Link]();
[Link]("Enter unit digits:");
b=[Link]();
res=((10*a+b)+(10*b+a))/(a-b);
[Link]("The answer:"+res);
}

Output:
Program-7

//To show the total and average of marks


class P7
{
public static void main (String args[])
{
double a=84;
double b=91;
double c=72;
double d=98;
double e=95;
double tot;
tot=a+b+c+d+e;
double avg;
avg=a+b+c+d+e;
[Link]("tot:"+tot);
[Link]("avg:"+avg);

}
}
Output:
Program-8

import [Link].*;
class P8
{
public static void main (String args[])
{
Scanner sc=new Scanner ([Link]);
double sp,p,cp,dy;
[Link]("Enter the total selling price");
sp=[Link]();
[Link]("Enter the total profit:");
p=[Link]()
cp=sp-p;
dy=cp/15;
[Link]("cost price of one item:"+dy);
}
}
Output:
Program-9
// A program to calculate gross salary and net salary
import [Link].*;
class P9
{
public static void main(String args[])
{
Scanner in=new Scanner([Link]);
int basic;
double da,hra,pf,gp=0,np=0;
String name;
[Link]("Enter the name of the employee");
name=[Link](); [Link]("Enter basic salary");
basic=[Link]();
da=basic*30.0/100.0;
hra=basic*12.5/100.0;
pf=basic*10.0/100.0;
gp=basic+da+hra;
np=gp-pf;
[Link]("Empolyee's Name:"+name);
[Link]("Gross pay:Rs."+gp); [Link]("Net
pay:Rs."+np);
}
}
Output:
Program-10

//To recieve different data


import [Link].*;
class Data
{
public static void main (String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter your class:");
byte c=[Link]();
[Link]("Enter your Roll No:");
short r=[Link]();
[Link]("Enter your age:");
int a=[Link]();
[Link]("Enter your first name:");
String name=[Link](); [Link]("Enter your
address:");
String address=[Link]();
[Link]("Enter your initial:");
char i=[Link]().charAt(0);
[Link]("***************************");
[Link]("Class:"+c); [Link]("Age:"+a);
[Link]("Name:"+name);
[Link]("Address:"+address);
[Link]("initial:"+i); [Link]("Thanking you for
providing data");
}
}

Output:

Program-11
// to input the temperature in farenheit and convert it into celisus
import [Link].*;
class temp
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
double F,C;
[Link]("Enter the temperature in farenheit");
F=[Link]();
C=(F-32)*5/9.0;
[Link]("Enter the value of celisus");
}
}
Output:
Program-12
//To use a formula
import [Link].*;
class Mathematics
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter the value of x1");
int x1=[Link]();
[Link]("Enter the value of x2");
int x2=[Link]();
[Link]("Enter the value y1");
int y1=[Link]();
[Link]("Enter the value of y2");
int y2=[Link]();
double d;
d=[Link]([Link]((x2-x1),2));
[Link]((y2-y1),2);
}
}
Output:

Program-13
//To display my answer
class P13
{
public static void main(String args[])
{
double m=[Link](8.0); [Link]("Result of rint
value="+m);
double n=[Link](8.49);
[Link]("Result of rint value="+n);
double k=[Link](8.50);
[Link]("Result of rint value="+k);
double c=[Link](8.51);
[Link]("Result of rint value="+c);
double t=[Link](-8.0);
[Link]("Result of rint value="+t);
double d=[Link](-8.49);
[Link]("Result of rint value="+d);
double s=[Link](-8.50); [Link]("Result of rint
value="+s);
double a=[Link](-8.51);
[Link]("Result of rint value="+a);
}
}

Output:
Program-14
//WAP to display the following
import [Link].*;
class P16
{
public static void main(String agrs[])
{
[Link]("**********************************");
[Link]("\t\t\t ");
[Link]("\t\tABC Restaurant");
[Link]("Date:14 April 2024\\tbill no:2403");
[Link]("SNO. \tItem\t\tRate\t\tQty\tTotal");
[Link]("1.\tBiriyani\t200\t\t1\t200");
[Link]("2.\tFried rice\t180\t\t2\t360");
[Link]("3.\tPopcorn chicken\t150\t\t2\t300");
[Link]("4.\tMojito\t\t80\t\t2\t160");
[Link]("\t\t\t\t\tTotal 1020");

[Link]("____________________________________");
[Link]("Thank you! Visit again!");

[Link]("***********************************");
}
}

Output:
Program-15
// To print chittu for five times
import [Link].*;
class chittu
{
public static void main (String args[])
{
for(int i=1;i<=5;i=i+1)
[Link]("chittu");

Output:
Program-16
//To arrange in ascending order
import [Link].*;
public class AscendingOrder {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Input three numbers


[Link]("Enter first number: ");
int num1 = [Link]();
[Link]("Enter second number: ");
int num2 = [Link]();
[Link]("Enter third number: ");
int num3 = [Link]();
// Print numbers in ascending order
if (num1 <= num2 && num1 <= num3) {
[Link](num1 + " ");
if (num2 <= num3) {
[Link](num2 + " " + num3);
}
else {
[Link](num3 + " " + num2);
}
{
else if (num2 <= num1 && num2 <= num3) {
[Link](num2 + " ");
if (num1 <= num3) {
[Link](num1 + " " +num3);
}
else {
[Link](num3 + " " + num1);
}
}
else {
[Link](num3 + " ");
if (num1 <= num2) {
[Link](num1 + " " + num2);
}
else {
[Link](num2 + " " + num1);
}
}
[Link]();
}
}
Output:
Program-17
//To arrange in series
import [Link].*;
class series
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int n=[Link]();
int a=0;
for(int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
[Link]("j");
[Link]();
}
}

Output:
Program-18
//sample program
Import [Link].*;
class sample
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
double sp,p,cp,dy; [Link]("Enter the total selling
price");
sp=[Link]();
[Link]("Enter the total profit");
p=[Link]();
cp=sp-p;
dy=cp/15;
[Link]("Cost price of one item:"+dy);
}
Output:
Program-19
// To display the numbers
public class Print1010 {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
[Link]("1010");
}
}
}

Output:
Program-20
import [Link];
class choice
{
public class IceCreamOrChocolate {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner([Link]);

// Ask the user for their choice


[Link]("Do you want ice cream or chocolate? (Enter
'ice cream' or 'chocolate'):");
String choice = [Link]().toLowerCase(); // Read the
user's input and convert it to lowercase

// Check the user's choice and display the result


if ([Link]("ice cream")) {
[Link]("You chose ice cream! Enjoy your treat!");
} else if ([Link]("chocolate")) {
[Link]("You chose chocolate! Enjoy your treat!");
} else {
[Link]("Invalid choice! Please enter 'ice cream' or
'chocolate'.");
}

// Close the scanner


[Link]();
}
}

Output:
Program-21
//To find the cosine of an angle
public class Cosine_value
{
public static void main(String args[])
{
double deg=45;
double radians=[Link](deg);
double cosine=[Link](radians);
[Link]("Value of Cos 45 degree="+(float)cosine);
}
}

Output:
Program-22
// a program to find the value of an expression
import [Link].*;
public class expression
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int a,b,c;
double d;
[Link]("Enter values of a,b and c");
a=[Link]();
b=[Link]();
c=[Link]();
d=1/[Link](a,2)+1/[Link](b,3)+1/[Link](c,4);
[Link]("Value of the expression="+d);
}
}
Output:
Program -23
// a program to dispaly the pattern
public class Pattern
{
public static void main(String args[])
{
int a,b;
[Link]("The Pattern:");
for(a=1;a<=a;b++)
{
for(b=1;b<=a;b++)
[Link](b+"");
[Link]();
}
}
}
Output:
Program-24
// A program to display the pattern
public class JP
{
public static void main(String args[])
{
int i,j;
[Link]("The Pattern:");
for (i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
[Link](j+" ");
[Link]();
}
}
}
Output:
Program – 25
//to display the pattern
public class example
{
public static void main(String args[])
{
int i,j;
[Link]("The Pattern:");
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
[Link](j+"");
[Link]();
}
}
}
Output:
Program-26
// program to display value of cosine for aa angle
public class rad
{
public static void main(String args[])
{
int a=60;
double rad=(22.0/(7.0*180))*a;
double d=[Link](rad);
[Link]("Value of Cos 60 degree is"+(float)d);
}
}

Output:
Program-27
// a program using do-while
import [Link].*;
class Digits
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int d,n;
[Link]("Enter a number");
n=[Link]();
//Displaying even/odd digits starting from unit place
do
{
d=n%10;
if(d%2==0)
[Link](d+":an even digit");
else
[Link](d+":an odd digit");
n=n/10;
}
while(n>0);
}
}
Output:
Program-28
//A program to display whether the number is positive of negative
import [Link].*;
class Number
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int n;
do
{
[Link]("Enter a number and zero to terminate:");
n=[Link]();
if(n==0)
break;
if(n>0)
[Link](n+":a positive number");
else
[Link](n+":a negative number");
}
while(true);
[Link]("Program terminates!");
}
}
Output:

Program-29
import [Link];

public class Patient {


// Attributes
String name;
int age;
String disease;
String contactNumber;

// Constructor
public Patient(String name, int age, String disease, String
contactNumber) {
[Link] = name;
[Link] = age;
[Link] = disease;
[Link] = contactNumber;
}

// Method to check eligibility for 50% discount


public boolean isEligibleForDiscount() {
return [Link] > 50;
}

// Method to display patient details


public void displayPatientDetails() {
[Link]("Patient Name: " + name);
[Link]("Age: " + age);
[Link]("Disease: " + disease);
[Link]("Contact Number: " + contactNumber);

if (isEligibleForDiscount()) {
[Link]("Eligible for 50% Medical Insurance
Discount\n");
} else {
[Link]("Not eligible for 50% Medical Insurance
Discount\n");
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner([Link]);

// Collecting patient details


[Link]("Enter Patient Name: ");
String name = [Link]();

[Link]("Enter Patient Age: ");


int age = [Link]();
[Link](); // Consume the newline character

[Link]("Enter Patient Disease: ");


String disease = [Link]();

[Link]("Enter Patient Contact Number: ");


String contactNumber = [Link]();

// Create a Patient object


Patient patient = new Patient(name, age, disease,
contactNumber);

// Display Patient details and insurance eligibility


[Link]();
}
}

Output:

Program-30
public class DisplayAlphabets

{
public static void main(String[] args)
{
// Displaying uppercase alphabets from A to Z
[Link]("Uppercase Alphabets:");
for (char letter = 'A'; letter <= 'Z'; letter++)
{
[Link](letter + " ");
}

// Displaying lowercase alphabets from a to z


[Link]("\nLowercase Alphabets:");
for (char letter = 'a'; letter <= 'z'; letter++)
{

[Link](letter + " ");


}
}
}

Output:
Program-31
public class p31
{
public static void main(String[] args)
{
// Loop to display the number 23456 four times
for (int i = 0; i < 4; i++) {
[Link](23456);
}
}
}

Output:

Program-32
import [Link].*;

public class HotelDetails


{
public static void main(String[] args)
{
// Create a scanner object to read input
Scanner scanner = new Scanner([Link]);

// Collecting details about the hotel


[Link]("Enter the hotel name: ");
String hotelName = [Link]();

[Link]("Enter the hotel address: ");


String hotelAddress = [Link]();

[Link]("Enter the number of rooms: ");


int numberOfRooms = [Link]();
[Link](); // To consume the remaining newline

[Link]("Enter the type of hotel (e.g., 5-star, budget,


resort): ");
String hotelType = [Link]();

// Displaying the collected hotel details


[Link]("\nHotel Details:");
[Link]("Hotel Name: " + hotelName);
[Link]("Hotel Address: " + hotelAddress)
[Link]("Number of Rooms: " + numberOfRooms);
[Link]("Hotel Type: " + hotelType);

// Close the scanner object


[Link]();
}
}

Output:
Program-33
import [Link];

public class CoffeePromotion


{
public static void main(String[] args)
{
// Create a scanner object to read input
Scanner scanner = new Scanner([Link]);

// Displaying promotion message


[Link]("Welcome to the Coffee Shop!");
[Link]("We have a special promotion just for you!");

// Collecting details about the coffee


[Link]("Enter the coffee name: ");
String coffeeName = [Link]();

[Link]("Enter the price of the coffee: ");


double coffeePrice = [Link]();

// Displaying coffee promotion details


[Link]("\n-------------------------");
[Link]("Promotion for " + coffeeName + "!");
[Link]("Original Price: $" + coffeePrice);
// Calculating and displaying discounted price (let's assume a
20% discount)
double discount = 0.20;
double discountedPrice = coffeePrice - (coffeePrice * discount);
[Link]("Special Offer: Get 20% OFF!");
[Link]("Discounted Price: $" + discountedPrice);

// Additional promotional message


[Link]("\nHurry, this offer is available for a limited
time only!");
[Link]("Visit us today and enjoy the perfect cup of "
+ coffeeName + "!");

// Close the scanner object


[Link]();
}
}
Output:

Program -34
import [Link];
import [Link];

public class FourCupsGame


{
public static void main(String[] args)
{
// Create scanner and random objects
Scanner scanner = new Scanner([Link]);
Random random = new Random();

// Shuffle cups and randomly hide the ball


int ballPosition = [Link](4); // Ball can be under any cup
(0 to 3)

// Greet the player


[Link]("Welcome to the Four Cups Game!");
[Link]("There are 4 cups. One of them is hiding the
ball.");
[Link]("Can you guess which cup the ball is
under?");

// Show the cups


[Link]("\nChoose a cup to guess (1-4): ");
int playerGuess = [Link]() - 1; // Convert to 0-indexed
// Check if the player guessed correctly
if (playerGuess == ballPosition)
{
[Link]("\nCongratulations! You guessed the right
cup!");
}
else {
[Link]("\nSorry, the ball was under cup " +
(ballPosition + 1) + ".");
}

// Close the scanner object


[Link]();
}
}

Output:

Program – 35
import [Link];

public class PoliceComplaint


{
public static void main(String[] args)
{
// Create scanner object for user input
Scanner scanner = new Scanner([Link]);

// Collecting the complainant's details


[Link]("Enter your full name:");
String complainantName = [Link]();

[Link]("Enter your contact number:");


String contactNumber = [Link]();

// Collecting details about the kidnapped person (sister)


[Link]("Enter your sister's full name:");
String sisterName = [Link]();

[Link]("Enter your sister's age:");


int sisterAge = [Link]();
[Link](); // Consume newline left over after integer
input
[Link]("Enter the location where your sister was
kidnapped:");
String kidnappingLocation = [Link]();

[Link]("Enter the date and time of the kidnapping


(e.g., 2025-02-04 18:30):");
String kidnappingDateTime = [Link]();

// Collecting other relevant details


[Link]("Do you have any suspects? (yes/no):");
String hasSuspects = [Link]();

// Print the complaint summary


[Link]("\n-- Police Complaint Summary --");
[Link]("Complainant Name: " + complainantName);
[Link]("Contact Number: " + contactNumber);
[Link]("Sister's Name: " + sisterName);
[Link]("Sister's Age: " + sisterAge);
[Link]("Kidnapping Location: " +
kidnappingLocation);
[Link]("Kidnapping Date & Time: " +
kidnappingDateTime);
[Link]("Suspects: " +
([Link]("yes") ? "Yes, there are suspects." :
"No suspects mentioned."));

// Closing statement
[Link]("\nThe complaint has been successfully filed.
The police will take immediate action.");

// Close the scanner object


[Link]();
}
}

Output:

Program-36
//To print a Robot Face
public class RobotFace {
public static void main(String[] args) {
// Display the robot face using asterisks
[Link](" ***** ");
[Link](" * * ");
[Link](" * O O * ");
[Link](" * ^ * ");
[Link](" * '-' * ");
[Link](" * * ");
[Link](" ***** ");
}
}

Output:

Program-37
import [Link];

public class TrafficSignal


{
public static void main(String[] args)
{
// Create a scanner object to read user input
Scanner scanner = new Scanner([Link]);

// Prompt user to choose a signal


[Link]("Choose a traffic signal:");
[Link]("1. Red");
[Link]("2. Yellow");
[Link]("3. Green");
[Link]("Enter your choice (1, 2, or 3): ");

int choice = [Link]();

// Display corresponding message based on the signal choice


switch (choice) {
case 1:
[Link]("Red signal: Stop your vehicle.");
break;

case 2:
[Link]("Yellow signal: Prepare to stop.");
break;
case 3:
[Link]("Green signal: You can go now.");
break;
default:
[Link]("Invalid choice. Please select a valid
option (1, 2, or 3).");
break;
}

// Close the scanner object


[Link]();
}
}

Output:

Program-38
import [Link];

public class FavoriteSubject


{
public static void main(String[] args)
{
// Create a Scanner object to read input
Scanner scanner = new Scanner([Link]);

// Display a list of subjects to choose from


[Link]("Choose your favorite subject:");
[Link]("1. Math");
[Link]("2. Science");
[Link]("3. English");
[Link]("4. History");
[Link]("5. Computer Science");

// Prompt the user to enter their choice


[Link]("Enter the number corresponding to your
choice: ");
int choice = [Link]();

// Display the chosen subject based on the user's input


switch (choice) {
case 1:
[Link]("Your favorite subject is Math!");
break;
case 2:
[Link]("Your favorite subject is Science!");
break;
case 3:
[Link]("Your favorite subject is English!");
break;
case 4:
[Link]("Your favorite subject is History!");
break;
case 5:
[Link]("Your favorite subject is Computer
Science!");
break;
default:
[Link]("Invalid choice. Please choose a number
between 1 and 5.");
}

// Close the scanner object


[Link]();
}
}
Output:
Program-39
// to find the circumference a\of a circle
public class CircleCircumference
{
public static void main(String[] args)
{
// Given radius is the square root of 44
double radius = [Link](44);

// Calculate the circumference using the formula: C = 2 * π * r


double circumference = 2 * [Link] * radius;

// Display the result


[Link]("The radius of the circle is: " + radius);
[Link]("The circumference of the circle is: " +
circumference);
}
}

Output:

Program-40
// to choose a fruit
import [Link];

public class FruitChooser


{
public static void main(String[] args)
{
// Create a scanner object for user input
Scanner scanner = new Scanner([Link]);

// Display the choices to the user


[Link]("Choose a fruit:");
[Link]("1. Apple");
[Link]("2. Banana");
[Link]("3. Cherry");

// Get the user's choice


[Link]("Enter the number corresponding to your
choice: ");
int choice = [Link]();

// Display the chosen fruit


switch (choice) {
case 1:
[Link]("You chose Apple!");
break;
case 2:
[Link]("You chose Banana!");
break;
case 3:
[Link]("You chose Cherry!");
break;
default:
[Link]("Invalid choice. Please choose 1, 2, or
3.");
break;
}

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-41
//To choose vote
import [Link];
public class VotingSystem
{

public static void main(String[] args)


{
// Declare and initialize vote counters for two candidates
int candidate1Votes = 0;
int candidate2Votes = 0;

// Create a Scanner object to read input from the user


Scanner scanner = new Scanner([Link]);

// Display the candidates


[Link]("Welcome to the voting system!");
[Link]("Candidates: ");
[Link]("1. Candidate A");
[Link]("2. Candidate B");

// Ask the user to vote


[Link]("Please enter your vote (1 for Candidate A, 2
for Candidate B): ");
int vote = [Link]();

// Record the vote


if (vote == 1) {
candidate1Votes++;
[Link]("You voted for Candidate A!");
} else if (vote == 2) {
candidate2Votes++;
[Link]("You voted for Candidate B!");
} else {
[Link]("Invalid vote!");
}

// Display the results [Link]("\nVote Results:");


[Link]("Candidate A: " + candidate1Votes + " votes");
[Link]("Candidate B: " + candidate2Votes + " votes");

// Close the scanner to avoid resource leak


[Link]();
}
}

Output:
Program-42
// a program on accounts of a chat shop
import [Link];

public class PaniPuriShop


{

public static void main(String[] args)


{
// Prices of items
final double PANI_PURI_PRICE = 50.0; // Price of one plate of
Pani Puri
final double BHEL_PRICE = 30.0; // Price of one plate of Bhel
final double PAV_BHAJI_PRICE = 80.0; // Price of one plate of
Pav Bhaji

// Initialize variables to track sales


int paniPuriSold = 0;
int bhelSold = 0;
int pavBhajiSold = 0;
double totalAmount = 0.0;

// Create Scanner object for user input


Scanner scanner = new Scanner([Link]);

while (true) {
// Display menu
[Link]("\nWelcome to Pani Puri Shop!");
[Link]("Menu:");
[Link]("1. Pani Puri - Rs. 50");
[Link]("2. Bhel - Rs. 30");
[Link]("3. Pav Bhaji - Rs. 80");
[Link]("4. View Total Sales");
[Link]("5. Exit");
[Link]("Please enter your choice (1-5): ");

int choice = [Link]();

switch (choice) {
case 1:
// Selling Pani Puri
[Link]("Enter the number of Pani Puri plates
sold: ");
int paniPuriCount = [Link]();
paniPuriSold += paniPuriCount;
totalAmount += paniPuriCount * PANI_PURI_PRICE;
[Link]("Sold " + paniPuriCount + " plates of
Pani Puri.");
break;

case 2:
// Selling Bhel
[Link]("Enter the number of Bhel plates sold:
");
int bhelCount = [Link]();
bhelSold += bhelCount;
totalAmount += bhelCount * BHEL_PRICE;
[Link]("Sold " + bhelCount + " plates of
Bhel.");
break;

case 3:
// Selling Pav Bhaji
[Link]("Enter the number of Pav Bhaji plates
sold: ");
int pavBhajiCount = [Link]();
pavBhajiSold += pavBhajiCount;
totalAmount += pavBhajiCount * PAV_BHAJI_PRICE;
[Link]("Sold " + pavBhajiCount + " plates of
Pav Bhaji.");
break;

case 4:
// Display total sales
[Link]("\nTotal Sales:");
[Link]("Pani Puri Sold: " + paniPuriSold + "
plates");
[Link]("Bhel Sold: " + bhelSold + " plates");
[Link]("Pav Bhaji Sold: " + pavBhajiSold + "
plates");
[Link]("Total Amount Collected: Rs. " +
totalAmount);
break;

case 5:
// Exit the program
[Link]("Exiting the system. Thank you!");
[Link]();
return;

default:
[Link]("Invalid choice! Please choose a valid
option.");
}
}
}
}

Output:
Program-43
// to calculate the income tax
import [Link];

public class IncomeTaxCalculator


{

public static void main(String[] args)


{
// Create a Scanner object to read input
Scanner scanner = new Scanner([Link]);

// Input: Monthly Salary


[Link]("Enter your monthly salary: ");
double salary = [Link]();

// Calculate the annual salary


double annualSalary = salary * 12;

// Initialize tax variable


double tax = 0.0;

// Calculate tax based on annual salary (simple tax slabs)


if (annualSalary <= 250000) {
tax = 0.0; // No tax for income up to 2.5 Lakh
} else if (annualSalary <= 500000) {
tax = (annualSalary - 250000) * 0.05; // 5% tax for income
between 2.5L and 5L
} else if (annualSalary <= 1000000) {
tax = (annualSalary - 500000) * 0.1 + 12500; // 10% tax for
income between 5L and 10L
} else {
tax = (annualSalary - 1000000) * 0.2 + 12500 + 50000; // 20%
tax for income above 10L
}

// Output the calculated tax


[Link]("\nYour annual salary: Rs. " + annualSalary);
[Link]("Your total tax liability: Rs. " + tax);

// Close the scanner


[Link]();
}
}
Output:

Program-44
// to calculate monthly expenditure
import [Link];
public class MonthlyExpenditureCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Prompt for the expenditures


[Link]("Enter monthly expenditure for groceries: ");
double groceries = [Link]();

[Link]("Enter monthly expenditure for rent: ");


double rent = [Link]();

[Link]("Enter monthly expenditure for utilities: ");


double utilities = [Link]();

[Link]("Enter monthly expenditure for transportation:


");
double transportation = [Link]();

[Link]("Enter monthly expenditure for entertainment:


");
double entertainment = [Link]();

// Calculate total expenditure


double totalExpenditure = groceries + rent + utilities +
transportation + entertainment;
// Display the total expenditure
[Link]("\nTotal Monthly Expenditure: $" +
totalExpenditure);

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-45
import [Link];

public class DegreeSelector


{
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);

[Link]("Welcome to the Degree Selector!");


[Link]("Answer the following questions to help
choose a good degree for you.");

// Question 1: Interest in numbers


[Link]("Do you enjoy working with numbers?
(yes/no): ");
String numbersInterest = [Link]();

// Question 2: Interest in helping people


[Link]("Do you enjoy helping people? (yes/no): ");
String peopleInterest = [Link]();

// Question 3: Interest in technology


[Link]("Are you interested in technology and
computers? (yes/no): ");
String techInterest = [Link]();

// Question 4: Interest in creativity


[Link]("Do you like to be creative and design things?
(yes/no): ");
String creativeInterest = [Link]();

// Suggest degree based on answers


[Link]("\nBased on your answers, we suggest the
following degrees:");

if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Healthcare or Nursing could
be a great fit for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Computer Science or
Engineering could be a great fit for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Psychology or Education
could be a good choice for you!");
} else if ([Link]("yes") &&
[Link]("yes")) {
[Link]("- A degree in Graphic Design, Digital
Media, or Web Development could be a great choice for you!");
} else {
[Link]("- Based on your answers, you might want
to consider exploring other options.");
}

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-46
public class TriangleAreaCalculator {
public static void main(String[] args) {
// Given sides of the right triangle
double side1 = 4.0; // base (in cm)
double side2 = 4.0; // height (in cm)

// Calculate the area of the right triangle


double area = 0.5 * side1 * side2;

// Display the result


[Link]("The area of the triangle is: " + area + "
square cm");
}
}

Output:

Program-47
import [Link];

public class SalaryCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Input: Basic Salary, Bonus, and Deductions


[Link]("Enter basic salary of the employee: ");
double basicSalary = [Link]();

[Link]("Enter bonus amount: ");


double bonus = [Link]();

[Link]("Enter total deductions: ");


double deductions = [Link]();

// Calculate the net salary


double netSalary = basicSalary + bonus - deductions;

// Display the result


[Link]("\nSalary Breakdown:");
[Link]("Basic Salary: $" + basicSalary);
[Link]("Bonus: $" + bonus);
[Link]("Deductions: $" + deductions);
[Link]("Net Salary: $" + netSalary);

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-48
import [Link];

public class MonthChooser {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

// Ask the user to choose a month number (1 to 12)


[Link]("Enter a month number (1 to 12): ");
int monthNumber = [Link]();

// Display the month based on the input


switch (monthNumber) {
case 1:
[Link]("You chose January.");
break;
case 2:
[Link]("You chose February.");
break;
case 3:
[Link]("You chose March.");
break;
case 4:
[Link]("You chose April.");
break;
case 5:
[Link]("You chose May.");
break;
case 6:
[Link]("You chose June.");
break;
case 7:
[Link]("You chose July.");
break;
case 8:
[Link]("You chose August.");
break;
case 9:
[Link]("You chose September.");
break;
case 10:
[Link]("You chose October.");
break;
case 11:
[Link]("You chose November.");
break;
case 12:
[Link]("You chose December.");
break;
default:
[Link]("Invalid month number! Please enter a
number between 1 and 12.");
}

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-49
// to input the details of a student
import [Link];

public class StudentFees


{
public static void main(String[] args)
{
Scanner scanner = new Scanner([Link]);

// Input the details of the student


[Link]("Enter student's name: ");
String name = [Link]();

[Link]("Enter student's grade (1 to 12): ");


int grade = [Link]();

[Link]("Is the student new or returning? (Enter 'new'


or 'returning'): ");
String studentType = [Link]().toLowerCase();

// Declare variables for the fee


double fee;

// Determine the fee based on student type and grade


if ([Link]("new")) {
if (grade >= 1 && grade <= 5) {
fee = 500; // Fee for new student in grades 1-5
} else if (grade >= 6 && grade <= 8) {
fee = 700; // Fee for new student in grades 6-8
} else if (grade >= 9 && grade <= 12) {
fee = 900; // Fee for new student in grades 9-12
}
else {
fee = 0; // Invalid grade
[Link]("Invalid grade entered.");
}
}
else if ([Link]("returning"))
{
if (grade >= 1 && grade <= 5) {
fee = 400; // Fee for returning student in grades 1-5
} else if (grade >= 6 && grade <= 8) {
fee = 600; // Fee for returning student in grades 6-8
} else if (grade >= 9 && grade <= 12) {
fee = 800; // Fee for returning student in grades 9-12
} else {
fee = 0; // Invalid grade
[Link]("Invalid grade entered.");
}
} else {
fee = 0; // Invalid student type
[Link]("Invalid student type entered.");
}

// Display the student's fee


if (fee > 0) {
[Link]("\nStudent Name: " + name);
[Link]("Grade: " + grade);
[Link]("Student Type: " + studentType);
[Link]("Total Fee: $" + fee);
}

// Close the scanner to prevent resource leak


[Link]();
}
}

Output:

Program-50
//to display hand
public class HandWithAsterisks {
public static void main(String[] args) {
// Print the hand using asterisks
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * * * * ");
[Link](" * * * * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
[Link](" * * ");
}
}
Output:

You might also like