Skip to content

Instantly share code, notes, and snippets.

View Liyansu's full-sized avatar
🏠
Working from home

Liyansu

🏠
Working from home
View GitHub Profile
@Liyansu
Liyansu / 2.5 Que.txt
Created June 5, 2021 15:32
2.5 Create a class Car with three data members [model, color, brand] and a method [setData, displayCarInfo]
Create a class Car with three data members [model, color, brand] and a method [setData, displayCarInfo].
Create following objects.
Car 1: Model-City, Color-White, Brand-Honda
Car 2: Model-Desire, Color-Red, Brand-Maruti
Car 3: Model-XUV500, Color-Maroon, Brand-Mahindra
You may use setData method to pass all these values. For example, car1.setData(String mdl, String
clr, String brnd). Use the displayCarInfo method to print the details of respective car (E.g.
car1.displayCarInfo();)
@Liyansu
Liyansu / 2.4 Que.txt
Created June 5, 2021 15:28
2.4 Write a Java program to implement Vector with following functionality.
Write a Java program to implement Vector with following functionality.
Create a vector student with syntax: Vector student = new Vector();
Using the syntax student.insertElementAt("Mobile",0); to add “Mobile” at 0th location OR use
the syntax Student.addElement(“Mobile”);
Subsequently, add “Laptop”, “Watch”, “Shoes”, “T-shirt” and “Jeans”.
Now, display all the items in student vector using System.out.println(student);
Later, the student decided to return “Jeans” using student.remove(“Jeans”);
After removing Jeans, display the items available with the student.
(You may try other functions related to Vectors mentioned in the lecture note)
@Liyansu
Liyansu / 2.3 Que.txt
Last active June 9, 2021 17:25
2.3 An employee gets paid (hours worked) × (basic pay), for each hour up to 40 hours for a week
An employee gets paid (hours worked) × (basic pay), for each hour up to 40 hours for a week.
For every hour over 40, they get overtime = (base pay) × 1.5.
The base pay must not be less than the minimum wage (Rs. 150 an hour).
If it is, print an error.
If the number of hours is greater than 60 per, print an error message.
Write a Java program that reads
(1) basic pay per hour and
(2) number of hours worked per week and display the wage/salary to be paid to him/her.
@Liyansu
Liyansu / 2.2 Que.txt
Created June 5, 2021 15:00
2.2 Following figure shows the pentagonal numbers creation for a typical pentagon
For any number “i”, the pentagonal number is computed using the equation [i*(3*i-1)]/2.
Hence, write a Java program with getPentagonalNumber as method that takes a number “i” as input and returns the equivalent
pentagonal number.
Print first 4 (n=4) pentagonal numbers (E.g. 1, 5, 12, 22 as shown in the figure).
@Liyansu
Liyansu / 2.1 Que.txt
Last active June 9, 2021 17:02
2.1 The formula for calculating Body Mass Index (BMI)
The formula for calculating Body Mass Index (BMI) is weight (kg) / [height (m)]^2.
A person is
"Underweight" if BMI is below 18.5,
"Normal" if BMI is between 18.5 to 24.9,
"Overweight" if BMI is between 25.0 to 29.9, and
"Obese" if BMI is 30.0 and Above.
Write a Java program that reads "weight" (in kg) and
"height" (in meter) and display the status of the person (e.g."Underweight", "Normal" etc.)
@Liyansu
Liyansu / 1.5 Que.txt
Created June 5, 2021 14:42
1.5 Write a Java program to display all the prime numbers between two given numbers. (You may initialize the two numbers or read them from keyboard or input them as command line arguments)
1.5
Write a Java program to display all the prime numbers between two given numbers.
(You may initialize the two numbers or read them from keyboard or input them as command line arguments)
@Liyansu
Liyansu / 1.4 Que.txt
Last active June 9, 2021 15:34
1.4 Create a class stack with data[size] and stackTop as data members
1.4 Create a class stack with data[size] and stackTop as data members and push, pop and display as methods.
Write a Java program to create an object of stack class in main and invoke all the three functions from main to test their working.
@Liyansu
Liyansu / 1.3 Que.txt
Last active June 9, 2021 15:24
1.3 Design a class Bank with accountNo, name and balance as three members.
The class should have methods viz.
(a) depositMoney,
(b) withdrawMoney and
(c) askBalanace.
Write a Java program to create an object of Bank class in main function and invoke all the three functions from main to test their working.
@Liyansu
Liyansu / 1.2 Que.txt
Last active June 5, 2021 14:09
1.2 Following is a sample income tax slab
Up to Rs.2.5 lakh - No Tax (NIL)
Rs.2.5 lakh - Rs.5 lakh - 5%
Rs.5 lakh - Rs.7.5 lakh - 10%
Rs.7.5 lakh - Rs.10 lakh - 15%
Rs.10 lakh - Rs.12.5 lakh - 20%
Rs.12.5 lakh - Rs.15 lakh - 25%
Above Rs.15 lakh - 30%
Write a Java program which initialized the earning of an employee (E.g. int income=1950000;). Your program
should display the outcome (E.g. Income tax to be paid: 307500)
Explanation: