java题目 ,那位高手帮忙做一下,谢谢了
第6问的文字问题描述不是很理解。稍微写了下。
public class Student {
//无参构造函数
public Student(){}
//有参构造函数
public Student(String no, String name, int age){
this.no = no;
this.age = age;
this.name = name;
}
private String no;//学号
private String name;//名称
private int age;//年龄
//-----------------------------Set 跟 Get 方法 start ------------------
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
//-----------------------------Set 跟 Get 方法 end ------------------
//重写toString方法
@Override
public String toString() {
return "我的名字叫:".concat(name).concat(",学号是:").concat(no).concat(",今年").concat(age+"岁了!");
}
//计算学生总数的方法(大概多此一举)
public static int getCount(List list){
return list.size();
}
//程序入口
public static void main(String[] args) {
//保存多个学生对象的集合
List list = new ArrayList();
//学生对象1
Student stu = new Student();
stu.setAge(18);
stu.setName("小明");
stu.setNo("00001");
System.out.println(stu.toString());
list.add(stu);
//学生对象2
stu = new Student("00002", "小花", 22);
System.out.println(stu.toString());
list.add(stu);
System.out.println("共有学生人数:"+getCount(list)+"人");//输出学生对象集合总数
}
}
public interface Computer {
public void poweron();
}
class PC implements Computer{
public void poweron() {
System.out.println("PC实现Computer接口");
}
}
class Laptop implements Computer{
public void poweron() {
stem.out.println("Laptop实现Computer接口");
}
}
public class Test {
public static void main(String[] args) {
Computer pc=new PC();
Computer laptop=new Laptop();
pc.poweron();
laptop.poweron();
}
}
public class Dog {
private String name;
private String color;
private int weight;
private int age;
public Dog() {
}
public Dog(String name, String color, int weight, int age) {
this.name = name;
this.color = color;
this.weight = weight;
this.age = age;
}
public String toString() {
String returnStr = "Dog name:" + this.name + " Dog color:" + this.color
+ " Dog weight:" + this.weight + " Dog age" + this.age;
return returnStr;
}
public void shoot() {
System.out.println("This is " + this.name +" shoot!");
}
public void bite() {
System.out.println("This is " + this.name + " bite");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public static void main(String[] args) {
Dog dog1 = new Dog("Dog1", "white", 5, 4);
Dog dog2 = new Dog("Dog2", "red", 6 , 4);
dog1.shoot();
dog2.bite();
}
}
已经试验过了
package dog;
public class Dog { private String dogName; private String dogColor; private int dogAge;
public Dog() {
}
public Dog(String name, String color, int age) { dogName = name; dogColor = color; dogAge = age; }
private void Away() { System.out.println("汪汪"); }
private void Bite() { System.out.println("撕咬"); }
public String toString() { return "名字:" + this.dogName + "颜色:" + this.dogColor + "年龄:" + this.dogAge; }
public static void main(String[] args) { Dog dog1 = new Dog("哈巴狗", "棕色", 1); System.out.println(dog1.toString()); dog1.Away();
Dog dog2 = new Dog("牧羊犬", "黑色", 1); System.out.println(dog1.toString()); dog2.Bite(); }
}
run结果:
名字:哈巴狗颜色:棕色年龄:1汪汪名字:哈巴狗颜色:棕色年龄:1撕咬
public class Dog
{
private String name;
private String color;
private int age;
private double body;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getColor()
{
return color;
}
public void setColor(String color)
{
this.color = color;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public double getBody()
{
return body;
}
public void setBody(double body)
{
this.body = body;
}
public Dog()
{
System.out.println("dog is coming");
}
public Dog(String name, String color, int age, double body)
{
super();
this.name = name;
this.color = color;
this.age = age;
this.body = body;
}
public String toString()
{
return this.getName()+":"+this.getAge();
}
public void yao()
{
System.out.print(this.getName()+"咬了");
}
public void jiao()
{
System.out.print(this.getName()+"叫了");
}
public final static void main()
{
Dog d1 = new Dog();
d1.setName("狗1");
d1.yao();
Dog d2 = new Dog();
d2.setName("狗2");
d2.jiao();
}
}
庄桦世扶:[答案] 给你个例子,手写的,没测试1.public Compu(int a, int b) public Compu(int a) 2.假设你要求出所有四则运算的值int[] calulate(int a, int b) { int[] result = new int[4]; result[0] = a+b; result[1] = a-b; result[2] = a*b; try { result[3] = a/b; } catch (ArithmeticException...
巴马瑶族自治县18526984934: 急急急!!!请java高手进来一下,题目很基础的,帮我做一下!!先谢了啊 - ?
庄桦世扶: 1,true 2,false,一般使用final关键字 3,true,main是入口方法,入口方法当然只能有一个 4,true 5,true,8大基本数据类型:short,int ,long,float,double,byte,char,boolean 6,true,一个父类实例化后,可以表现为多个子类对象 7,true,这个是jdk高版本以后出现的泛型,用泛型约束的,可省略强制类型转换 8,false,数组的属性有length,不需要用length()取得 9,true,默认的字符编码 10,true,可以出现,int[],也可以出现String[]
巴马瑶族自治县18526984934: 编程题目JAVA,求大神高手帮忙解答谢谢! - ?
庄桦世扶: int i = 80000; int y = 1; while(ii = i*1.25; y++; } System.out.printf(2006+y);
巴马瑶族自治县18526984934: 那位达人帮忙做一下java题啊 急求 拜谢 - ?
庄桦世扶: 程序如下,应该是正确的,没有考虑可扩展性优化什么的==================================================== package cn.baidu; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class...
巴马瑶族自治县18526984934: 有个java作业,哪位高手帮忙解决下,谢谢!?
庄桦世扶: public class Student { private int id; private String name; public Student(){} public Student(int id,String name){ this.id=id; this.name=name; }public int getId() { return id; }public void setId(int id) { this.id = id; }public String getName() { return name; }...
巴马瑶族自治县18526984934: java题目... 求高手解答 重谢! !!!!! - ?
庄桦世扶: import java.util.Scanner; public class ChangeGoods { public static void main(String[] args) { System.out.println("输入消费金额:"); Scanner scanner = new Scanner(System.in); String money = scanner.next(); int spendMoney = Integer....
巴马瑶族自治县18526984934: 一道JAVA题谁能帮一下 - ?
庄桦世扶: //第一个类 class Peron{ public Peron(String name){ this.name = name; } String name; int age; } //第二个类 class Student{ public void work(){ Peron p = new Peron(...
巴马瑶族自治县18526984934: JAVA题目 急用 那个高手看到了帮忙作下,我有不到100分 很好的全给了....做好的发给我 - ?
庄桦世扶: 1确实挺简单的,我初学者作的如下package com.zs;import java.text.SimpleDateFormat;import java.util.Calendar;public class YM...
巴马瑶族自治县18526984934: 请教一个基础的JAVA程序题,请高手帮忙解惑. - ?
庄桦世扶: 以学习之名 我写了个东西 值得参考的话 你看看.感觉不行的话 就当学习了 import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;//主类 public class BaiduDemo6 { public ...
巴马瑶族自治县18526984934: 跪求各位好心的网友帮忙做一下JAVA的题 真心谢谢了 - ?
庄桦世扶: 大概做一下:long多重字节码ObjectBorderLayoutfinal修饰的new类抽象方法 superimportcatch 单,多抽象,final修饰的27.run()29.-1430.731.if(x==y)32.System.out.p