Lab Record For Java Programming and Introduction of Python Lab (BCE-C657)
Lab Record For Java Programming and Introduction of Python Lab (BCE-C657)
Lab Record For Java Programming and Introduction of Python Lab (BCE-C657)
for
Java Programming and Introduction
of python Lab (BCE-C657)
2022 - 2023
Submitted
By:
Gautam Singh Kushwaha
206320055
Branch-ECE
Submitted
to
Mr. Namit Khanduja,
Assistant Professor, Department of Computer Science & Engineering,
Faculty of Engineering & Technology,
Gurukul Kangri Deemed to be University, Haridwar.
Declaration
This is to certify that the programs done in this manual has been developed by me and I have
not copied this file from anywhere.
Signature of Student
Certificate
This is to certify that Mr. Gautam Singh Kushwaha of B.Tech VI semester has
satisfactorily completed his experiments for Java programming and
Introduction of python lab in requirement for partial fulfillment of bachelor
degree in Electronics & Communication Engineering prescribed by Faculty of
Engineering & Technology, Gurukula Kangri Deemed to be University,
Haridwar during the year 2022 -2023.
Signature Signature
Internal Examiner External Examiner
Index
S.No Program / Problem Name
1. CEL TO FARENHEIT
2. FARENHEIT TO CEL
3. NESTED CLASSES
5. STRING SLICING
6. LIST COMPREHENSION
7. DICTIONARY COMPREHENSION
8. BMI CALCULATION
9. DAWOOD ABRAHIM
/**
*/ import
java.util.Scanner;
float C = in.nextFloat();
/* Print result */
class FahrenheittoCelsius
{ double
a,c;
a=sc.nextDouble();
{ return (f-
32)*5/9;
Q.3) write four program explaining the nested class of each type.
:1. Java static nested class class TestOuter1{
class CPU {
double price; //
nested class
class Processor{
manufacturer;
double getCache(){
return 4.3;
manufacturer;
double getClockSpeed(){
return 5.5;
}
}
main(String[] args) {
public Inner()
{
divisor = 4;
remainder = sum%divisor;
}
private int getDivisor()
{
return divisor;
}
private int getRemainder()
{
return sum%divisor;
}
private int getQuotient()
{
System.out.println("Inside inner class");
return sum / divisor;
}
}
// Interface
interface Age {
// Class 1
// Helper class implementing methods of Age Interface class
MyClass implements Age {
// Class 2
// Main class
// AnonymousDemo
class GFG { // Main driver method
public static void main(String[] args)
{
// Class 1 is implementation class of Age interface
MyClass obj = new MyClass();
class Stack {
// store elements of
// Creating a stack
Stack(int size) {
capacity = size;
top = -1;
if (isFull()) {
System.out.println("Stack OverFlow");
// terminates the program
System.exit(1);
arr[++top] = x;
// if stack is empty
// no element to pop
if (isEmpty()) {
System.out.println("STACK EMPTY");
System.exit(1);
return arr[top--];
return top + 1;
}
// check if the stack is empty
stack.push(1);
stack.push(2);
stack.push(3);
System.out.print("Stack: ");
stack.printStack();
stack.pop();
stack.printStack();
}
Q.5 Write a program to demonstrate string slicing in python for negative and
positive slicing.
# String slicing
String = 'ASTRING'
print("String slicing")
print(String[s1])
print(String[s2])
print(String[s3])
Q.6) Write a program in python to demonstrate different ways to create list and list
comprehension.
print(matrix)
Example 4: List Comprehensions vs For Loop
# Empty list
List = []
print(numbers)
Example 2:
sDict = {x.upper(): x*3 for x in 'coding '}
print (sDict)
Q.8 Create a BMI calculation application that reads the user's weight in pounds or
kg and height in inches or meter. Calculate and display the user's BMI . the should
also display the catagory like :
1> underweight if the BMI is less than 18.5
2> normal if the BMI is in between 18.5 to 24.9
3> overweight if the BMI is greater than 30
formula use for the BMI calculation is : : BMI=
(weight(pounds)*703)/height(inches) and BMI=(weight(kg))/height(m)
class BMICalculator {
// check range
if(bmi < 18.5)
return "Thinness";
else if(bmi < 25)
return "Normal";
else if(bmi < 30)
return "Overweight";
else return "Obese";
}
// declare variables
double weightInKg = 0.0f;
double heightInMeters = 0.0f;
String result = null;
// display result
System.out.println(result);
Q.9) The famous gangster Dawood Abrahim is moving to Islamabad. He has a very
big family there, all of them living on khan Avenue. Since he will visit all his
relatives very often, he wants to find a house close to them. Indeed, Dawood
wants to minimize the total distance to all of his relatives and has blackmailed you
to write a program that solves his problem.
Input
The input consists of several test cases. The first line contains the number
of test cases. For each test case you will be given the integer number of
relatives r (0 < r < 500) and the street numbers (also integers) s1, s2, . . . , si,
. . . , sr where they live (0 < si < 30, 000). Note that several relatives might
live at the same street number.
Output
For each test case, your program must write the minimal sum of distances
from the optimal Dawood’s house to each one of his relatives. The
distance between two street numbers si and sj is dij = |si − sj |.
Sample Input 2
224
3246
Sample Output
2
4
input:
2
2 2 4
3 2 4 6
Output:
2
4
# override calculateCost function to add additional fee per ounce to base cost per ounce
Input:
2
John Smith
123 Main Street
New York
NY
10001
Jane Doe
456 Elm Street
Los Angeles
CA
90001
10
0.5
2
Mary Jones
789 Pine Avenue
Chicago
IL
60606
Bob Lee
321 Maple Road
Houston
TX
77002
15
0.4
3
0.1
Output:
7.0
9.5
Program no. 2
Create an Account class that a bank might use to represent customers’ bank
accounts. Include a data member of type float to represent the account balance.
Provide a constructor that receives an initial balance and uses it to initialize the
data member. The constructor should validate the initial balance to ensure that it’s
greater than or equal to zero. If not, set the balance to zero and display an error
message indicating that the initial balance was invalid. Provide three member
functions. Member function credit should add an amount to the current balance.
Member function debit should withdraw money from the Account and ensure that
the debit amount does not exceed the Account’s balance. If it does, the balance
should be left unchanged and the function should print a message indicating “Debit
amount exceeded account balance”. Member function getBalance should return
the current balance. Create a program that creates two Account objects and tests
the member functions of class Account
import java.util.Scanner;
class BankDetails {
private String accno;
Scanner sc = new
Scanner(System.in); //method to
openAccount() {
accno = sc.next();
= sc.next();
balance = sc.nextLong();
long amt;
}
//method to withdraw
= balance - amt;
ac_no) { if (accno.equals(ac_no)) {
return (false);
int n = sc.nextInt();
C[i].openAccount();
do {
switch (ch) {
case 1:
C[i].showAccount();
break;
case 2:
} if
(!found) {
break;
case 3:
{ C[i].deposit();
break;
}
}
if (!found) {
break;
case 4:
System.out.print("Enter Account No :
{ C[i].withdrawal();
break;
} if
(!found) {
break;
case 5:
break;