1. Create a base class named Point consisting of x and y data members representing point coordinates. From this class, derive a class named Circle with another data member named radius. For this derived class, the x and y data members represent a circle’s centre coordinates. The member method of the Point class should consist of a constructor that set the value for x and y to 0, an area() method that return 0.
The derived class should has an override method named area() that return’s a circle area.
Area = 3.14 x radius2.
Draw UML diagram for the class Point and class Circle and then implement the class. Write a test program that creates one Point object and one Circle object with x 5, y 7 and radius 13. Display x and y for Point Object; x, y and radius for Circle Object.
2.
Create a class named Rectangle that contains data fields for height and length and a method named getArea() that returns the area of this Rectangle.
Create a child class (derived from Rectangle) named Cube. Cube contains an additional data field named depth, and a getArea() method that overrides the parent method.
Draw the UML diagram for the class (Class Rectangle and Class Cube) and then implement the class. Write a test program that creates one Rectangle object with height 4 and length 40 and one Cube object height 15, length 20 and depth 45.
Display height, length and area of each object.
Showing posts with label 17/18 SEM 2 BCS2233. Show all posts
Showing posts with label 17/18 SEM 2 BCS2233. Show all posts
5/15/2018
4/24/2018
BCS2233 OOP. Lab 25 April 2018
Give both Structured and Object Oriented solution for the following problems.
1. Write a java program that reads the length and height of a rectangle and computes its area and parameter using the following formulas:-
Area = length x height
Perimeter = 2 x (length + height)
Structured: https://drive.google.com/file/d/0BxDLK8tlx2V1dEo0MGRRY3FLcmM/view?usp=sharing
2. Write a java program that reads the height of a cube and computes its area and parameter using the following formulas:-
Area = height2
Perimeter = 4 x height
Structured: https://drive.google.com/file/d/0BxDLK8tlx2V1MzM4SERjQkctLUk/view?usp=sharing
3. Write a program that reads in the radius and length of a cylinder and computes its volume using the following formulas:
Area = radius * radius * 3.14
Volume = area * length
1. Write a java program that reads the length and height of a rectangle and computes its area and parameter using the following formulas:-
Area = length x height
Perimeter = 2 x (length + height)
Structured: https://drive.google.com/file/d/0BxDLK8tlx2V1dEo0MGRRY3FLcmM/view?usp=sharing
2. Write a java program that reads the height of a cube and computes its area and parameter using the following formulas:-
Area = height2
Perimeter = 4 x height
Structured: https://drive.google.com/file/d/0BxDLK8tlx2V1MzM4SERjQkctLUk/view?usp=sharing
3. Write a program that reads in the radius and length of a cylinder and computes its volume using the following formulas:
Area = radius * radius * 3.14
Volume = area * length
4/17/2018
BCS2233 OOP. Method.
By implementing functions (also called methods) in a program, programmer
reduces coding time and debugging time, thereby reducing the overall
development time.
Consider the following Java program. Create and use method where necessary.
Consider the following Java program. Create and use method where necessary.
//program 1
import java.util.Scanner;
public class tambahNombor {
public static void main(String[] args) {
int
N1,N2,hasiltambah;
Scanner
input= new Scanner(System.in);
System.out.println("Sila
masukkan dua nombor");
N1=
input.nextInt();
N2=
input.nextInt();
hasiltambah=N1+N2;
System.out.println("Hasil
tambah dua nombor ialah "+hasiltambah);
System.out.println("Sila
masukkan dua nombor");
N1=
input.nextInt();
N2=
input.nextInt();
hasiltambah=N1+N2;
System.out.println("Hasil
tambah dua nombor ialah "+hasiltambah);
System.out.println("Sila
masukkan dua nombor");
N1=
input.nextInt();
N2=
input.nextInt();
hasiltambah=N1+N2;
System.out.println("Hasil
tambah dua nombor ialah "+hasiltambah);
System.out.println("Sila
masukkan dua nombor");
N1=
input.nextInt();
N2=
input.nextInt();
hasiltambah=N1+N2;
System.out.println("Hasil
tambah dua nombor ialah "+hasiltambah);
}
}
//program 2
import
java.util.Scanner;
public class sumInteger {
public
static void main(String[] args) {
int N1,N2,sum,count;
Scanner input = new
Scanner(System.in);
System.out.println("Sila
masukkan dua nombor!");
N1= input.nextInt();
N2= input.nextInt();
sum=0;
for(count=N1;count<=N2;count++)
{
sum=sum+count;
}
System.out.println("Hasil tambah "+N1+" hingga
"+N2+" ialah " + sum);
System.out.println("Sila masukkan dua nombor ");
N1= input.nextInt();
N2= input.nextInt();
sum=0;
for(count=N1;count<=N2;count++)
{
sum=sum+count;
}
System.out.println("Hasil tambah "+N1+" hingga
"+N2+" ialah " + sum);
System.out.println("Sila masukkan dua nombor!");
N1= input.nextInt();
N2= input.nextInt();
sum=0;
for(count=N1;count<=N2;count++)
{
sum=sum+count;
}
System.out.println("Hasil tambah "+N1+" hingga
"+N2+" ialah " + sum);
}
}
//program 3
import java.util.Scanner;
public class bmi {
public static void main(String[] args) {
double
berat,tinggi,BMI;
String
status;
Scanner
input = new Scanner(System.in);
System.out.println("Sila
masukkan berat (KG) dan tinggi (Meter)");
berat
= input.nextDouble();
tinggi
= input.nextDouble();
BMI=berat/(tinggi*tinggi);
if(BMI<18 .5="" p="">
System.out.println("underweight");
else
if((BMI>=18.5)&&(BMI<=24.9))
System.out.println("healthy");
else
if((BMI>=25)&&(BMI<=29.9))
System.out.println("overweight");
else
if (BMI>=30)
System.out.println("obes");
System.out.println("Sila
masukkan berat (KG) dan tinggi (Meter)");
berat
= input.nextDouble();
tinggi
= input.nextDouble();
BMI=berat/(tinggi*tinggi);
if(BMI<18 .5="" p="">
18>
System.out.println("underweight");
else
if((BMI>=18.5)&&(BMI<=24.9))
System.out.println("healthy");
else
if((BMI>=25)&&(BMI<=29.9))
System.out.println("overweight");
else
if (BMI>=30)
System.out.println("obes");
System.out.println("Sila
masukkan berat (KG) dan tinggi (Meter)");
berat
= input.nextDouble();
tinggi
= input.nextDouble();
BMI=berat/(tinggi*tinggi);
if(BMI<18 .5="" p="">
18>
18>
System.out.println("underweight");
else
if((BMI>=18.5)&&(BMI<=24.9))
System.out.println("healthy");
else
if((BMI>=25)&&(BMI<=29.9))
System.out.println("overweight");
else
if (BMI>=30)
System.out.println("obes");
}
}
//program 4
import java.util.Scanner;
public class ulangPesanan {
public static void main(String[] args) {
Scanner
input = new Scanner(System.in);
String
pesanan;
int
i,jumlahUlangan;
System.out.println("Sila
masukkan Pesanan :");
pesanan
= input.nextLine();
System.out.println("Berapa
kali nak ulang ? :");
jumlahUlangan
= input.nextInt();
for (i=1;i<=jumlahUlangan;i++)
{
System.out.println(pesanan);
}
System.out.println("Sila masukkan
Pesanan :");
pesanan
= input.nextLine();
System.out.println("Berapa
kali nak ulang ? :");
jumlahUlangan
= input.nextInt();
for (i=1;i<=jumlahUlangan;i++)
{
System.out.println(pesanan);
}
System.out.println("Sila masukkan
Pesanan :");
pesanan
= input.nextLine();
System.out.println("Berapa
kali nak ulang ? :");
jumlahUlangan
= input.nextInt();
for (i=1;i<=jumlahUlangan;i++)
{
System.out.println(pesanan);
}
}
}
18>
Subscribe to:
Posts (Atom)
Cara download Installer windows 10 dalam format ISO
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...
-
1.TOPUP Cepat Susut Jika anda merasa topup prepaid anda cepat susut walaupun tak banyak call- ada baiknya anda semak log call/sms/content ...
-
Section 8 The String Class 8.1 Suppose that s1 , s2 , s3 , and s4 are four strings, given as follows: String s1 = ...
-
1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan. ...