update,
This commit is contained in:
11
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Circle.java
Normal file
11
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Circle.java
Normal file
@@ -0,0 +1,11 @@
|
||||
class Circle {
|
||||
private double radius;
|
||||
|
||||
public Circle(double r) {
|
||||
radius = r;
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return radius*radius*Math.PI;
|
||||
}
|
||||
}
|
33
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Ex1.java
Normal file
33
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Ex1.java
Normal file
@@ -0,0 +1,33 @@
|
||||
class Circle {
|
||||
private double radius;
|
||||
|
||||
public Circle(double r) {
|
||||
radius = r;
|
||||
}
|
||||
|
||||
public double area() {
|
||||
return radius*radius*Math.PI;
|
||||
}
|
||||
}
|
||||
|
||||
class Rectangle {
|
||||
private double length;
|
||||
private double width;
|
||||
public Rectangle(double l, double w) {
|
||||
length = l;
|
||||
width = w;
|
||||
}
|
||||
public double area() {
|
||||
return length * width;
|
||||
}
|
||||
}
|
||||
|
||||
public class Ex1 {
|
||||
public static void main(String [] args) {
|
||||
Rectangle r = new Rectangle(30.1, 10.2);
|
||||
Circle c = new Circle(5.3);
|
||||
|
||||
System.out.println("r=" + r);
|
||||
System.out.println("c=" + c);
|
||||
}
|
||||
}
|
15
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Ex2.java
Normal file
15
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Ex2.java
Normal file
@@ -0,0 +1,15 @@
|
||||
public class Ex2 {
|
||||
public static void main(String [] args) {
|
||||
Rectangle r = new Rectangle(1, 2);
|
||||
System.out.println("r=" + r);
|
||||
System.out.println("area=" + r.area());
|
||||
|
||||
r = new Rectangle(3, 4);
|
||||
System.out.println("r=" + r);
|
||||
System.out.println("area=" + r.area());
|
||||
|
||||
r = null;
|
||||
System.out.println("r=" + r);
|
||||
System.out.println("area=" + r.area());
|
||||
}
|
||||
}
|
11
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Rectangle.java
Normal file
11
it114105/itp3914/Lab11/ques_source/Ex1_Ex2/Rectangle.java
Normal file
@@ -0,0 +1,11 @@
|
||||
class Rectangle {
|
||||
private double length;
|
||||
private double width;
|
||||
public Rectangle(double l, double w) {
|
||||
length = l;
|
||||
width = w;
|
||||
}
|
||||
public double area() {
|
||||
return length * width;
|
||||
}
|
||||
}
|
24
it114105/itp3914/Lab11/ques_source/Ex3/Triangle.java
Normal file
24
it114105/itp3914/Lab11/ques_source/Ex3/Triangle.java
Normal file
@@ -0,0 +1,24 @@
|
||||
class Triangle {
|
||||
private int base;
|
||||
private int height;
|
||||
|
||||
public Triangle() {
|
||||
base = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
public Triangle(int base, int height) {
|
||||
this.base = base;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void printThis() {
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
public static void main(String [] args) {
|
||||
Triangle t = new Triangle(1, 2);
|
||||
System.out.println(t);
|
||||
t.printThis();
|
||||
}
|
||||
}
|
28
it114105/itp3914/Lab11/ques_source/Ex4/DataUser.java
Normal file
28
it114105/itp3914/Lab11/ques_source/Ex4/DataUser.java
Normal file
@@ -0,0 +1,28 @@
|
||||
class Date {
|
||||
private int day;
|
||||
private int month;
|
||||
private int year;
|
||||
|
||||
public Date() {
|
||||
this(1, 1, 1970);
|
||||
}
|
||||
|
||||
public Date(int day, int month, int year) {
|
||||
this.day = day;
|
||||
this.month = month;
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + day + "/" + month + "/" + year + "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class DataUser {
|
||||
public static void main(String [] args) {
|
||||
Date d1 = new Date();
|
||||
|
||||
System.out.println(d1);
|
||||
}
|
||||
}
|
13
it114105/itp3914/Lab11/ques_source/Ex5/Q1Main.java
Normal file
13
it114105/itp3914/Lab11/ques_source/Ex5/Q1Main.java
Normal file
@@ -0,0 +1,13 @@
|
||||
public class Q1Main {
|
||||
public static void main(String [] args) {
|
||||
QuestionOne q1 = new QuestionOne(); //line1
|
||||
q1.A = 12; //line2
|
||||
q1.b = 12; //line3
|
||||
q1.c = 12; //line4
|
||||
q1.methodOne(12); //line5
|
||||
q1.methodOne();//line6
|
||||
System.out.println(q1.methodTwo());//line7
|
||||
q1.b = q1.methodTwo();//line8
|
||||
}
|
||||
|
||||
}
|
12
it114105/itp3914/Lab11/ques_source/Ex5/QuestionOne.java
Normal file
12
it114105/itp3914/Lab11/ques_source/Ex5/QuestionOne.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class QuestionOne {
|
||||
public final int A = 345;
|
||||
public int b;
|
||||
private float c;
|
||||
|
||||
private void methodOne(int a) {
|
||||
b = a;
|
||||
}
|
||||
public float methodTwo() {
|
||||
return 23;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user