nak cerita sikit bila dah masuk semester baru nie..rasa tertekan plak ngan subject sem ni..
nak kata susah tu xdelah susah sangat sebenarnye maybe sebab mali yang kurang struggle kot kalau nak compare ngan semester sebelum nie..btw tiba-tiba pulak ada 1 subject ni yang payah sikit nak paham bila compile by my brain.maunye pecah dok invoke itu ini,mutator la..parameter la..macam 2 la..padahal lecturer ajar punya semangat kat depan tapi mali still blurr nak pahamkan sampai berkerut 1000 line kt setiap urat muka nie..haishh...engat lagi mase ktorang blur2 lagi nak wat programme ni,berterabuh file2..pdahal madam da ckp "You must do 5 file in 1 folder!!" tyme tu rasenye mali da terlajak buat 2 file in 3 folder. habislah kalau tyme tu madam check mali pnye..alhamdulillah coz end up berjaya jugak siapkan..just nak kongsi past programme did i successed debug..happy sangat ..syukran to all my friends and my lovely lecturer ^^ ~
public abstract class GeometricObject {
private String color = "white";
protected GeometricObject () {
}
protected GeometricObject (String color){
this.color = color;
}
public String getColor (){
return color;
}
public void setColor (String color){
this.color=color ;
}
public abstract double getArea ();
public abstract double getPerimeter ();
}
import java.util.Scanner;
public class Circle extends GeometricObject {
private double radius;
public Circle (){
}
public Circle (double newradius){
radius = newradius;
}
public Circle (double radius,String color){
super (color);
this.radius = radius;
}
public double getRadius (){
return radius;
}
public void setRadius (double radius){
this.radius = radius;
}
public double getArea (){
return radius * radius * 3.142;
}
public double getPerimeter (){
return 2 * radius * 3.142;
}
public String toString (){
return "(Circle).radius = "+radius;
}
public String howToPrint(){
return "using glossy paper";
}
}
public class Rectangle extends GeometricObject {
private double width;
private double height;
public Rectangle (){
}
public Rectangle(double width,double height){
this.width=width;
this.height=height;
}
public Rectangle (double width,double height, String color){
super(color);
this.width = width;
this.height = height;
}
public double geWidth (){
return width;
}
public void setWidth (double width){
this.width = width;
}
public double getHeight (){
return height;
}
public void setHeight (double height){
this.height = height;
}
public double getArea (){
return width * height;
}
public double getPerimeter (){
return width+width+height+height;
}
public String toString (){
return "[Rectangle].width = "+width+"and (Rectangle).height="+height;
}
public String howToPrint(){
return "using A4 paper";
}
}
public class TestCircleRectangle {
public static void main (String[]args){
Circle lisaCircle = new Circle (1.0);
System.out.println("A Circle" +lisaCircle.toString ());
System.out.println("The color is" +lisaCircle.getColor ());
System.out.println("The radius is"+lisaCircle.getArea());
System.out.println("The perimeter is" +lisaCircle.getPerimeter ());
System.out.println(lisaCircle.howToPrint ());
Rectangle lisaRectangle = new Rectangle (7.0,55.0);
System.out.println("\nA rectangle" +lisaRectangle.toString ());
System.out.println("The area is" +lisaRectangle.getArea ());
System.out.println("The perimeter is"+lisaRectangle.getPerimeter());
System.out.println(lisaRectangle.howToPrint ());
}
}
public interface Printable {
public abstract String howToPrint ();
}
No comments:
Post a Comment