《Java语言程序设计基础篇》第六版的练习题和编程题答案

《Java语言程序设计基础篇》第六版的练习题和编程题答案,第1张

哥们我给你写完了,耽误了我半个小时的时间啊!你直接运行就可以了

import javaawtBorderLayout;

import javaawtFlowLayout;

import javaawteventActionEvent;

import javaawteventActionListener;

import javautilCalendar;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJTextField;

public class Constellation implements ActionListener{

private JFrame frame = null;

private JTextField year = null;

private JTextField month = null;

private JTextField day = null;

private JLabel label1 = null;

private JLabel label2 = null;

private JLabel label3 = null;

private JPanel panel1 = null;

private JPanel panel2 = null;

private JButton button = null;

private JTextField output = null;

public static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇",

"马", "羊" };

public static final String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座",

"狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };

public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22,

22 };

/

根据日期获取生肖

@return 11

/

public static String date2Zodica(Calendar time) {

return zodiacArr[timeget(CalendarYEAR) % 12];

}

/

根据日期获取星座

@param time

@return

/

public static String date2Constellation(Calendar time) {

int month = timeget(CalendarMONTH);

int day = timeget(CalendarDAY_OF_MONTH);

if (day < constellationEdgeDay[month]) {

month = month - 1;

}

if (month >= 0) {

return constellationArr[month];

}

// default to return 魔羯

return constellationArr[11];

}

public Constellation(){

frame = new JFrame("计算生肖,星座");

year = new JTextField("",3);

month = new JTextField("",3);

day = new JTextField("",3);

label1 = new JLabel("请输入年份:");

label2 = new JLabel(",请输入月份:");

label3 = new JLabel(",请输入日期:");

button = new JButton("查看结果");

buttonaddActionListener(this);

panel1 = new JPanel();

panel1setLayout(new FlowLayout(FlowLayoutCENTER));

panel1add(label1);

panel1add(year);

panel1add(label2);

panel1add(month);

panel1add(label3);

panel1add(day);

panel1add(button);

framesetLayout(new BorderLayout());

frameadd(panel1,BorderLayoutNORTH);

panel2 = new JPanel();

output = new JTextField("",40);

panel2add(output,JPanelCENTER_ALIGNMENT);

frameadd(panel2,BorderLayoutCENTER);

framesetSize(500, 100);

framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

framesetVisible(true);

}

public void actionPerformed(ActionEvent e) {

outputsetText("");

int y = IntegerparseInt(yeargetText());

int m = IntegerparseInt(monthgetText());

int d = IntegerparseInt(daygetText());

Calendar calendar = CalendargetInstance();

calendarset(CalendarYEAR, y);

calendarset(CalendarMONTH, m);

calendarset(CalendarDAY_OF_MONTH, d);

String zodica = date2Zodica(calendar);

String constellation = date2Constellation(calendar);

String str = "您输入的日期为:"+y+"年-"+m+"-月"+d+"日,得到的生肖:"+zodica+",星座:"+constellation;

outputsetText(str);

}

//testcode

public static void main(String[] args) {

new Constellation();

}

}

public class Car1 extends Car {

public String manufacturer;

public Car1(String color, String style, String manufacturer) {

super(color, style);

thismanufacturer = manufacturer;

}

public Car1(String color) {

thiscolor = color;

thismanufacturer = "上海大众";

}

@Override

public String toString() {

return "Car1 [manufacturer=" + manufacturer + ", color=" + color + ", style=" + style + "]";

}

public Car1() {

super();

}

public static void main(String[] args) {

Car1 a = new Car1();

Car1 b = new Car1("黑色", "卡车", "斯泰尔");

Car1 c = new Car1("白色");

Systemoutprintln(atoString());

Systemoutprintln(btoString());

Systemoutprintln(ctoString());

}

}

class Car {

public String color;

public String style;

public Car() {

thiscolor = "red";

thisstyle = "car";

}

public Car(String color, String style) {

thiscolor = color;

thisstyle = style;

}

public void showColor() {

Systemoutprintln("颜色   " + thiscolor);

}

public void showStyle() {

Systemoutprintln("型号   " + thisstyle);

}

}

>

以上就是关于《Java语言程序设计基础篇》第六版的练习题和编程题答案全部的内容,包括:《Java语言程序设计基础篇》第六版的练习题和编程题答案、java程序设计,求答案、求《Java程序设计教程》 牛晓太主编 清华大学出版社出版 课后习题答案 ……急需等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9968591.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存