java程序设计课后答案 java程序设计第四版辛运帏
大家好,今天来为大家解答java程序设计课后答案这个问题的一些问题点,包括java程序设计第四版辛运帏也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~
Java程序设计,急求答案.
注释就不写了,将就着看吧
awt/swing的题目就算了,懒得写,很少用
1、声明一个类Person,成员变量有姓名、出生年月、性别。有成员方法以显示姓名、年龄和性别。
import java.text.SimpleDateFormat;
import java.util.Date;
class Person{
public Person(String name, Date birthday, boolean isMale){
super();
this.name= name;
this.birthday= birthday;
this.isMale= isMale;
}
private String name;
private Date birthday;
private boolean isMale;
public void showName(){
System.out.println("姓名:"+ name);
}
public void showBirthday(){
System.out.println("出生年月日:"
+ new SimpleDateFormat("yyyy年MM月dd日").format(birthday));
}
public void showSex(){
System.out.print("性别:");
if(isMale){
System.out.println("男");
} else{
System.out.println("女");
}
}
}
2、声明一个接口,将一个人的出生年份转换成年龄
public interface DateUtil{
public int DateToAge();
}
3、在类Shapearea中声明三个同名方法求圆、矩形和三角形的面积(三个方法有不同的参数)。
public class Shapearea{
static final double PI=3.1415926;
public static double getArea(double r){
return r*r*PI;
}
public static double getArea(double x,double y){
return x*y;
}
public static double getArea(double a,double b,double c){
double l=a+b+c;
return Math.sqrt(l*(l-c)*(l-b)*(l-a));
}
}
4、已知某一角度的值,求它的正弦值。
Math.sin(a);
5、由键盘输入两个字符串“10”和“20”,将他们转换成整数,然后计算并输出这两个数的和。
Scanner sc=new Scanner(System.in);
String str1=sc.next();
String str2=sc.next();
Integer int1=new Integer(str1);
Integer int2=new Integer(str2);
System.out.println("结果是:"+int1+int2);
6绘图
7、绘制一圆角矩形、实心普通矩形,分别使用不同的颜色。
8、绘制一多边形(至少4个顶点)和一空心弧线(长度和角度自定)。颜色自定。
9、绘制一折线(至少六个顶点)和一正方形。颜色自定。
10、创建一个String类的对象Str1和Str2,判断Str2是否str1的子串。如果是,输出str1中在子串str2后的字符串。
Scanner sc=new Scanner(System.in);
String str1=sc.next();
String str2=sc.next();
if(str1.contains(str2)){
System.out.println(str1.split(str2, 2)[1]);
}
11、声明一个矩形类Rectangle,其中有多个构造方法。用不同的构造方法创建对象,并输出矩形的周长和面积。
12、完成一小应用程序,实现用CardLayout布局摆放三个按钮(每张卡片上一个按钮,点击按钮换卡片。)
JAVA程序设计题解答,加分50
/**
*接口Max
*本类中有两个方法
*@author pisa
*/
public interface Max{
public double twoMax(double a,double b);//两个数中最大
public double threeMax(double a,double b,double c);//三个数中最大
}
/**
* Test类实现了Max接口,并且实现了Max接口中的所有方法。
*@author pisa
*/
public class Test implements Max{
public double threeMax(double a, double b, double c){
if(c>=twoMax(a,b))
return c;
else
return twoMax(a,b);
}
public double twoMax(double a, double b){
if(a>=b)
return a;
else
return b;
}
public static void main(String[]args){
Test t= new Test();
System.out.println(t.twoMax(1.2, 5));
System.out.println(t.threeMax(34, 78,-23));
}
}
/**
* Staff该java Bean有4个职员基本的信息
*并且提供了设置和得到该职员信息的基本方法
*@author pisa
*/
public class Staff{
private String name;//职员姓名
private Integer age;//职员年龄
private String sex;//职员性别
private String position;//职员职位
public String getName(){
return name;
}
public void setName(String name){
this.name= name;
}
public Integer getAge(){
return age;
}
public void setAge(Integer age){
this.age= age;
}
public String getSex(){
return sex;
}
public void setSex(String sex){
this.sex= sex;
}
public String getPosition(){
return position;
}
public void setPosition(String position){
this.position= position;
}
}
您的进步是我最大的动力和满足,如果您对我的回答很满意,请给我多加分。谢谢!
JAVA语言程序设计题目,求高人解答
3-1
有main方法的就是主类,
错误1:String[] args的String大写,并且中间有空格
保存在MyJavaClass名字的文件里
错误2:System.out.println("程序结束。");只能写在main方法里
3-2.标识符只能由字母或数字和_和$构成,不能以数字开头,只能以字母或_或$开头,并且不能是关键字
1 2 5对 3错:不能以数字开头,4错:只能由字母或数字和_和$构成
3-8
2
2
false
2
关于java程序设计课后答案,java程序设计第四版辛运帏的介绍到此结束,希望对大家有所帮助。