package ta;
import java.util.Random;
/* @author
*/
public class Main {
public static void main(String [] args){
int i;
Point point1=new Point(10,15);
//Rectangle rec=new Rectangle(point1);
Rectangle rec=new Rectangle(10,5);
System.out.println(rec.affiche());
System.out.println(point1.getY());
System.out.println(point1.getX());
Rectangle r1=new Rectangle(10,3);
System.out.println(r1);
// rec.affiche();
System.out.println(new Rectangle(new Point(2,3),5,6));
r1.toString();
Carre c1=new Carre(10);
c1.setLongueur(2);
System.out.println(c1);
Test test1= new Test();
test1.affiche2();
// c1.affiche2();
}
}
Автору нужно помочь разобраться в Java-коде за деньги.
Код:
Код:
package ta;
public class Point {
private int x,y;
public Point(int a , int b){
x=a;
y=b;
}
public Point(){
this(0,0);
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
public class Point {
private int x,y;
public Point(int a , int b){
x=a;
y=b;
}
public Point(){
this(0,0);
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
Код:
package ta;
public class Rectangle extends Figure{
protected int longueur , largeur;
public Rectangle( int x , int y ) {
super(new Point ());
longueur=x;
largeur=y;
}
public Rectangle (Point p, int x, int y ){
super (p);
longueur=x;
largeur=y; } ;
public int getLongueur(){
return(longueur);
}
public int getLargeur(){
//return(this.largeur);
return (largeur);
}
public double getPerimetre(){
//return(2*(this.longueur+this.largeur));
return (2*(largeur+longueur));
}
public double getSurface(){
return((longueur)*(largeur));
}
public String affiche(){
int i,j,k;
System.out.print("+");
for(i=0;i<this.longueur;i++) System.out.print("--");
System.out.print("+");
System.out.println("");
for(j=0;j<this.largeur;j++){
System.out.print("|");
for(k=0;k<this.longueur;k++) System.out.print(" ");
System.out.println("|");
}
System.out.print("+");
for(i=0;i<this.longueur;i++) System.out.print("--");
System.out.println("+");
return("");
}
}
public class Rectangle extends Figure{
protected int longueur , largeur;
public Rectangle( int x , int y ) {
super(new Point ());
longueur=x;
largeur=y;
}
public Rectangle (Point p, int x, int y ){
super (p);
longueur=x;
largeur=y; } ;
public int getLongueur(){
return(longueur);
}
public int getLargeur(){
//return(this.largeur);
return (largeur);
}
public double getPerimetre(){
//return(2*(this.longueur+this.largeur));
return (2*(largeur+longueur));
}
public double getSurface(){
return((longueur)*(largeur));
}
public String affiche(){
int i,j,k;
System.out.print("+");
for(i=0;i<this.longueur;i++) System.out.print("--");
System.out.print("+");
System.out.println("");
for(j=0;j<this.largeur;j++){
System.out.print("|");
for(k=0;k<this.longueur;k++) System.out.print(" ");
System.out.println("|");
}
System.out.print("+");
for(i=0;i<this.longueur;i++) System.out.print("--");
System.out.println("+");
return("");
}
}
Код:
package ta;
public class Carre extends Rectangle {
Carre(){
super(0,0);
}
Carre(int a){
super(a,a); ///вызывает конструктор суперкласса
}
Carre(int px,int py){
super(px,py);
}
public void setLongueur(int l){
this.longueur=l;
this.largeur=l;
}
public void setlargeur(int l){
this.longueur=l;
this.largeur=l;
}
public void setBoundingBox(int hBB,int lBB){
this.longueur=lBB;
this.largeur=hBB;
}
}
public class Carre extends Rectangle {
Carre(){
super(0,0);
}
Carre(int a){
super(a,a); ///вызывает конструктор суперкласса
}
Carre(int px,int py){
super(px,py);
}
public void setLongueur(int l){
this.longueur=l;
this.largeur=l;
}
public void setlargeur(int l){
this.longueur=l;
this.largeur=l;
}
public void setBoundingBox(int hBB,int lBB){
this.longueur=lBB;
this.largeur=hBB;
}
}
Код:
package ta;
public abstract class Figure {
protected Point origine;
public Figure (Point or ){
origine=or;
}
public Figure(){
this.origine=new Point(0,0);
}
public String toString()
{
return("l'origine est "+origine.getX()+" et "+origine.getY()+"");
}
public abstract double getPerimetre();
public abstract double getSurface();
}
public abstract class Figure {
protected Point origine;
public Figure (Point or ){
origine=or;
}
public Figure(){
this.origine=new Point(0,0);
}
public String toString()
{
return("l'origine est "+origine.getX()+" et "+origine.getY()+"");
}
public abstract double getPerimetre();
public abstract double getSurface();
}
Код:
package ta;
import java.util.Random;
/**
*
* @author User
*/
public class Test {
public void affiche2(){
Figure[] tf= new Figure[4];
tf[0]=new Ellipse(12,4);
tf[1]= new Rectangle(8,3);
tf[2]=new Carre(4);
tf[3]=new Cercle(4);
System.out.println(((Ellipse)tf[0]).getSurface());
System.out.println(((Rectangle)tf[1]).getSurface());
System.out.println(((Carre)tf[2]).getSurface());
System.out.println(((Cercle)tf[3]).getSurface());
}
public void affiche3(String [] args){
int t=Integer.parseInt(args[0]);
int [] tab =new int [t];
Random rand= new Random();
int i ;
for (i=0 ; i<t; i++){
tab= rand.nextInt(4);
}
Figure [] tf2=new Figure[t];
int j ;
for (j=0; j<t; j++){
switch(tab[j]){
case 0: tf2[j]=new Ellipse(4,2); break;
case 1: tf2[j]=new Cercle(4); break;
case 2: tf2[j]=new Rectangle(5,10); break;
case 3: tf2[j]=new Carre(4); break;
}
}
for (j=0;j<t;j++){
System.out.println(tf2[j].perimetre());
System.out.println(tf2[j].surface());
}
}
}
import java.util.Random;
/**
*
* @author User
*/
public class Test {
public void affiche2(){
Figure[] tf= new Figure[4];
tf[0]=new Ellipse(12,4);
tf[1]= new Rectangle(8,3);
tf[2]=new Carre(4);
tf[3]=new Cercle(4);
System.out.println(((Ellipse)tf[0]).getSurface());
System.out.println(((Rectangle)tf[1]).getSurface());
System.out.println(((Carre)tf[2]).getSurface());
System.out.println(((Cercle)tf[3]).getSurface());
}
public void affiche3(String [] args){
int t=Integer.parseInt(args[0]);
int [] tab =new int [t];
Random rand= new Random();
int i ;
for (i=0 ; i<t; i++){
tab= rand.nextInt(4);
}
Figure [] tf2=new Figure[t];
int j ;
for (j=0; j<t; j++){
switch(tab[j]){
case 0: tf2[j]=new Ellipse(4,2); break;
case 1: tf2[j]=new Cercle(4); break;
case 2: tf2[j]=new Rectangle(5,10); break;
case 3: tf2[j]=new Carre(4); break;
}
}
for (j=0;j<t;j++){
System.out.println(tf2[j].perimetre());
System.out.println(tf2[j].surface());
}
}
}
Код:
package ta;
public class Cercle extends Ellipse {
public Cercle(Point p , int a){
super(p,a,a);
}
public Cercle(int a ){
super(a,a);
}
}
public class Cercle extends Ellipse {
public Cercle(Point p , int a){
super(p,a,a);
}
public Cercle(int a ){
super(a,a);
}
}
package ta;
public class Ellipse extends Figure {
protected int grandaxe ;
protected int petitaxe;
public Ellipse (Point p , int a , int b){
super (p);
grandaxe=a;
petitaxe=b;
}
public Ellipse(int a, int b){
grandaxe=a;
petitaxe=b;
}
public double Surface(){
return (3.14*(grandaxe*petitaxe)/4);
}
public double perimetre(){
return 3.14*(grandaxe+petitaxe);
}
}
[/CODE
:eek:
pomogite razobratsia , za dengi !
stuchite icq : 490015486
Если я правильно угадал условия ; то собственно вот решение:
public class Rectangle
private int x;
private int y;
public Rectangleint xVal, int yVal
x = xVal;
y = yVal;
public void paint
System.out.printlncalcChart;
private String calcChart
StringBuffer sb = new StringBuffer"";
if x=0y=0
sb.append"Data is incorrect.";
else
StringBuffer horizontalLine = new StringBuffer"n";
StringBuffer verticalLine = new StringBuffer"n";
for int i=0; ix; i
horizontalLine.inserthorizontalLine.length-2,"-";
verticalLine.insertverticalLine.length-2," ";
for int i=1; i=y; i
sb.appendi==1i==y?horizontalLine:verticalLine;
return sb.toString;
public static void mainString args
Rectangle myRect = new Rectangle28,10;
myRect.paint;