十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
//参考下面的代码自己写一个吧。对自己有好处
创新互联公司一直在为企业提供服务,多年的磨炼,使我们在创意设计,网络营销推广到技术研发拥有了开发经验。我们擅长倾听企业需求,挖掘用户对产品需求服务价值,为企业制作有用的创意设计体验。核心团队拥有超过十载以上行业经验,涵盖创意,策化,开发等专业领域,公司涉及领域有基础互联网服务重庆服务器托管、重庆APP开发公司、手机移动建站、网页设计、网络整合营销。
package Example5_1;
public class Example5_1
{
public static void main(String args[])
{
Telephone2 t=new Telephone2("TCL","123123123",100);
t.setRate(0.2);
t.setDialledTime(150);
t.display();
t.callCost();
t.recharge(50);
}
}
class Telephone2
{
private String brand;
private String number;
private double dialledTime;
private double rate;
private double balance;
public Telephone2(String brand,String number,double balance)
{
this.brand=brand;
this.number=number;
this.balance=balance;
}
public void setBrand(String brand)
{
this.brand=brand;
}
public String getBrand()
{
return brand;
}
public void setNumber(String number)
{
this.number=number;
}
public String getNumber()
{
return number;
}
public void setDialledTime(double dialledTime)
{
this.dialledTime=dialledTime;
}
public double getDialledTime()
{
return dialledTime;
}
public void setRate(double rate)
{
this.rate=rate;
}
public double getRate()
{
return rate;
}
public double getBalance()
{
return balance;
}
public void recharge(double cost)
{
balance=balance+cost;
System.out.println("充值后的余额:"+balance);
}
public void callCost()
{
double callcost=dialledTime*rate;
balance=balance-callcost;
System.out.println("话费:"+callcost);
System.out.println("余额:"+balance);
}
public void display()
{
System.out.println("电话品牌:"+brand+"电话号码:"+number);
System.out.println("通话时间:"+dialledTime+"费率"+rate);
}
}
public class B
public static void main(String[] args)
SetTeacher set = new HashSetTeacher()
IteratorTeacher iterator = set.iterator()
while (iterator.hasNext())
System.out.println
class Teacher
private int id
public Teacher()
public Teacher(int id, String name, int age, boolean sex)
this.sex = sex
HashSet类
实现了Set接口,由哈希表(实际上是一个HashMap实例)支持。它不保证Set的迭代顺序,特别是它不保证该顺序持久不变,此类允许使用null元素。添加到由HashSet类实现的Set集合中的对象。需要重新实现equal()方法。
从而保证插入集合中对象的标识的唯一性。HashSet类实现了Set接口,由哈希表(实际上是一个HashMap实例)支持。它不保证Set的迭代顺序,特别是它不保证该顺序持久不变。
给你写的例子 你可以仿照写Director类 ,Director是 extends Teacher implements IPerson ,你可以练习下
IPerson接口:
--------------------------------------
package com.demo;
/**
* p
* Description: 接口
* /p
*
*/
public interface IPerson {
public void print();
}
------------------------------------------------------
Teacher类:
package com.demo;
/**
* p
* Description:老师类
* /p
*/
public class Teacher implements IPerson {
private String ID;//工号ID,
private String name;//姓名name,
private double salary;//工资salary,
private String job;//职务job;
public void Tesacher() {
}
public Teacher(String ID, double salary, String job) {
this.ID = ID;
this.salary = salary;
this.job = job;
}
public Teacher(String ID, String name, double salary, String job) {
this.ID = ID;
this.name = name;
this.salary = salary;
this.job = job;
}
/**
* @return the iD
*/
public String getID() {
return ID;
}
/**
* @param iD the iD to set
*/
public void setID(String iD) {
ID = iD;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the salary
*/
public double getSalary() {
return salary;
}
/**
* @param salary the salary to set
*/
public void setSalary(double salary) {
this.salary = salary;
}
/**
* @return the job
*/
public String getJob() {
return job;
}
/**
* @param job the job to set
*/
public void setJob(String job) {
this.job = job;
}
/* (non-Javadoc)
* @see com.demo.IPerson#print()
*/
public void print() {
System.out.println("老师工号:" + getID());
System.out.println("老师姓名:" + getName());
System.out.println("老师职务:" + getJob());
System.out.println("老师工资:" + getSalary());
}
}
-----------------------------------------------------
Test类:
package com.demo;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
IPerson teacher = new Teacher("1", "张三丰", 20000, "太极");
teacher.print();
}
}
描述教师和学生的关系
/**教师类*/
public class Teacher{
private int id;//教工号
private String name;//姓名
}
/**学生类*/
public class Student{
private int id;//学号
private String name;//姓名
}
/**课程类,描述教师和学生的关系*/
public class Course {
private int id;//课程号
private String name;//名称
private Teacher teacher;//教授课程的教师
ListStudent students;//学习课程的学生
}
教室和课程的对应关系
/**教室类*/
class ClassRoom{
private int id;//教室编号
private String name;//教室名称
}
/**排课信息*/
public class CourseArrangement {
private Date date;//授课日期
private String startTime;//授课开始时间,格式为“HH:mm:ss”
private String endTime;//授课结束时间,格式为“HH:mm:ss”
private Course course;//课程
private ClassRoom classRoom;//教室
}