اپلت های آرتا تک (سوالات)
مسابقه نخبگان IT با همکاری موسسه پژوهشگران جوان روز سه شنبه این هفته برگزار شد.
گروه آرتا تک هم با سرگروهی بنده در این مسابقه شرکت کرد.
از این جهت که ممکن است سوالات این مسابقه و جوابهای آن برای دوستان جالب باشد آنها را در ذیل تقدیم می کنم.
آرایه ی A مفروض است:
1- آرایه را از کار بر گرفته آن را مرتب کنید.
2- اولین خانه ای که شماره خانه با عدد محتوای آن یکی نیست را چاپ کنید
3- نقطه ای از سمت راست صفحه شروع به حرکت کند و پس از رسیدن به سمت چپ ، در بازگشت در وسط صفحه متوقف شود.
4- نقطه از وسط صفحه به یکی از گوشه های صفحه تا منتهی علیه حرکت کند.
5- رشته S را از کار بر دریافت کنید. برای نمایش رشته پردازشی انجام دهید که قبل از رسیدن به حروف بزرگ(capital letter) ادامه ی رشته را از خط جدید آغاز کند.
Ali Is Student --->
Ali
Is
Student
6- توپی در نقطه ی تصادفی ایجاد شود. و به سمتی از صفحه متمایل شود. پس از برخورد با کناره ی صفحه با زاویه ی 45 درجه برگردد. آن عمل تا زدن دکمه ی Enter ادامه یابد
اپلت های آرتا تک (جواب ها)
جواب سو الهای 1و2 به دلیل اینکه نسبتا ساده است ذکر نشده است.
جواب سوال 6(که یک سوال مشکل) است هم کامل نیست. بسیار خوشحال می شوم که در مورد پاسخ آن همفکری کنیم.
:11:سوال 3
[HTML]
package arta_tech;
import java.awt.*;
import java.awt.event.*;
//This program is Written by Navid Hosseini - arta.tech
public class dotMove1 extends java.applet.Applet implements Runnable{
Thread runner;
int xpos;
public void start(){
if(runner==null){
runner=new Thread(this);
runner.start();
}
}
public void stop(){
if(runner!=null){
runner.stop();
runner=null;
}
}
public void run(){
setBackground(Color.white);
for(xpos=200;xpos>0;xpos-=1){
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
for(xpos=0;xpos<=100;xpos+=1){
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawRect(0,0,200,200);
g.setColor(Color.red);
g.fillOval(xpos,100,5,5);
}
}
[/HTML]
:11:سوال 4
[HTML]
package arta_tech;
import java.awt.*;
import java.awt.event.*;
//This program is Written by Navid Hosseini - arta.tech
public class dotMove2 extends java.applet.Applet implements Runnable{
Thread runner;
int xpos,ypos=100;
public void start(){
if(runner==null){
runner=new Thread(this);
runner.start();
}
}
public void stop(){
if(runner!=null){
runner.stop();
runner=null;
}
}
public void run(){
setBackground(Color.white);
for(xpos=100;xpos>0;xpos-=1){
ypos-=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawRect(0,0,200,200);
g.setColor(Color.red);
g.fillOval(xpos,ypos,5,5);
}
}
[/HTML]
:11:سوال 5
[HTML]
package arta_tech;
import java.awt.*;
import java.lang.String;
//This program is Written by Navid Hosseini - arta.tech
public class StringUp extends java.applet.Applet{
TextField theField;
Label theLabel;
TextArea theArea;
String msg="";
public void init(){
setBackground(Color.white);
theLabel=new Label("Enter your name");
add(theLabel);
theField=new TextField("Your name here",20);
add(theField);
add(new Button("Click!"));
theArea=new TextArea(10,50);
add(theArea);
}
public boolean action(Event evt,Object args){
if(evt.target instanceof Button){
String value=theField.getText();
ChangeLabel(value);
}
return true;
}
void ChangeLabel(String theWord){
String theWord2=theWord.toUpperCase();
int theWordL=theWord.length();
for(int i=0;i<=(theWordL-1);i++){
char theChar=theWord.charAt(i);
char theChar2=theWord2.charAt(i);
String theCh=theChar+"*";
String theCh2=theChar2+"*";
if((!theCh.equals(" *"))&(theCh.equals(theCh2))){
int j=i-1;
if(j==-1)msg+=theChar;
else
msg+="\n"+theWord.charAt(i);
}
else{
msg+=theChar;
}
}
msg+="\n";
theArea.setText(msg);
}
}
[/HTML]
:11:سوال 6
[HTML]
package arta_tech;
import java.awt.*;
//This program is Written by Navid Hosseini - arta.tech
public class ball extends java.applet.Applet implements Runnable{
int boxlenght1,boxlenght2,boxlenght;
int xpos,ypos;
double k;
Thread runner;
public void start(){
if(runner==null){
runner=new Thread(this);
runner.start();
}
}
public void stop(){
if(runner!=null){
runner.stop();
runner=null;
}
}
public void run(){
setBackground(Color.white);
k=Math.random();
if(k<=0.5){xpos=70;ypos=30;}
if(k>0.5){xpos=30;ypos=70;}
if(xpos>=ypos){
while(true){
boxlenght1=200-xpos;
boxlenght2=200-ypos;
boxlenght=Math.min(boxlenght1,boxlenght2);
for(int i=0;i<=boxlenght;i++){
xpos+=1;
ypos+=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght2=200-ypos;
for(int i=0;i<=boxlenght2;i++){
xpos-=1;
ypos+=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght1=xpos;
for(int i=0;i<=boxlenght1;i++){
xpos-=1;
ypos-=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght2=ypos;
for(int i=0;i<=boxlenght2;i++){
xpos+=1;
ypos-=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
}
}
if(xpos<ypos){
while(true){
boxlenght1=200-xpos;
boxlenght2=200-ypos;
boxlenght=Math.min(boxlenght1,boxlenght2);
for(int i=0;i<=boxlenght;i++){
xpos+=1;
ypos+=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght1=200-xpos;
for(int i=0;i<=boxlenght1;i++){
xpos+=1;
ypos-=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght2=ypos;
for(int i=0;i<=boxlenght2;i++){
xpos-=1;
ypos-=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
boxlenght1=xpos;
for(int i=0;i<=boxlenght1;i++){
xpos-=1;
ypos+=1;
repaint();
try{Thread.sleep(100);}
catch (InterruptedException e){}
}
}
}
}
public void paint(Graphics g){
g.setColor(Color.black);
g.drawRect(0,0,220,220);
g.setColor(Color.red);
g.fillOval(xpos,ypos,20,20);
}
}
[/HTML]
:40:در ضمن از هفته آینده اگر خدا بخواهد آموزش زبان جاوا را شروع خواهیم کرد.
انجمن جاوا منتظر سوالات و جوابهای شما می باشد.
موفق باشید.....