You are on page 1of 4

Department of Electronics & communication Engineering

Midterm 2
Course Information
Course Title: Object Oriented Programming
Course code: ICE107
Section: 01
Course Instructor: Mohammad Rafsun Islam
Student Information
Name: Rafat Hasan Dipu
ID: 2020-1-50-042

Submitted to: Submitted by:


Mohammad Rafsun Islam Rafat Hasan Dipu

Date: 27-08-2020

Code:
1.package Midterm_2;
class product{
String productname;
String producttype;
double rate;
void addstring() {
System.out.println(productname+producttype);
}
}
class tax extends product{
double productweight;
tax(String productname,String producttype,double rate,double
productweight){
this.productname=productname;
this.producttype=producttype;
this.rate=rate;
this.productweight=productweight;
}
double calculatetax() {
double cost,totalcost;
if((productweight>50)||( producttype=="car")) {
cost=productweight*rate;
totalcost=cost*0.15;
return totalcost;
}
else {
totalcost=productweight*rate;
return totalcost;
}
}
}
public class Inheritance {
public static void main(String[] args) {
tax a=new tax("RAFAT","car",10,60);
tax b=new tax("RAFAT","car",10,40);
System.out.println("Total cost is :"+a.calculatetax());
System.out.println("Total cost is :"+b.calculatetax());
a.addstring();// TODO Auto-generated method stub
}
}
2.
package Midterm_2;
class experiment{
static class one{
static int n;
static void square(int n) {
int power;
for(int i=1;i<=n;i++) {
power=i*i;
System.out.println(power);
}
}
}
class two{
void primerange(int n1,int n2){
int c1=0;
for(int i=n1; i<=n2; i++) {
for(int j=2; j<i; j++)
{
c1=0;
if(i%j==0)
{
c1=1;
break;
}
}
if(c1==0) {
System.out.println("The prime no is : "+i);
}
}
}
}
}
public class innerclass {
public static void main(String[] args) {
experiment.one.square(10);
experiment e=new experiment();
experiment.two d=e. new two();
d.primerange(20, 30);
// TODO Auto-generated method stub
}
}
3.
package Midterm_2;
class student{
int totalmarks[];
student(int marks[]){
this.totalmarks=marks;
}
void grade() {
int highest=totalmarks[0];
for(int i=0; i<totalmarks.length; i++) {
if(totalmarks[i]>highest) {
highest=totalmarks[i];
}
}
System.out.println("The highest marks of the total
students"+highest);
}
void grade(int a[]) {
int held;
for(int i=0; i<a.length;i++) {
for(int j=0;j<a.length-1; j++) {
if(a[j]>a[j+1]) {
held=a[j];
a[j]=a[j+1];
a[j+1]=held;
}
}
}
System.out.println("Print the value low to high.");
for(int j=0;j<a.length;j++) {
System.out.println(a[j]);
}
}
}
public class Methodoverloading {
public static void main(String[] args) {
student rafat= new student(new int[] {33,40,50,55,67,73,98,85});
rafat.grade();
int x[]= {40,33,85,90,87,75};
rafat.grade(x);
// TODO Auto-generated method stub
}
}
Discussiom:
in this first problem a class named product their have three
members name productname, producttype and rate. it will have a
method addstring. then as subclass of product named tax. it has a
constructor which assign the value of sub class and superclass. it
has a method named calculatetax which is calculate total cost if
productweight greater than 50 then is will add 15% vat of
totalcost. in the main class create a object a for subclass and
called the method. second problem class named student and its
member tottal marks which has constructor assign the value of
array.then a method which is empty and find heigest value of the
array.
second method determine low to high value using bubble sort.

You might also like