谁能帮一下我,java选修课的作业,一题两题都可以,先谢谢了!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了谁能帮一下我,java选修课的作业,一题两题都可以,先谢谢了!!相关的知识,希望对你有一定的参考价值。
一. 作业要求:给出程序代码,代码要有详细注释;
二. 题目(任选两题完成Java编程)
1、类与对象的基础题:
1)编程实现:设计一个类Simple,有三个成员变量,分别为int型、double型和String型,这三个成员变量分别含有各自的get方法和set方法,可以用toString方法显示这三个成员变量。,
2)声明测试类:在测试类的main 方法中创建Simple类的对象aSimple,此对象调用set方法分别对对象的各个属性设置具体的值,然后调用get方法将aSimple的具体的值输出在屏幕上。
2、类的方法与异常处理:
在一个类的main方法中定义一个长度为8的int型数组,用for循环对数组中的元素1到8的值。随机产生两个整数,将这两个整数作为数组的下标来引用数组中的元素,求出这两个元素的积,并在屏幕上输出这两个元素的值和积。要求在出现数组下标越界时,采用try-catch的方法捕获异常。
3、输入/输出流:
在一个类的main方法中通过键盘输入一串字符,以“#”号作为结束,再将字符串中的小写英文字母改写成在大写,最后将改写好的字符串写入D盘下的file1.txt, 然后将此文件中的内容读取出来显示在屏幕上。
4、 多线程与Syncronized同步控制:
定义一个DataPool数据池类,有一个能存放一个int型数据的成员变量data,还有一个setData(int d)方法。有三个线程a, b和c负责向DataPool类的数据池对象中存放数据,一次只能有一个线程向其中存放数据,数据放入以后,该线程随机休眠一段时间,让其它线程运行, 存放数据和休眠前要求在屏幕上输出相关的提示信息.
5、基于套接字Socket的网络通信:
制作一个简单的C/S应用。其中,客户端为GUI程序,用于提供界面输入两个整数,并使用5个按钮分别表示加、减、乘、除和发送,另外还有一个TextFieldet 用于输出传来的结果。服务器是一个多线程的服务器,可以同时服务多个客户端,用于监听数据、计算结果、送回数据结果。
在一个类的main方法中定义一个长度为8的int型数组,用for循环对数组中的元素1到8的值。随机产生两个整数,将这两个整数作为数组的下标来引用数组中的元素,求出这两个元素的积,并在屏幕上输出这两个元素的值和积。要求在出现数组下标越界时,采用try-catch的方法捕获异常。
import java.util.Random;
public class SecondTest
public static void main(String[] args)
//定义一个长度为8的int型数组
int[] ary = 35, 42, 13, 46, 59, 37, 125, 99;
//用for循环对数组中的元素1到8的值
for(int i= 1; i < ary.length;i++)
System.out.print(ary[i] + "\t");
System.out.println();
try
Random rand = new Random();
//随机产生两个整数
int first = rand.nextInt();
int second = rand.nextInt();
//这两个整数作为数组的下标来引用数组中的元素,求出这两个元素的积
long mul = ary[first] * ary[second];
//屏幕上输出这两个元素的值和积
System.out.println("积为" + mul);
catch(ArrayIndexOutOfBoundsException exp)
//出现数组下标越界时,采用try-catch的方法捕获异常
System.out.println("数组下标越界! Error!");
、类与对象的基础题:
1)编程实现:设计一个类Simple,有三个成员变量,分别为int型、double型和String型,这三个成员变量分别含有各自的get方法和set方法,可以用toString方法显示这三个成员变量。,
2)声明测试类:在测试类的main 方法中创建Simple类的对象aSimple,此对象调用set方法分别对对象的各个属性设置具体的值,然后调用get方法将aSimple的具体的值输出在屏幕上。
public class TestSimple //测试类的
public static void main(String[] args)
//创建Simple类的对象aSimple
Simple aSimple = new Simple();
//set方法分别对对象的各个属性设置具体的值
aSimple.setIntValue(5);
aSimple.setDoubleValue(123.45D);
aSimple.setStrValue("string value for simple");
//get方法将aSimple的具体的值输出在屏幕上
System.out.println("int value for simple is: " + aSimple.getIntValue());
System.out.println("double value for simple is: " + aSimple.getDoubleValue());
System.out.println("String value for simple is: " + aSimple.getStrValue());
class Simple//类Simple
private int intValue;//int型成员变量
private double doubleValue;//double型成员变量
private String strValue;//String型成员变量
//用toString方法显示这三个成员变量
public String toString()
return intValue + ", " + doubleValue + ", " + strValue;
public double getDoubleValue()
return doubleValue;
public void setDoubleValue(double doubleValue)
this.doubleValue = doubleValue;
public int getIntValue()
return intValue;
public void setIntValue(int intValue)
this.intValue = intValue;
public String getStrValue()
return strValue;
public void setStrValue(String strValue)
this.strValue = strValue;
参考技术A 前两个
------------------------------------------------------------
public class Operation1
public static void main(String[] args)
Simple s = new Simple();
s.setTypeInt(10);
s.setTypeDouble(20.1);
s.setTypeString("your name");
System.out.println(s.getTypeInt());
System.out.println(s.getTypeDouble());
System.out.println(s.getTypeString());
System.out.println(s.toString());
class Simple
private int typeInt = 0;
private double typeDouble = 0.0;
private String typeString = "";
public int getTypeInt()
return typeInt;
public void setTypeInt(int typeInt)
this.typeInt = typeInt;
public double getTypeDouble()
return typeDouble;
public void setTypeDouble(double typeDouble)
this.typeDouble = typeDouble;
public String getTypeString()
return typeString;
public void setTypeString(String typeString)
this.typeString = typeString;
public String toString()
return "[typeInt=" + typeInt + ",typeDouble=" + typeDouble
+ ",typeString" + typeString + "]";
------------------------------------------------------------
import java.util.Random;
public class Operation2
public static void main(String[] args)
// 定义一个长度为8的int型数组,用for循环对数组中的元素1到8的值。
int[] array = new int[8];
for (int i = 0; i < array.length; i++)
array[i] = i + 1;
Random random = new Random();
// 随机产生两个整数
int index1 = random.nextInt(10);
int index2 = random.nextInt(10);
try
// 并在屏幕上输出这两个元素的值和积
System.out.println(array[index1] +" * "+ array[index2] +" = "+array[index1] * array[index2]);
catch (Exception e)
// 数组下标越界时,采用try-catch的方法捕获异常
System.out.println(e.getMessage());
参考技术B 我害怕给你做了,你不采纳我,毕竟这个都要我花时间写的啊!你答应只采纳我,我现在就做! 参考技术C 前两个很简单 参考技术D 第一题:
//类Simple
public class Simple
public int intDate;
public String StringDate;
public double doubleDate;
public int getIntDate()
return intDate;
public void setIntDate(int intDate)
this.intDate = intDate;
public String getStringDate()
return StringDate;
public void setStringDate(String stringDate)
StringDate = stringDate;
public double getDoubleDate()
return doubleDate;
public void setDoubleDate(double doubleDate)
this.doubleDate = doubleDate;
//测试类
public class TestSimple
/**
* @param args
*/
public static void main(String[] args)
// TODO Auto-generated method stub
Simple simple = new Simple();
simple.setStringDate("String");
simple.setIntDate(100);
simple.setDoubleDate(100.11);
System.out.println("String:"+simple.getStringDate()+
"int:"+simple.getIntDate()+
"Double:"+simple.getDoubleDate());
各位。能帮我用英语翻译一下这段关于销售手机的情景对话?
我是做手机零售的,每天都面对很多很多外国人。自己的英语也不好,所以想找高人帮我用英语翻译一段对话。内容如下:
“这款手机是最新款,内置1G内存,屏幕大,功能简单,款式特别。而且还能触屏,触屏很灵敏的。”
“有没有WIFI功能和电子词典翻译?”
“有的,打开界面,用手指触动屏幕,这里就能找到WIFI。电子词典翻译的话只要手机有JAVA就可以下载。”
“什么价格?”
“我直接给你个最低价吧,450元。”
“太贵了,这款手机我在市场上随处可见,300元给我我立刻拿走。”
“先生,我给你的价格已经很低了,没赚你什么钱。你可以去市场调查一下,我这个价格绝对合理。可能市场上有很多相似的款式,但质量是不一样的。”
“这手机语言能改成法文的吗?”
“如果您有需要的话我可以帮你升级成法文的。”
“OK,保修多久?”
“一年!”
“如果手机用了两天有问题可以拿来换,或者退吗?”
“不好意思,换是可以的,退款的话恐怕不行,不过您放心,这款手机正常使用下是不会有什么问题的。”
“好吧,开张单给我!”
“好的,如果先生以后有什么朋友要买手机的话可以介绍他们来我这买,价钱绝对合理,绝对给你最低价。”
“没问题!”
“那这是保修单,凭单保修一年!请您记住!”
“好的!”
“欢迎下次再来!”
拜托各位尽快帮我翻译出来好吗?最主要要准确啊!!!小弟感激不尽啊!
This phone is the latest, built-in 1G memory, large screen, simple functions, special style. But also touch screen, touch screen is very sensitive." "There is no WIFI function and electronic dictionary translation?" "Yes, open the interface and touch the screen with your fingers, you can find the WIFI. Electronic dictionary translation, as long as the phone can be downloaded JAVA." "What price?" "I give you the lowest price, 450 yuan." "Too expensive, this phone I can be seen everywhere in the market, 300 yuan to me immediately take away." "Sir, I gave you the price is already very low, did not make you any money. You can go to the market to investigate, I this price is absolutely reasonable. There may be a lot of similar style, but the quality is not the same." "Is the language of the mobile phone in French?" "I can help you upgrade to French if you need it." "OK, how long is the guarantee?" "One year!" "If the mobile phone uses two days to have a problem can be used to change, or back?" Sorry, change is possible, then I am afraid not, but you can rest assured that the use of this phone is not a problem for normal use." "Well, give me a single!" "Yes, if you have any friends to buy a mobile phone can introduce them to me to buy, the price is absolutely reasonable, absolutely give you the lowest price." "No problem!" "This is the warranty, one year warranty voucher! Please remember!" "Good!" "Welcome to come again!" 参考技术A 这个情景对话应该比较简单,但是里面肯定要涉及到一些手机的术语。请发图片文章或者把情景对话写上来。 参考技术B This phone is the latest models, built-in 1G memory, large screens, features simple and special style. But also the touch screen, touch-screen is very sensitive. "
"Is there WIFI function and electronic dictionary translation?"
"Some, open interface, a finger touch screen, where you will find WIFI. Electronic dictionary translator, then as long as the phone has JAVA can be downloaded."
"What price?"
"I give you directly to a low bar, 450 million."
"Too expensive, this phone I can be seen everywhere in the market, 300 yuan to me I immediately removed."
"Sir, I'll give you the price is already so low, and did not make you any money. You can go to the market to look into my price is absolutely reasonable. May be on the market there are many similarities of style, but the quality is not the same."
"This cell phone into the French language can it?"
"If you have a need to do so I can help you upgrade to the French."
"OK, how long the warranty?"
"A year!"
"If the phone can be used for two days in question brought a change, or withdraw it?"
"I beg your pardon, change is possible, a refund, then I'm afraid not, but you rest assured that this phone under normal use will not have any problem."
"Well, the opening of a single to me!"
"Well, what if the future President of the words of a friend to buy mobile phones can introduce them to me to buy, the price is absolutely reasonable to give you the absolute lowest price."
"No problem!"
"Well, this is a warranty, vouchers for one year warranty! You remember!"
"Good!"
"Welcome to come again next time!" 参考技术C "This is the latest mobile phone models, built-in 1G memory, large screens, features simple style in particular. But also the touch screen, touch-screen is very sensitive."
"Is there WIFI function and electronic dictionary translation?"
"Some, open interface, a finger touch screen, where you will find WIFI. Electronic dictionary translator, then as long as the phone has JAVA can be downloaded."
"What price?"
"I give you directly to a low bar, 450 million."
"Too expensive, this phone I can be seen everywhere in the market, 300 yuan to me I immediately removed."
"Sir, I'll give you the price is already so low, and did not make you any money. You can go to the market to look into my price is absolutely reasonable. May be on the market there are many similarities of style, but the quality is not the same."
"This cell phone into the French language can it?"
"If you have a need to do so I can help you upgrade to the French."
"OK, how long the warranty?"
"A year!"
"If the phone can be used for two days in question brought a change, or withdraw it?"
"I beg your pardon, change is possible, a refund, then I'm afraid not, but you rest assured that this phone under normal use will not have any problem."
"Well, the opening of a single to me!"
"Well, what if the future President of the words of a friend to buy mobile phones can introduce them to me to buy, the price is absolutely reasonable to give you the absolute lowest price."
"No problem!"
"Well, this is a warranty, vouchers for one year warranty! You remember!"
"Good!"
"Welcome to come again next time!"
希望你够帮助你哦 参考技术D did it for the retail cell phone every day and deal with many foreigners. Their English is not good, so looking for Gao Ren help me with the English translation of a dialogue. Reads as follows:
"This is the latest mobile phone models, built-in 1G memory, large screens, features simple style in particular. But also the touch screen, touch-screen is very sensitive."
"Is there WIFI function and electronic dictionary translation?"
"Some, open interface, a finger touch screen, where you will find WIFI. Electronic dictionary translator, then as long as the phone has JAVA can be downloaded."
"What price?"
"I give you directly to a low bar, 450 million."
"Too expensive, this phone I can be seen everywhere in the market, 300 yuan to me I immediately removed."
"Sir, I'll give you the price is already so low, and did not make you any money. You can go to the market to look into my price is absolutely reasonable. May be on the market there are many similarities of style, but the quality is not the same."
"This cell phone into the French language can it?"
"If you have a need to do so I can help you upgrade to the French."
"OK, how long the warranty?"
"A year!"
"If the phone can be used for two days in question brought a change, or withdraw it?"
"I beg your pardon, change is possible, a refund, then I'm afraid not, but you rest assured that this phone under normal use will not have any problem."
"Well, the opening of a single to me!"
"Well, what if the future President of the words of a friend to buy mobile phones can introduce them to me to buy, the price is absolutely reasonable to give you the absolute lowest price."
"No problem!"
"Well, this is a warranty, vouchers for one year warranty! You remember!"
"Good!"
"Welcome to come again next time!"
以上是关于谁能帮一下我,java选修课的作业,一题两题都可以,先谢谢了!!的主要内容,如果未能解决你的问题,请参考以下文章
谁能帮我解释一下java线程中的wait()方法的作用与执行原理非常感谢!
10道java经典算法题,每一题都能提升你的java水平!第二弹!
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType这个异常怎么解决 谁能帮我一下