一道JAVA編程題 求大神解答 過程詳細的
定義接口Worker,有一個方法login()實現打卡功能。rnrn定義該接口實現類ChinaWorker,給出login()的具體實現,只需輸出“我來了!!”即可。public interface Worker{
void login();
}
class ChinaWorker implments Worker{
public void login(){
system.out.println("我來了!!")
}
}
/**
* 接口
*/
public interface Worker {
/**
* 接口方法
*/
public void login();
}
/**
* 實現專worker接口
*/
public class ChinaWorker implements Worker {
/**
* 實現接口方法.
*/
public void login() {
System.out.println("我來了!!屬");
}
}
一道JAVA編程題,求大神解答
鍵盤輸入一個數字之后開始執行循環輸出隨機數到控制臺n要求:有輸入提示語、隨機數、控制臺輸出n提示:hasNext()方法是判斷是否有鍵盤輸入值有分就會有答案
一道java編程題求大神指點
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
public class AccessTask implements Count {
AtomicLong count = new AtomicLong(0);
CopyOnWriteArrayList<Long> list = new CopyOnWriteArrayList<>();
//hr接口多線程訪問
@Override
public void hr() {
count.getAndAdd(1);
System.out.println(Thread.currentThread().getName() +" 訪問次數:"+count);
list.add(System.currentTimeMillis());
}
@Override
public DateState state() {
DateState dateState = new DateState();
int num = 0;
long now = System.currentTimeMillis();
long s1 = TimeUnit.SECONDS.toMillis(10);
long s2 = TimeUnit.SECONDS.toMillis(60);
long m1 = TimeUnit.MINUTES.toMillis(10);
long m2 = TimeUnit.MINUTES.toMillis(60);
if (list.size()>0) {
for (int i = list.size()-1; i >-1 ; i--) {
long time = now - list.get(i);
num++;
if (time<s1) {
dateState.setLast10Second(num);
}
if (time < s2) {
dateState.setLast60Second(num);
}
if (time<m1) {
dateState.setLast10Minute(num);
}
if (time < m2) {
dateState.setLast60Minute(num);
} else {
break;
}
}
}
System.out.println(dateState);
return dateState;
}
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class TestCount {
public static void main(String[] args) {
AccessTask accessTask = new AccessTask();
ExecutorService pool = Executors.newFixedThreadPool(20);
for (int i = 0; i < 100; i++) {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
pool.execute(new Runnable() {
@Override
public void run() {
accessTask.hr();
accessTask.state();
}
});
}
pool.shutdown();
}
}
我可以幫你寫,私聊我發給你吧
有一道Java編寫程序的題求大神解答,萬分感謝。
3、編寫程序,要求如下:rn (1)根據下面的要求實現學生類Student: rn Student類的成員變量: rn id (私有, 字符串型) ; //存放學號rn name (私有,字符串型) ; //存放姓名rn Student類的方法成員rn Student(String i,String n) 構造方法,創建Student對象時將學號初始化為i,將姓名初始化為n rn String getId() 獲得學生的學號rn String getName() 獲得學生的姓名rn void disp() 將學生的學號、姓名輸出 rn (2)繼承上題中的Student類,派生本科生類Undergraduate,要求如下:rn Undergraduate類的成員變量: rn maths (私有,整型) ; //存放數學成績rn computer (私有,整型) ; //存放計算機成績rn Undergraduate類的方法成員: rn Undergraduate(String i,String n,int m,int c)構造方法,創建Undergraduate對象時將學號初始化為i,將姓名初始化為n,將數學成績初始化為m,將計算機成績初始化為crn int getMaths() 獲得數學成績rn int getComputer() 獲得計算機成績rn void disp() 將本科生的學號、姓名、數學成績、計算機成績及成績等級輸出 rn (3)利用類Undergraduate創建一個學號為101,姓名為張三,數學成績為85,計算機成績為90的Undergraduate對象,并調用disp方法將該對象的學號、姓名、數學成績、計算機成績輸出。public class Student {
private String id;
private String name;
public Student(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void disp() {
System.out.println(this.id+" "+this.name);
}
}
package com.my.student;
public class Undergraduate extends Student {
private int maths ;
private int computer;
public Undergraduate(String id, String name, int maths, int computer) {
super(id, name);
this.maths = maths;
this.computer = computer;
}
public int getMaths() {
return maths;
}
public int getComputer() {
return computer;
}
public void disp() {
System.out.println(super.getId()+" "+super.getName()+ " "+this.getMaths()+" "+this.getComputer());
}
public static void main(String[] args){
Undergraduate undergraduate = new Undergraduate("101","張三",85,90);
undergraduate.disp();
}
}
請采納!!
求解一道java編程題,大神幫幫忙
題目如圖
public class Human {
public String name;
public int age;
// 無參構造
public Human() {
super();
}
// 帶參構造
public Human(String name, int age) {
super();
this.name = name;
this.age = age;
}
public void walk() {
System.out.println(name + "正在行走");
}
}
===============上面是Human類===============
public class Child extends Human {
private String schoolName;
// 有參構造
public Child(String name, int age, String schoolName) {
super(name, age);// 用父類的構造方法
this.schoolName = schoolName;
}
public void study() {
System.out.println(super.name + "在" + schoolName + "認真地學習");
}
@Override
public void walk() {
super.walk();
}
}
===============上面是Child類===============
public class Demo {
public static void main(String[] args) throws Exception {
Child child = new Child("小明", 9, "希望小學");
child.study();
child.walk();
}
}
===============上面是Demo類===============
Demo類執行情況
===============上面是Demo類的執行情況===============
相關推薦:
網頁版權信息(網頁版權怎么寫)
注冊商標查詢(注冊商標該怎么查詢)
商標使用許可(商標使用許可的種類有哪些)
表演者享有哪些權利(表演者對其表演依法享有什么權利呢)
商標的侵權處罰(商標侵權解決辦法)