
===============================第一题==============================
import javaappletApplet;
import javaawtColor;
import javaawtLabel;
public class test extends Applet {
private Label label;
@Override
public void init() {
label=new Label("欢迎来到java世界!");
labelsetBackground(ColorBLUE);
setBackground(ColorPINK);
add(label);
}
}
===============================第二题==============================
因为没图,所以自己设计的界面
import javaawtBorderLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJScrollPane;
import javaxswingJTextArea;
public class test implements ActionListener {
private JFrame frame;
private JLabel label;
private JTextArea jt;
private JScrollPane jsp;
private JButton show;
public test() {
frame=new JFrame("Test");
label=new JLabel("显示内容");
jt=new JTextArea(10,20);
jsp=new JScrollPane(jt);
show = new JButton("显示给定内容");
JPanel panel=new JPanel();
paneladd(label);
paneladd(show);
frameadd(jsp,BorderLayoutNORTH);
frameadd(panel,BorderLayoutSOUTH);
showaddActionListener(this);
show();
}
public void show(){
framesetLocation(200, 200);
framesetSize(300, 260);
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
framesetVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
labelsetText(jtgetText());
}
public static void main(String[] args) {
new test()show();
}
}
package employee;
public class Employee {
//员工私有属性
private String name; //员工姓名
private int age; //员工年龄
private String position; //员工职位
private int salary; //工资
/
给所有的属性指定初始值
@param name
@param age
@param position
@param salary
/
public Employee(String name,int age,String position,int salary){
thisname = name;
thisage =age;
thisposition = position;
thissalary = salary;
}
/
给name属性赋值
@param name
/
public void setName(String name){
thisname = name;
}
public String getName() {
return name;
}
/
给age属性赋值
@param age
/
public void setAge(int age){
if(age<18){
thisage=18;
Systemoutprintln("当年龄无效时,默认为18");
}else{
thisage =age;
}
}
public int getAge() {
return age;
}
/
给position属性赋值
@param position
/
public void setPosition(String position){
if(positionequals("售后服务") || positionequals("销售员") ){
thisposition = position;
}else{
thisposition = "售后服务";
Systemoutprintln("输入不符合要求,默认为售后服务");
}
}
public String getPosition() {
return position;
}
/
给员工工资赋值
@param salary
/
public void setSalary(){
if(age>=18 && age<=20){
thissalary = 1000;
}else if(age>=21 && age<=25){
thissalary = 1500;
}else if(age>=26 && age<=30){
thissalary = 2000;
}else if(age>=31 && age<=40){
thissalary = 3000;
}else if(age>=41 && age<=50){
thissalary = 3500;
}else if(age>=51){
thissalary = 4000;
}else{
Systemoutprintln("没有设置年龄或者年龄无效");
}
}
public int getSalary() {
return salary;
}
}
测试类
package employee;
import javautilScanner;
public class TestEmployee {
public static void main(String[] args){
Employee emp1 = new Employee(null, 0, null, 0) ;
Scanner sc = new Scanner(Systemin);
Systemoutprintln("请输入第一个员工姓名");
//获取输入的名字
String name1 = scnext();
emp1setName(name1);
Systemoutprintln("请输入第一个员工年龄");
//获取输入的年龄
int age1 = scnextInt();
emp1setAge(age1);
Systemoutprintln("请输入第一个员工职位");
//获取输入的职位
String position1 = scnext();
emp1setPosition(position1);
emp1setSalary();
Systemoutprintln("---------------------------------");
Systemoutprintln("员工1姓名为:"+emp1getName());
Systemoutprintln("年龄:"+emp1getAge());
Systemoutprintln("工作为:"+emp1getPosition());
Systemoutprintln("工资为:"+emp1getSalary());
}
}
第一次回答问题,玩玩而已但是还是希望采纳
interface PatCarel {
public void raise();
public void play();
}
class Worker implements PatCarel {
String name;
String sex;
Worker(String name,String sex) {
thisname = name;
thissex = sex;
}
public void raise() {
Systemoutprintln("喂养小猫");
}
public void play() {
Systemoutprintln("no time");
}
}
class Farmer implements PatCarel {
int age;
int income;
Farmer (int age,int income) {
thisage = age;
thisincome = income;
}
public void raise() {
Systemoutprintln("喂养小狗");
}
public void play() {
Systemoutprintln("no money");
}
}
class Officer implements PatCarel {
int income;
int age;
Officer(int income,int age) {
thisincome = income;
thisage = age;
}
public void raise() {
Systemoutprintln("喂养小鸟");
}
public void play() {
Systemoutprintln("have money");
}
}
public class TestInterface {
public static void main(String[] args) {
PatCarel p = new Worker("Tom","male");
PatCarel m = new Farmer(66,10000);
PatCarel q = new Officer (100000,60);
praise(); pplay() ;
mplay() ;
qraise(); qplay() ;
}
}
楼主一定看了马士兵的视频教程吧
以上就是关于java面向对象程序设计期末考试编程题!急!!!全部的内容,包括:java面向对象程序设计期末考试编程题!急!!!、有一道 java面向对象编程题 求大家帮我写一下 面向对象基础 看到迷茫、java面向对象课堂习题(菜鸟级).等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)