Created
March 8, 2012 08:36
-
-
Save ngnguyen1/1999693 to your computer and use it in GitHub Desktop.
So phuc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vidu1; | |
/** | |
* | |
* @author NgaNguyenDuy | |
*/ | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
SoPhuc sp1=new SoPhuc(3,5); | |
sp1.inSoPhuc(); | |
SoPhuc sp2=new SoPhuc(); | |
System.out.println("nhap thong tin cho so phuc thu 2 "); | |
sp2.nhapSoPhuc(); | |
System.out.println("ket qua vua nhap"); | |
sp2.inSoPhuc(); | |
System.out.println("ket qua tong cua hai so phuc vua nhap "); | |
SoPhuc spt=sp1.congSoPhuc(sp2); | |
spt.inSoPhuc(); | |
// TODO code application logic here | |
} | |
} | |
/*Class SOPHUC | |
*/ | |
package vidu1; | |
/** | |
* | |
* @author NgaNguyenDuy | |
*/ | |
import java.util.Scanner; | |
public class SoPhuc { | |
double phanThuc,phanAo; | |
SoPhuc(){} | |
SoPhuc(double pt,double pa) | |
{phanThuc=pt; phanAo=pa; | |
} | |
public void inSoPhuc() | |
{System.out.println(phanThuc+"+"+phanAo+"i"); | |
} | |
public void nhapSoPhuc() | |
{Scanner input =new Scanner(System.in); | |
System.out.print("nhap phan thuc: ="); | |
phanThuc=input.nextDouble(); | |
System.out.print("nhap phan ao: ="); | |
phanAo=input.nextDouble(); | |
} | |
public SoPhuc congSoPhuc(SoPhuc sp) | |
{SoPhuc spTong=new SoPhuc(); | |
spTong.phanThuc=phanThuc+sp.phanThuc; | |
spTong.phanAo=phanAo+sp.phanAo; | |
return spTong; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment