3:写一个课程类:
属性:课程名;学时;任课老师;
创建五个对象:“c语言”,“java编程”,“php网络编程”,“c++”,“数据结构” public class Course{
public static void main(String[]args){
Content cYu=new Content(\语言\诸葛亮Content java=new Content(\编程\周
\ 瑜\
Content php=new Content(\网络编程\鲁肃\
Content c=new Content(\语言\曹操\
Content shuJu=new Content(\数据结构\徐庶\ }
class Content{
private String courseName; private int time; private String teacher; }
public Content(String courseName,int time,String teacher) {
this.courseName = courseName;
this.time=time;
this.teacher = teacher;
System.out.println(\课程名:\学时:\任课老师:\ }
4: 0——————>X | |
| P(X,Y) | | Y
定义一个类,用于描述坐标点
(1) 具有计算当前点到原点距离的功能 (2) 求到任意一点(m,n)的距离
(3) 具有坐标点显示功能,显示格式(x,y) public class Distance{
public static void main(String[]args){ }
Point point=new Point(); point.getXY(3,4); point.getPoint(3,4,6,7); }
}
class Point{
int x; int y; int x1; int y1;
public void getXY(int x,int y) {
int d; this.x = x; this.y = y; d=x*x+y*y;
System.out.println(\坐标点:(\到原点的距离为\ {
}
public void getPoint(int x,int y,int x1,int y1)
double d; this.x = x; this.y = y; this.x = x1; this.y = y1;
d=Math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
System.out.println(\坐标点:(\到坐标点(\的距离为\ }
3:定义一个圆类型 提供显示圆周长功能的方法 提供显示圆面积的方法 public class Circle {
int R;
static double c; static double s;
public static void main(String[] args) { }
public static void perimeter(int R){ }
public static void area(int R){
s=Math.PI*R*R;
System.out.println(\圆的面积为:\c=2*Math.PI*R;
System.out.println(\圆的周长为:\ perimeter(5); area(5); }
相关推荐: