hw3.pdf

‫ﺑﻪ ﻧﺎم دوﺳﺖ‬
‫ﺑﺮﻧﺎﻣﻪ ﻧﻮﻳﺴﯽ ﭘﻴﺸﺮﻓﺘﻪ‬
‫ﻧﻴﻢ ﺳﺎل دوم ‪٨۴-٨٣‬‬
‫ﺕﻤﺮﻳﻦ ﺳﻮم‬
‫ﺕﺬﮐﺮ ﻣﻬﻢ‪ :‬ﺑﻪ ﻋﻠﺖ ﺧﺮاﺑﯽ و ﻋﺪم ﮐﺎرﮐﺮد ‪ Mailing list‬داﻧﺸﮑﺪﻩ ‪Group ،‬ﻳﯽ در ‪ yahoo‬ﺑﺎ‬
‫ﻣﺸﺨﺼﺎت و ﺁدرس زﻳﺮ ﺑﺮای اﻳﻦ ﻣﻨﻈﻮر ﺳﺎﺧﺘﻪ ﺵﺪﻩ اﺳﺖ‪ .‬ﮐﺴﺎﻧﯽ ﮐﻪ ﻗﺒﻼ در ‪mailing list‬‬
‫داﻧﺸﮑﺪﻩ ﻋﻀﻮ ﺑﻮدﻧﺪ ﺑﻪ اﻳﻦ ‪ mailing list‬دﻋﻮت ﺵﺪﻩ اﻧﺪ‪ .‬ﮐﺴﺎﻧﯽ ﮐﻪ ﺕﺎ ﺑﻪ ﺣﺎل ﻋﻀﻮ ‪mailing‬‬
‫‪ list‬ﻧﺸﺪهﺎﻧﺪ‪ ،‬ﻝﻄﻔﺎ در ‪ mailing list‬ﻣﺬﮐﻮر ﻋﻀﻮ ﺵﻮﻧﺪ‪.‬‬
‫ﺑﺮای ﻋﻀﻮ ﺵﺪن در ‪ mailing list‬ﻓﻮق ﮐﺎﻓﯽ اﺳﺖ ﮐﻪ ﺑﻪ‬
‫‪ http://groups.yahoo.com/group/ce_java‬ﻣﺮاﺟﻪ ﮐﻨﻴﺪ و ﻋﻀﻮ ‪ group‬درس‬
‫‪ ce244‬ﺵﻮﻳﺪ‪.‬‬
‫‪ce_java‬‬
‫‪http://groups.yahoo.com/group/ce_java‬‬
‫‪[email protected]‬‬
‫‪Group name‬‬
‫‪Group home page‬‬
‫‪Group email address‬‬
‫در ﻏﻴﺮ اﻳﻦ ﺻﻮرت ﻋﺬر ﺵﻤﺎ ﻣﺒﻨﯽ ﺑﺮ ﻣﻄﻠﻊ ﻧﺒﻮدن از ﻣﺴﺎﺋﻞ و ﻣﻄﺎﻝﺐ ﻣﻄﺮح ﺵﺪﻩ در‬
‫‪ mailing list‬ﭘﺬﻳﺮﻓﺘﻪ ﻧﺨﻮاهﺪ ﺑﻮد‪.‬‬
‫اﺵﮑﺎﻻت و ﺳﻮاﻻت ﺥﻮد را از اﻳﻦ ﺑﻪ ﺑﻌﺪ ﺑﻪ اﻳﻦ ‪ Mailing list‬درس ﺑﻔﺮﺳﺘﻴﺪ‪.‬‬
‫ﺑﺮای هﺮ ﻳﮏ از ﻣﺴﺎﺋﻞ زﻳﺮ ﻳﮏ ﺑﺮﻧﺎﻣﻪ ﺟﺎوا ﺑﻨﻮﻳﺴﻴﺪ‪ ،‬ﮐﻪ اﺳﻢ ﮐﻼس اﺹﻠﯽ ﮐﻪ ﺣﺎوی ﻣﺘﺪ )‪main(String [] args‬‬
‫ﻣﯽ ﺑﺎﺵﺪ ﺑﺎﻳﺪ ﺑﺎ اﺳﻢ ﮐﻼس اﺹﻠﯽ ﮐﻪ در ﺹﻮرت ﻣﺴﺌﻠﻪ دادﻩ ﺵﺪﻩ اﺳﺖ‪ .‬در ﻏﻴﺮ اﻳﻦ ﺹﻮرت ﻣﻤﮑﻦ اﺳﺖ ﺕﺼﺤﻴﺢ‬
‫ﺕﻤﺮﻳﻦ ﺵﻤﺎ دﭼﺎر ﻣﺸﮑﻞ ﺵﻮد‪) .‬ﺑﻪ ﺑﺰرﮔﯽ و ﮐﻮﭼﮑﯽ ﺣﺮوف ﺕﻮﺟﻪ ﮐﻨﻴﺪ(‪.‬‬
‫ﺑﺮای ﺕﺤﻮﻳﻞ ﺕﻤﺮﻳﻦ ﺧﻮد ﻓﻘﻂ ﻓﺎﻳﻞ هﺎی ‪ *.java‬ﺕﻤﺮﻳﻦ ﺥﻮد را )ﺑﺪون ﻓﺎﻳﻠﻬﺎی ‪ *.class‬و ‪ file‬ﻳﺎ داﻳﺮﮐﺘﻮری‬
‫اﺽﺎﻓﯽ( ‪ zip‬ﮐﺮدﻩ ]از ﻓﺮﻣﺖ ‪ rar‬اﺳﺘﻔﺎدﻩ ﻧﮑﻨﻴﺪ[‪ ،‬ﮐﻪ ﻧﺎم ﺁن ﺑﻪ ﺻﻮرت زﻳﺮ ﻣﻴﺒﺎﺵﺪ‪:‬‬
‫ﺑﻌﺪ از ”‪ “HW-3‬ﺵﻤﺎرﻩ داﻧﺸﺠﻮﻳﯽ ﺥﻮد را وارد ﮐﺮدﻩ )ﺑﺪون اﻳﻨﮑﻪ از ﮐﺎراﮐﺘﺮ ﻓﺎﺻﻠﻪ ﺥﺎﻝﯽ اﺳﺘﻔﺎدﻩ ﮐﻨﻴﺪ(‪ .‬ﺑﻪ‬
‫ﻋﻨﻮان ﻣﺜﺎل ‪ ] HW3-83182239.zip :‬از ﻓﺮﻣﺖ ‪ *.rar‬ﻣﺎﻧﻨﺪ ‪ HW3-83182239.rar‬اﺳﺘﻔﺎدﻩ ﻧﮑﻨﻴﺪ[ و ﺳﭙﺲ‬
‫ﺁن را ﺕﻮﺳﻂ ﻳﮏ ‪ email‬ﺑﺎ ﻣﺸﺨﺼﺎت زﻳﺮ ﺑﻪ ﺁدرس ﻣﺬﮐﻮر ارﺳﺎل ﮐﻨﻴﺪ‪.‬‬
‫‪[email protected]‬‬
‫‪HW3-83182239‬‬
‫‪HW3-83182239.zip‬‬
‫‪Recipient:‬‬
‫‪Subject:‬‬
‫‪Body:‬‬
‫‪Attachments:‬‬
‫ﻓﻴﻠﺪ ‪ Subject‬ﻧﺎﻣﻪ‪ ،‬درﺳﺖ ﻣﺎﻧﻨﺪ اﺳﻢ ‪ zip‬ﻓﺎﻳﻞ ‪ attach‬ﺵﺪﻩ ﻣﻴﺒﺎﺵﺪ‪ .‬ﺑﺪﻳﻦ ﺹﻮرت ﮐﻪ ﺑﻌﺪ از ”‪ “HW3-‬ﺵﻤﺎرﻩ‬
‫داﻧﺸﭽﻮﻳﯽ ﺧﻮد را وارد ﮐﺮدﻩ )ﺑﺪون اﻳﻨﮑﻪ از ﮐﺎراﮐﺘﺮ ﻓﺎﺹﻠﻪ ﺧﺎﻝﯽ اﺳﺘﻔﺎدﻩ ﮐﻨﻴﺪ(‪.‬‬
‫ﻧﮑﺎﺕﯽ ﮐﻪ در ارﺳﺎل ﺕﻤﺮﻳﻦ ﺑﺎﻳﺪ ﺣﺘﻤﺎ رﻋﺎﻳﺖ ﺵﻮﻧﺪ‪:‬‬
‫‪ .١‬ﺕﻤﺮﻳﻦ هﺎ ﺣﺘﻤﺎ ﺑﺎﻳﺪ ﺑﻪ ﺹﻮرت ﮔﻔﺘﻪ ﺵﺪﻩ ارﺳﺎل ﮔﺮدﻧﺪ‪ .‬در ﻏﻴﺮ اﻳﻦ ﺹﻮرت ﺕﺼﺤﻴﺢ ﻧﺨﻮاهﻨﺪ ﮔﺸﺖ‪ ،‬و‬
‫ﻧﻤﺮﻩ ﺁن را از دﺳﺖ ﻣﻴﺪهﻨﺪ‪.‬‬
‫‪ .٢‬ﺕﻮﺟﻪ ﮐﻨﻴﺪ ﮐﻪ ﺑﺪﻧﻪ ‪ mail‬ﺵﻤﺎ ﺧﻮاﻧﺪﻩ ﻧﻤﻴﺸﻮد‪ ،‬ﻝﺬا اﮔﺮ ﻗﺼﺪ ﺑﻴﺎن ﻣﻄﻠﺒﯽ را دارﻳﺪ‪ ،‬ﻧﺎﻣﻪ ای ﺟﺪاﮔﺎﻧﻪ ای‬
‫ارﺳﺎل ﮐﻨﻴﺪ ﮐﻪ ‪ subject‬ﺁن ﻣﺘﻔﺎوت ﺑﺎﺵﺪ‪.‬‬
‫‪ .٣‬ﺕﻮﺟﻪ ﻣﻬﻢ‪ :‬در ﺻﻮرﺕﯽ ﮐﻪ ﮐﺴﯽ ﺕﻤﺮﻳﻦ ﺥﻮد را ﺑﻪ ﺟﺎی ﺁدرس‪ mail‬درس ﺑﻪ ﺁدرس ‪mailing list‬‬
‫درس ارﺳﺎل ﮐﻨﺪ‪ .‬ﻧﻤﺮﻩ ﺁن ﺕﻤﺮﻳﻦ را از دﺳﺖ ﻣﯽ دهﺪ‪ .‬و در ﺻﻮرت ﺕﮑﺮار ﻧﻤﺮﻩ ﻣﻨﻔﯽ ﺥﻮاهﺪ ﮔﺮﻓﺖ‪.‬‬
.‫ ﻣﯽ ﺑﺎﺵﺪ‬٨۴/١/٣١ ‫ ﻇﻬﺮ روز ﭼﻬﺎرﺵﻨﺒﻪ‬١٣:٣٠ ‫ ﺕﺎ ﺳﺎﻋﺖ‬،‫ﻣﻬﻠﺖ ارﺳﺎل ﺕﻤﺮﻳﻦ ﺳﺮی ﺳﻮم‬
.‫ ﺕﺼﺤﻴﺢ ﻧﺨﻮاهﻨﺪ ﺵﺪ‬،‫از ﺕﻤﺮﻳﻦ هﺎﻳﯽ ﮐﻪ ﺑﻌﺪ از اﻳﻦ ﺕﺎرﻳﺦ و ﺳﺎﻋﺖ ﻓﺮﺳﺘﺎدﻩ ﺵﻮﻧﺪ‬
‫ ﺵﺒﻴﻪ ﺳﺎزی اﻋﺪاد ﮐﺴﺮی و اﻋﻤﺎل رﻳﺎﺽﯽ روی ﺁﻧﻬﺎ‬: ‫ﻣﺴﺌﻠﻪ ﻳﮏ‬
Rational.java : ‫ﻧﺎم ﮐﻼس اﺻﻠﯽ ﺑﺮﻧﺎﻣﻪ‬
Create a class called Rational for performing arithmetic with fractions.
Use Integer variable to represent the private instance variables of the class (the
numerator and the denominator).
Provide a constructor method that enables an object of this class to be initialized when it
is declared. The constructor should store the fraction in reduced form (i.e., the fraction
2/4 would be stored in the object as 1 in the numerator and 2 in the denominator).
Provide a no argument constructor with default values in case no initializers are provided.
Provide public methods for each of the following:
a) Additions of two Rational numbers. The result of the addition should be stored in
reduced form.
The signature of the method should be the same as below:
public Rational add (Rational num)
b) Subtraction of two Rational numbers. The result of the subtraction should be
stored in reduced form.
The signature of the method should be the same as below:
public Rational sub (Rational num)
c) Multiplication of two Rational numbers. The result of the multiplication should
be stored in reduced form.
The signature of the method should be the same as below:
public Rational mul (Rational num)
d) Division of two Rational numbers. The result of the division should e stored in
reduced form.
The signature of the method should be the same as below:
public Rational div (Rational num)
In all above methods the result of operations isn’t save in the Rational
number that the method is called on it.
For example, if we have a Rational numbers x and y with initial value of ½, the
operation x.add(y) is not effect in the value of x or y, and both of them remain ½.
e) Convert a Rational number to a floating-point format.
The signature of the method should be the same as below:
public double toFloatingPoint (Rational num)
f) Convert a Rational number to String with this format: “ a/b “ which a is
numerator and b is denominator.
The signature of the method should be the same as below:
public String toString ()
g) Printing Rational numbers in floating-point format.
The signature of the method should be the same as below:
public Rational print()
Attention: As all of your files are be corrected with a preWritten TestClass file, your
Class NAME and all method SIGNATURES must be the same as above even in
upper case and lower case format of them. Otherwise you may loose your grade and
No excuse will be approved.
fractal ‫ رﺳﻢ اﺵﮑﺎل‬: ‫ﻣﺴﺌﻠﻪ دوم‬
Fractal.java : ‫ﻧﺎم ﮐﻼس اﺻﻠﯽ ﺑﺮﻧﺎﻣﻪ‬
‫ ﺵﮑﻞ‬Initiator .‫ ﻳﮏ داﻧﻪ ﺑﺮف را رﺳﻢ ﮐﻨﺪ‬fractal ‫ ﺑﻨﻮﻳﺴﻴﺪ ﮐﻪ ﺕﻮﺳﻂ اﺵﮑﺎل‬applet ‫در اﻳﻦ ﻣﺴﺌﻠﻪ ﺵﻤﺎ ﺑﺎﻳﺪ ﻳﮏ‬
‫ ﺵﻤﺎ ﻳﮏ ﻣﺜﻠﺚ ﻣﺘﺴﺎوی اﻻﺽﻼع‬fractal
‫ ﻗﺴﻤﺖ ﻣﺴﺎوی ﺕﻘﺴﻴﻢ‬٣ ‫ ﺵﮑﻞ ﺵﻤﺎ ﺵﮑﻞ زﻳﺮ ﻣﯽ ﺑﺎﺵﺪ ﮐﻪ در ﺣﻘﻴﻘﺖ ﻳﮏ پﺎرﻩ ﺧﻂ اﺳﺖ ﮐﻪ ﺑﻪ‬Generator ‫ﻣﻴﺒﺎﺵﺪ و‬
‫ﺵﺪﻩ اﺳﺖ و ﺑﻪ ﺟﺎی ﭘﺎرﻩ ﺥﻂ ﻣﻴﺎﻧﯽ ﻳﮏ ﻣﺜﻠﺚ ﻣﺘﺴﺎوی اﻻﺽﻼع ﻗﺮار)ﻃﻮل اﺽﻼع ﺁن ﺑﺮاﺑﺮ ﻃﻮل پﺎرﻩ ﺧﻂ ﻣﻴﺎﻧﯽ‬
.‫ روی اﺽﻼع ﻣﺜﻠﺚ ﺟﺎﻳﮕﺰﻳﻦ ﻣﻴﺸﻮد‬recursive ‫ ﮐﻪ ﺑﻪ ﻃﻮر‬.‫( ﮔﺮﻓﺘﻪ ﮐﻪ ﻗﺎﻋﺪﻩ زﻳﺮﻳﻦ ﺁن ﺣﺬف ﺵﺪﻩ اﺳﺖ‬.‫اﺳﺖ‬
‫ اﻳﻦ ﻋﻤﻞ را ﺵﻤﺎ ﺑﺎﻳﺪ روی‬.‫ ﻣﺮﺣﻠﻪ ﺑﺮ روی ﻳﮏ ﺽﻠﻊ از ﻣﺜﻠﺚ ﻣﻴﺒﻨﻴﺪ‬۵ ‫در زﻳﺮ ﻳﮏ ﻧﻤﻮﻧﻪ از اﻳﻦ ﺟﺎﻳﮕﺰﻳﻨﯽ را در‬
‫ ﺑﺮ روی ﻳﮏ‬mouse ‫ ﮐﻪ ﮔﺬر از هﺮ ﻣﺮﺣﻠﻪ ﺑﻪ ﻣﺮﺣﻠﻪ ﺑﻌﺪ ﺕﻮﺳﻂ ﮐﻠﻴﮏ‬.‫ ﻣﺮﺣﻠﻪ اﻧﺠﺎم دهﻴﺪ‬۵ ‫ ﺽﻠﻊ ﻣﺜﻠﺚ و ﺕﺎ‬٣ ‫هﺮ‬
.‫ ﺙﺎﻧﻴﻪ ﺑﻴﻦ هﺮ دو ﻣﺮﺣﻠﻪ اﻧﺠﺎم ﻣﻴﺸﻮد‬١ ‫ و ﻳﺎ ﺑﻪ ﻃﻮر ﻣﺘﻮاﻝﯽ پﺸﺖ ﺳﺮهﻢ وﻝﯽ ﺑﺎ ﻣﮑﺚ‬applet ‫دﮐﻤﻪ در ﺑﺎﻻ ﻳﺎ پﺎﻳﻴﻦ‬
‫ﺧﺪاﻳﺎ! ﺁﺳﺎن ﺑﻮدن دﺵﻮار اﺳﺖ‬
‫ﺁﺳﺎﻧﻢ ﮐﻦ‪.‬‬
‫ﺁﻧﯽ ﻧﻴﺴﺘﻢ ﮐﻪ ﺑﺎﻳﺪ‬
‫ﺁﻧﻢ ﮐﻦ‪.‬‬