導航:首頁 > 編程語言 > java編程作業答案

java編程作業答案

發布時間:2022-07-12 20:13:28

❶ 求一個java編程題的答案

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class Student {

private String id;

private String name;

private boolean isMale;

private Date birth;
public Student() {
super();
}
public Student(String id, String name, boolean isMale, Date birth) {
super();
this.id = id;
this.name = name;
this.isMale = isMale;
this.birth = birth;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isMale() {
return isMale;
}
public void setMale(boolean isMale) {
this.isMale = isMale;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", isMale=" + isMale + ", birth=" + birth + "]";
}
}
public class StudentTest {

public static void main(String[] args) throws ParseException {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");

Student stu = new Student("00001", "Tom", true, dateFormat.parse("2000-01-01"));
System.out.println(stu);
}
}

❷ Java編程作業 多線程Web伺服器 小女子跪求答案

1、創建一個動物集合,插入動物園中有的幾種動物(請給出10種)
2、一次性輸出內容
3、使用iterator遍歷集合中所有內容
4、將集合內容轉存儲於一個數字內,並在數組中進行排序

只列舉了2種動物,自己再添加
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/**
*
* @author Administrator
*/
interface Animal {
public String toString();

}

class Cat implements Animal,Comparable<Animal> {
public String name;
public Cat(){
super();
name = "貓";

}

public String toString(){
return name;
}

@Override
public int compareTo(Animal o) {
if(this.toString().compareTo(o.toString())==-1){
return -1;
}else if(this.toString().compareTo(o.toString())==0){
return 0;
}else
return 1;
}
}
class Dog implements Animal,Comparable<Animal> {
public String name;
public Dog(){
super();
name="狗";
}
public String toString(){
return name;
}

@Override
public int compareTo(Animal o) {
if(this.toString().compareTo(o.toString())==-1){
return -1;
}else if(this.toString().compareTo(o.toString())==0){
return 0;
}else
return 1;
}
}
public class Demo8 {
public static void main(String[] args){

// 創建一個動物集合,插入動物園中有的幾種動物
Collection<Animal> col = new ArrayList<Animal>();
col.add(new Cat());
col.add(new Dog());
col.add(new Cat());
// 一次性輸出內容
System.out.println(Arrays.toString(col.toArray()));
//使用iterator遍歷集合中所有內容
//並將集合內容轉存儲於一個數組內
Iterator<Animal> it = col.iterator();
int n = 0;
Animal[] an = new Animal[3];
while(it.hasNext()){
Animal temp = (Animal)it.next();
System.out.println("使用iterator遍歷集合中所有內容:"+temp);
an[n++]=temp;
}
//並在數組中進行排序
Arrays.sort(an);
System.out.println(Arrays.toString(an));

}

❸ java編程題 答案完整追加50分

public abstract class DepositBook {
protected String account;// 表示存摺賬號
protected double money;// 表示存摺余額
protected String name;// 表示賬戶名

public DepositBook(String account, String name, double money) {

this.account = account;
this.name = name;
this.money = money;
}

public abstract void depositMoney(double addMoney); // 代表存款行為

public abstract double drawMoney(double moneyCount); // 代表取款行為

public void printInfo() {
System.out.println("姓名:" + name);
System.out.println("賬號:" + account);
System.out.println("余額:" + money);
}

}

====================

public class DemandDepositBook extends DepositBook {

public DemandDepositBook(String account, String name, double money) {
super(account, name, money);
}

@Override
public void depositMoney(double addMoney) {
money += addMoney;

}

@Override
public double drawMoney(double moneyCount) {
if (money > moneyCount) {
money -= moneyCount;
return moneyCount;
}
money = 0;
return money;
}

}

❹ java編程作業,求答案··

class Student
{
private String name;
private String sex;
private int age;
private String grade;

public Student()
{
this("","",0,"");
}
public Student(String name,String sex,int age,String grade)
{
this.name=name;
this.sex=sex;
this.age=age;
this.grade=grade;
}
public void setName(String name)
{this.name=name;}
public void setSex(String sex)
{this.sex=sex;}
public void setA(int age)
{this.age=age;}
public void setGrade(String grade)
{this.grade=grade;}

public String toString()
{
return name+","+sex+","+age+","+grade;
}
}

另外一類:
public class X
{
public static void main(String arg[])
{
Student student=new Student();
System.out.println(student);
}
}

❺ java編程題求答案

原來寫的一個socket 例子,你可以做參考
package com.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
private static final int PORT = 3600;
private List<Socket> mList = new ArrayList<Socket>();
private ServerSocket server = null;
private ExecutorService mExecutorService = null; // thread pool

public static void main(String[] args) {
new Main();
}

public Main() {
try {
server = new ServerSocket(PORT);
mExecutorService = Executors.newCachedThreadPool(); // create a
// thread pool
System.out.print("server start ...");
Socket client = null;
while (true) {
client = server.accept();
mList.add(client);
mExecutorService.execute(new Service(client)); // start a new
// thread to
// handle the
// connection
}
} catch (Exception e) {
e.printStackTrace();
}
}

class Service implements Runnable {
private Socket socket;
private BufferedReader in = null;
private String msg = "";

public Service(Socket socket) {
this.socket = socket;
try {
in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
msg = "user" + this.socket.getInetAddress() + "come toal:"
+ mList.size();
this.sendmsg();
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public void run() {
// TODO Auto-generated method stub
try {
while (true) {
if ((msg = in.readLine()) != null) {
if (msg.equals("exit")) {
System.out.println("ssssssss");
mList.remove(socket);
in.close();
msg = "user:" + socket.getInetAddress()
+ "exit total:" + mList.size();
socket.close();
this.sendmsg();
break;
} else {
msg = socket.getInetAddress() + ":" + msg;
this.sendmsg();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

}

public void sendmsg() {
System.out.println(msg);
int num = mList.size();
for (int index = 0; index < num; index++) {
Socket mSocket = mList.get(index);
PrintWriter pout = null;
try {
pout = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(mSocket.getOutputStream())),
true);
pout.println(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
}

❻ 求JAVA語言程序設計作業答案

3、C;4、A;6、A;7、A;8、D;12、A;13、B;14、B;17、A;18、D;19、D;20、A;
4題:A很明顯是錯誤的,java程序在運行前需要編譯成位元組碼文件,才能運行。

14題:在Java語言中,標識符是以字母、下劃線或美元符開頭,由字母、數字、下劃線或美元符組成的字元串。標識符區分大小寫,長度沒有限制。除以上所列幾項之外,標識符中不能含有其他符號,也不允許插入空格。

17題:向main方法傳入的是三個參數接收後args[]={"aaa","bb","c"}
int k1=args.length;//得到數組元素個數,為3
int k2=args[1].length();//得到數組中下標為1的元素字元數(即第二個元素)

18題:String s1="AbcD"; String s2=s1.toLowerCase(); 作用是把字元串全部轉為小寫,所以選D

19題:函數重載定義 1:保持相同的功能,並且有相同的函數名
2、重載方式為:返回值類型不同,形參個數不同同,形參類型不同。
在滿足一的前提下,二中三個條件任意一個,或其中多個的任意組合都是重載
20題:BB繼承了AA並且重寫了Show()方法。父類AA實例化了a,所以a.Show()調用的是父類中的Show方法,顯示:我喜歡Java!子類BB實例化了b,所以b.Show()調用子類BB中的Show方法,顯示:我喜歡C++!

❼ 跪求Java編程題答案,我一點都不會~~~(>_<)~

(1)
import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);
System.out.println("Please enter...");
String name = s.next();
String studentId = s.next();
String specialty = s.next();

System.out.println("姓名:"+name+",學號:"+studentId+" ,專業: "+specialty);
}
}
--------------------------------------
--------------------------------------
(2)
import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);
System.out.println("Please enter...");
int n = s.nextInt();
double sum = 0;
for(int i=1;i<=n;i++){
if(i%2==1){
sum += 1.00/(2*i-1);
}else{
sum -= 1.00/(2*i-1);
}
}
System.out.println("PI = "+4*sum);
}
}

❽ java編程作業,求答案

import java.awt.*;
import java.awt.event.*;

public class TestFrame {
public static void main(String[] args) {
Frame frame = new Frame("姓名:xxx");
frame.setLayout(new BorderLayout());
Panel panel1 = new Panel();
Panel panel2 = new Panel();
TextField tf = new TextField(20);
panel1.add(tf);
panel2.setLayout(new GridLayout(4,4));

panel2.add(new Button("0"));
panel2.add(new Button("1"));
panel2.add(new Button("2"));
panel2.add(new Button("3"));
panel2.add(new Button("4"));
panel2.add(new Button("5"));
panel2.add(new Button("6"));
panel2.add(new Button("7"));
panel2.add(new Button("8"));
panel2.add(new Button("9"));
panel2.add(new Button("A"));
panel2.add(new Button("B"));
panel2.add(new Button("C"));
panel2.add(new Button("D"));
panel2.add(new Button("E"));
panel2.add(new Button("F"));

frame.add(panel1, BorderLayout.NORTH);
frame.add(panel2, BorderLayout.SOUTH);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
}
}

閱讀全文

與java編程作業答案相關的資料

熱點內容
erp是什麼伺服器 瀏覽:182
python中tmp 瀏覽:19
說明wpf加密過程 瀏覽:142
java讀取list 瀏覽:702
iis7gzip壓縮 瀏覽:39
有什麼安卓機打吃雞好 瀏覽:597
三星u盤加密狗 瀏覽:473
php函數的返回值嗎 瀏覽:586
國企穩定程序員 瀏覽:328
編程貓如何使用教程視頻 瀏覽:218
安卓遠端網頁如何打日誌 瀏覽:218
壓縮flash大小 瀏覽:993
解壓的玩具教程可愛版 瀏覽:366
哪個求職app比較靠譜 瀏覽:888
java的讀法 瀏覽:59
nod32區域網伺服器地址 瀏覽:1003
數碼科技解壓 瀏覽:236
新網的雲伺服器管理界面復雜嗎 瀏覽:367
無人聲解壓強迫症視頻 瀏覽:573
計算機編譯運行 瀏覽:640