Professional Documents
Culture Documents
5 6089131777291453670
5 6089131777291453670
College Admission
import java.util.Scanner;
System.out.println("Applicant name");
String name=sc.nextLine();
System.out.println("Gender");
char gender=sc.next().charAt(0);
}
}
02. Ludo King
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
}
}
03. Sim Card
import java.util.Scanner;
int odd=0,even=0;
long temp=phn,rem=0;
while(temp>0){
rem=temp%10;
if(rem%2==0){
even+=rem;
}
else{
odd+=rem;
}
temp/=10;
}
if(odd>even){
System.out.println("Sum of odd is greater than sum of even");
}
else if (odd<even){
System.out.println("Sum of even is greater than sum of odd");
}
else{
System.out.println("Sum of odd and even are equal");
}
}
}
04. Oxygen Plants
import java.util.Scanner;
import java.util.Formatter;
import java.*;
public class Main {
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
double a=l*b;
double bd=area/10000;
double Tplant=a/bd;
double rem=Tplant%10;
Tplant-=rem;
double oxygen=Tplant*0.9;
String poxygen=String.format("%.02f",oxygen);
String pl=String.format("%.02f",l);
String pb=String.format("%.02f",b);
String pTplant=String.format("%.0f",Tplant);
}
05. Sum of Ten
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
//CustomerDetails
this.customerId=customerId;
this.customerName=customerName;
this.phoneNumber=phoneNumber;
this.city=city;
this.unitConsumed=unitConsumed;
this.costPerUnit=costPerUnit;
//================================================//
import java.util.Scanner;
CustomerDetails c = new
CustomerDetails("Sample","Sample",123456789,"Sample",12.00,13.00);
System.out.println("Enter Customer Id");
c.setCustomerId(sc.nextLine());
System.out.println("Enter Customer Name");
c.setCustomerName(sc.nextLine());
System.out.println("Enter Phone Number");
c.setPhoneNumber(sc.nextLong());
System.out.println("Enter City");
c.setCity(sc.next());
System.out.println("Enter Units Consumed");
c.setUnitConsumed(sc.nextDouble());
System.out.println("Enter Cost per Units");
c.setCostPerUnit(sc.nextDouble());
double amount=c.calculateElectricityBill();
System.out.printf("Amount to be paid is Rs.%.2f",amount);
}
07. Game Card Points
//CardPoints
//======================================================//
import java.util.Scanner;
do{
System.out.println("Enter balance points");
balancePoints = sc.nextInt();
if(balancePoints<=0){
System.out.println("Balance points should be positive");
}
}while(balancePoints<=0);
cp.setCardId(cardId);
cp.setHolderName(holderName);
cp.setBalancePoints(balancePoints);
return cp;
}
public int getPointUsage()
{
Scanner sc = new Scanner(System.in);
int points;
do{
System.out.println("Enter points should be used");
points =sc.nextInt();
if(points<=0){
System.out.println("Points should be positive");
}
}while(points<=0);
return points;
}
import java.util.Scanner;
//=================================================//
public class Hospital {
//============================================================//
import java.util.Scanner;
}
10. Incredible Toys
//====================================================//
import java.util.Scanner;
CustomerDetails cd = new
CustomerDetails(cid,name,phone,email,type,price);
if(cd.validateCustomerId()==false){
System.out.println("Provide a proper Customer Id");
return;
}
System.out.printf("Amount to be paid by the Customer
%.2f\n",cd.calculateDiscount());
}
}
11. PIN Number
import java.util.Scanner;
int n,x,c;
System.out.println("Enter the total number of PIN numbers");
n=sc.nextInt();
if(n>0){
int[] arr=new int[n];
System.out.println("Enter the PIN numbers");
for(int i=0; i<n; i++){
arr[i]=sc.nextInt();
if(arr[i]>0){
x=arr[i];
c=0;
while(x!=0){
x/=10;
++c;
}
if(c<4 || c>4){
System.out.println(arr[i]+" is an invalid PIN number");
System.exit(0);
}}
else{
System.exit(0);
}
}
int flag=0,m=0;
for(int k=0; k<n;k++){
int one = (arr[k]/1000)%10;
int two = (arr[k]/100)%10;
int three =(arr[k]/10)%10;
int four =arr[k]%10;
else{
System.out.println(+n+" is an invalid number");
}
}
}
12. Resort booking
import java.util.Scanner;
public static void CalCost(String name, int period, int child, int day){
int total=((period*1000)+(child*650))*day;
System.out.println(name+" your booking is confirmed and the total cost is
Rs "+total);
String input=sc.next();
String[] str=input.split(":");
String name=str[0];
int adults=Integer.parseInt(str[1]);
int childs=Integer.parseInt(str[2]);
int days=Integer.parseInt(str[3]);
Check(adults,childs,days);
CalCost(name,adults,childs,days);
}
}
13. Find the winner
import java.util.Scanner;
sum[i]=Float.parseFloat(td[1])+Float.parseFloat(td[2])+Float.parseFloat(td[3])+Floa
t.parseFloat(td[4]);
}
}
if(flag){
int winnerIndex=findWinner(sum);
System.out.print(teams[winnerIndex].split(":")[0]+" team wins the
race in");
System.out.printf(" %.2f ",sum[winnerIndex]);
System.out.print("minutes");
}
}else{
System.out.println("Invalid input");
}
}
}
14. Fishing competition
import java.util.Scanner;
public static int Points(int age, int big, int medium, int small, int count){
int total=0;
if(age<18){
System.out.println(age+" is an invalid age");
System.exit(1);
}
else if(count<0){
System.out.println(count+" is an invalid input");
System.exit(1);
}
else if(big<0){
System.out.println(big+" is an invalid input");
System.exit(1);
}
else if(medium<0){
System.out.println(medium+" is an invalid input");
System.exit(1);
}
else if(small<0){
System.out.println(small+" is an invalid input");
}
else{
total=(big*10)+(medium*6)+(small*3);
}
return total;
}
}
}
15. Two arrays game
import java.util.Scanner;
if(Size!=Size2){
System.out.println("Both array size are not same");
System.exit(1);
}
//BoatHouseBooking
int noOfDays;
String foodType;
public BoatHouseBooking(String customerName, String cityName, String
phoneNumber, int noOfPeople, int noOfDays, String foodType){
super(customerName,cityName,phoneNumber,noOfPeople);
this.noOfDays=noOfDays;
this.foodType=foodType;
}
//=============================================//
//BoatRideBooking
public class BoatRideBooking extends Booking{
//================================================//
//Booking
import java.util.*;
public abstract class Booking {
//===============================================//
//UserInterface
import java.util.Scanner;
int choice=Integer.parseInt(sc.nextLine());
int days=0;
if(choice==1){
System.out.println("Enter number of days");
days=Integer.parseInt(sc.nextLine());
System.out.println("Enter food type (Veg/NonVeg)");
String foodType=sc.nextLine();
}
17. Vivek Furnitures - Polymorphism
//Bero
//==========================================//
//=============================================//
//===================================================//
//==============================================//
//===========================================//
import java.util.Scanner;
double TotalPrice=0;
Discount d=new Discount();
Scanner sc = new Scanner(System.in);
if(btype.equals("Wooden Bero")){
System.out.println("Enter Wood Type");
String wType=sc.nextLine();
wb.calculatePrice();
TotalPrice= wb.getPrice()-d.calculateDiscount(wb);
sb.calculatePrice();
TotalPrice=sb.getPrice()-d.calculateDiscount(sb);
}
}
}
18. Departmental Store – Interface
double calculateBonusPoints();
//===================================//
//=============================================//
double deliveryCharge();
}
//==============================================//
import java.util.Scanner;
int busFee=0;
if(distance>30 && distance <=40){
busFee=28000;
}
else if (distance>20 && distance<=30){
busFee=20000;
}
else if(distance >10 && distance <= 20){
busFee=12000;
}
else{
busFee=6000;
}
return (collegeFee+busFee);
}
}
//===============================================//
public abstract class Student {
//===========================================//
import java.util.Scanner;
if(category.equals("DayScholar")){
System.out.println("Enter Bus number");
int busNumber=Integer.parseInt(sc.nextLine());
System.out.println("Enter the distance");
int distance=Integer.parseInt(sc.nextLine());
Hosteller hosteller=new
Hosteller(studentId,name,deptName,gender,category,collegeFee,roomNumber,blockName,r
oomType);
System.out.println("Total College fee is
"+hosteller.calculateTotalFee());
}
//======================================//
//================================================//
//=================================================//
//=====================================================//
import java.util.Scanner;
if(endowmentType.equalsIgnoreCase("Educational")){
System.out.println("Enter Educational Institution");
String educationalInstitution=sc.nextLine();
System.out.println("Enter Educational Division");
String educationalDivision=sc.nextLine();
EducationalEndowment educationalEndowment = new
EducationalEndowment(endowmentId,holderName,endowmentType,registrationDate,educatio
nalInstitution,educationalDivision);
System.out.println("Endowment Amount
"+educationalEndowment.calculateEndowment());
}
else{
System.out.println("Enter Health Care Center");
String healthCenter=sc.nextLine();
System.out.println("Enter Holder Age");
int holderAge=Integer.parseInt(sc.nextLine());
HealthEndowment healthEndowment=new
HealthEndowment(endowmentId,holderName,endowmentType,registrationDate,healthCenter,
holderAge);
System.out.println("Endowment Amount
"+healthEndowment.calculateEndowment());
}
}
}
21. Auditing
import java.util.ArrayList;
//========================================//
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
return employeeAudit;
}
switch(choice){
case 1:
System.out.println("Enter the Employee name");
String name=sc.nextLine();
System.out.println("Enter the Employee Salary");
double salary=Double.parseDouble(sc.nextLine());
emp.addEmployeeDetails(name,salary);
break;
case 2:
System.out.println("Enter the salary to be searched");
double search=Double.parseDouble(sc.nextLine());
ArrayList<String>
nameList=findEmployee().fetchEmployeeDetails(search);
if(nameList.isEmpty()){
System.out.println("No employee found");
}
else{
System.out.println("Employee List");
for(String empName: nameList){
System.out.println(empName);
}
}
break;
default:
break;
}}while(choice!=3);
}
}
22. Number Category
//=========================================//
import java.util.*;
while(i<j){
if(n.charAt(i)==n.charAt(j)){
i++;
j--;
continue;
}return false;
}return true;
}
if(isAmicable){
System.out.println("The numbers are amicable");
}
else{
System.out.println("The numbers are not amicable");
}
if(isPalindrome){
System.out.println("Product do produces a palindrome");
}
else{
System.out.println("Product does not produce a palindrome");
}
}
}
23. Travel Agency
//=========================================//
//======================================//
import java.util.*;
if(ticketObj.getClassType().equalsIgnoreCase("sl")||ticketObj.getClassType().equals
IgnoreCase("2s")){
commissionAmt+=60;
}
else{
commissionAmt+=100;
}
return commissionAmt;
});
return commissionInfo;
}
commission+=generateCommissionObtained().calculateCommissionAmount(tickets[i]);
}
System.out.printf("Commission obtained per each person:
Rs.%.2f",commission);
}
}
24. Water Distributor
//============================================//
//============================================//
import java.util.Scanner;
public class UserInterface {
}
}
25. College Account
//===================================//
import java.util.Scanner;
int tuitionFee =
generateFeeReceipt().calculateTuitionFees(courseType,basicFee,semesters);
System.out.println("Fees Receipt");
System.out.println("Registration number: "+regNo);
System.out.println("Student name: "+studName);
if(courseType.equalsIgnoreCase("regular"))
System.out.println("Tuition fee for regular student: "+tuitionFee);
else System.out.println("Tuition fee for selfFinance student:
"+tuitionFee);
}
}
26. Vehicle Capacity Calculator
//==============================================//
import java.util.Scanner;
try {
validatePetrolUsage(petrol);
} catch(PetrolOverflowException e) {
System.out.println(e.getMessage());
}
}
}
//==============================================//
return flag;
}
}
27. Array Manipulation - Use try with multi catch
import java.util.*;
import java.io.*;
int n=sc.nextInt();
int p[]=new int[n];
System.out.println("Enter the array elements");
for (int i=0; i<n; i++)
p[i]=sc.nextInt();
//========================================//
import java.util.Scanner;
//=========================================//
}
return flag;
}
}
29. String Extraction
import java.util.Scanner;
}
30. Campus Radio Frequency
//========================================//
import java.util.Scanner;
try {
validateStation(freq);
} catch(StationNotAvailableException e) {
System.out.println(e.getMessage());
}
//===========================================//
else{
throw new StationNotAvailableException("Radio Station not
available");
}
return flag;
}
}
31. Stock List
import java.util.*;
import java.util.Scanner;
int num=Integer.parseInt(sc.nextLine());
System.out.println(company);
}
}
32. Babitha’s App
import java.util.*;
for(String str:text){
if(!words.containsKey(str)){
words.put(str,1);
}
else{
int count = words.get(str);
words.put(str, count+1);
}
}
int total=0,num=0;
words.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(x->
wordSort.put(x.getKey(),x.getValue()));
for(Map.Entry<String,Integer> entry:wordSort.entrySet()){
num=entry.getValue();
total+=num;
}
wordSort.entrySet().forEach(entry -> {
System.out.println(entry.getKey()+" - "+entry.getValue());
});
}
}
33. Plip Event
import java.util.Scanner;
//==============================================//
import java.util.*;
int Count=0;
for(Map.Entry<String, Double> i:studentMap.entrySet())
if(i.getValue()>90)
Count++;
return Count;
}
}
34. Top Tier Motors
import java.util.Scanner;
String decision=null;
System.out.println("Enter the vehicle name to be searched");
String vehicleName=sc.nextLine();
do{
double discount =
vehicleUtility.calculateCostAfterDiscount(vehicleName);
if(discount>0){
System.out.println("Price after discount for
"+vehicleName+" is "+discount);
}
else if (discount<=0){
System.out.println(vehicleName+" is not available
currently");
}
System.out.println("Do you want to continue (Y/N)");
decision=sc.next();
if(decision.equalsIgnoreCase("Y")){
System.out.println("Enter the vehicle name to be
searched");
sc.nextLine();
vehicleName=sc.nextLine();
continue;
}
else{
break;
}
}while(decision!="N");
System.out.println("Thank you for using the Application");
}
}
//============================================//
import java.util.HashMap;
import java.util.Map;
// This method should add the vehicleName as key and the price of the
// vehicle as value into a Map
public void addVehiclePriceDetails(String vehicleName, double price) {
// fill the code
vehicleMap.put(vehicleName, price);
}
// This method should calculate the discount and return the selling price
// after the discount for the vehicle name passed as an argument.
public double calculateCostAfterDiscount(String vehicleName) {
//from here
// fill the code
try{
if(vehicleName.contains("TVS")){
return vehicleMap.get(vehicleName)*0.90;
}
else if (vehicleName.contains("Honda")){
return vehicleMap.get(vehicleName)*0.95;
}
else if (vehicleName.contains("Yamaha")){
return vehicleMap.get(vehicleName)*0.93;
}
else{
return 0;
}
}
catch(NullPointerException e){
return -1;
}
}
}