java实验报告实验一、集成环境及语言基础
一、实验目的:熟悉集成环境,通过设计一个简单的类来完成编码编译及运行的全过程。
二、实验要求:
熟悉Eclipse(或Jcreator等)集成环境的使用;学习Java程序的基本结构,类的定义及对象的创建;学习变量、表达式、控制流程使用。
三、实验内容
1、 对editplus进行设置,配置用户工具。(使用Eclipse 可略)
2、 Write a static double calculateArea (String shape ,double radius, double width, dou...
实验一、集成环境及语言基础
一、实验目的:熟悉集成环境,通过
一个简单的类来完成编码编译及运行的全过程。
二、实验要求:
熟悉Eclipse(或Jcreator等)集成环境的使用;学习Java程序的基本结构,类的定义及对象的创建;学习变量、
达式、控制
使用。
三、实验
1、 对editplus进行设置,配置用户工具。(使用Eclipse 可略)
2、 Write a static double calculateArea (String shape ,double radius, double width, double height) function which computes and returns the area of a shape based on the following criteria:
1. if the shape is “circle”, the formula to calculate area is 3.14*radius*radius.
2. if the shape is “rectangle”, the formula to calculate area is width * height.
3. if the shape is “square”, the formula to calculate area is width * width.
4. if the shape is any other String value, the formula to calculate area is return -1.
3、 编写一个程序用以设置和输出员工属性,员工属性包括工号,姓名和工资(经理是一类特殊的员工,除了员工的基本属性另外还具有奖金);
参考程序
计算面积
一、
import java.io.*;
public class calculatearea1 {
/**
* @param args
*/
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
final double PI=3.14;
String shape;
double radius;
double weight;
double heigth;
double area;
shape=br.readLine();
if (shape.equals("circle")){
System.out.println("input radius:");
radius=Double.parseDouble(br.readLine());
area=PI*radius*radius;
System.out.println("the area of circle is"+area);
}
else if(shape.equals("rectangle")){
System.out.println("input weight:");
weight=Double.parseDouble(br.readLine());
System.out.println("input height:");
heigth=Double.parseDouble(br.readLine());
area=weight*heigth;
System.out.println("the area of rectangle is"+area);
}
else if(shape.equals("squre")){
System.out.println("input wigth:");
weight=Double.parseDouble(br.readLine());
area=weight*weight;
System.out.println("the area of rectangle is"+area);
}
else System.out.println("the input is wrong");
}
}
二、import java.io.*;
public class calculatearea2 {
/**
* @param args
*/
public void calculate()throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
final double PI=3.14;
String shape;
double radius;
double weight;
double heigth;
double area;
shape=br.readLine();
if (shape.equals("circle")){
System.out.println("input radius:");
radius=Double.parseDouble(br.readLine());
area=PI*radius*radius;
System.out.println("the area of circle is"+area);
}
else if(shape.equals("rectangle")){
System.out.println("input weight:");
weight=Double.parseDouble(br.readLine());
System.out.println("input height:");
heigth=Double.parseDouble(br.readLine());
area=weight*heigth;
System.out.println("the area of rectangle is"+area);
}
else if(shape.equals("squre")){
System.out.println("input wigth:");
weight=Double.parseDouble(br.readLine());
area=weight*weight;
System.out.println("the area of rectangle is"+area);
}
else System.out.println("the input is wrong");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
calculatearea2 c=new calculatearea2();
try{
c.calculate();
}
catch (Exception e){
System.out.println("there is an exception");
}
finally {
System.out.println("it must be excuted");
}
}
}
三、import java.util.*;
public class calculatearea3 {
/**
* @param args
*/
public void calculate(){
Scanner sc=new Scanner(System.in);
final double PI=3.14;
String shape;
double radius;
double weight;
double heigth;
double area;
shape=sc.next();
if (shape.equals("circle")){
System.out.println("input radius:");
radius=sc.nextDouble();
area=PI*radius*radius;
System.out.println("the area of circle is"+area);
}
else if(shape.equals("rectangle")){
System.out.println("input weight:");
weight=sc.nextDouble();
System.out.println("input height:");
heigth=sc.nextDouble();
area=weight*heigth;
System.out.println("the area of rectangle is"+area);
}
else if(shape.equals("squre")){
System.out.println("input wigth:");
weight=sc.nextDouble();
area=weight*weight;
System.out.println("the area of rectangle is"+area);
本文档为【java实验报告】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。