Mark 1
Mark 1
UID : 2022300004
QUE 1 : Write a program to find the sum of the first two digit of two numbers. Use the
concept of classes and objects.
Code :
import java.util.Scanner;
System.out.println("The sum of the first two digits of the two numbers is: " + sum); }
}
class NumberAdder {
private int num1;
private int num2;
Que 2 : Create class Product. Using a method, set its values for product name, prize, brand.
Write
another method to display the GST needed to pay on the current object.
Code :
class Product {
private String name;
private double price;
private String brand;
public void setName(String name) {
this.name = name;
}
public void setPrice(double price) {
this.price = price;
}
public void setBrand(String brand) {
this.brand = brand;
}
public void displayGST() {
double gst = price * 0.25;
System.out.println("GST on " + name + " (" + brand + ") is " + gst);
}
}
public class Main {
public static void main(String[] args) {
Product product = new Product();
product.setName("Laptop");
product.setBrand("HP");
product.setPrice(485990);
product.displayGST();
}
}
Output :
Que 3 : Write a program to design a Class cycler with name, age, no. of marathon attended
and calculate the average speed of each cycler. use appropriate data for cycler if missing.
Code :
class Cycler {
String name;
int age;
int noOfMarathonsAttended;
Output :
QUE 4 : A painter is given a contract to paint a wall. He goes and measures with a meter
tape. However
he makes further calculations in foot. Cost of painting per square foot is Rs. 10. Find the
amount
to be paid to him for painting. A constructor is used to set the length and breadth of the wall.
Use an object as a parameter. Note: 1 meter= 3.28 feet.
Code :
class Painter {
this.lengthInMeters = lengthInMeters;
this.breadthInMeters = breadthInMeters;
}
public double calculateAreaInSquareFeet() {
return areaInSquareFeet;
return amountToBePaid;
Output :
Que 5 : Create a Class Student containing the student's name, marks of 5 papers of a
subject (use integer
array).
Use parameterized constructors to initialize values of marks and
name. Write a method:
1. To find average of 5 papers
2. To display the name of the student, marks of 5 papers, and average.
Code :
class Student {
this.name = name;
this.marks = marks;
double sum = 0;
sum += marks[i];
return average;
System.out.print("Marks: ");
System.out.println();
} Ouput :