Új hozzászólás Aktív témák
-
Dirty_Pio
csendes tag
Sziasztok, mostanaba kezdtem bajlodni a csomagokkal. Inkabb beteszem akodot, hogy lassatok ti is:
//Figure.java:
package Figure;
import java.util.*;
public class Figure
{
protected int ox, oy;
Figure(int x, int y)
{
ox=x;
oy=y;
}
}
// ez utan kovetkeznek a kivetelek, amikre majd szuksegem lesz.
// Rect.java:
package Figure;
public class Rect extends Figure
{
protected int px,py;
Rect(int px, int py, int x, int y)
{
super(x,y);
this.px=px;
this.py=py;
}
public boolean equals(Object o)
{
return (o instanceof Rect)&&((((Rect)o).ox)==this.ox)&&((((Rect)o).oy)==this.oy)&&(((Rect)o).px==this.px)&&(((Rect)o).py==this.py);
}
public String toString()
{
return "Rectangle: "+"xo:"+ox+" oy:"+oy+" side:"+Math.sqrt((px-ox)*(px-ox)+(py-oy)*(py-oy));
}
}
//Circle.java:
package Figure;
public class Circle extends Figure
{
protected int rad;
Circle(int r,int x,int y)
{
super(x,y);
this.rad=r;
}
public boolean equals(Object o)
{
return (o instanceof Circle)&&((((Circle)o).rad==this.rad)&&(((Circle)o).ox==this.ox)&&(((Circle)o).oy==this.oy));
}
public String toString()
{
return "Circle: x="+this.ox+" y="+this.oy+" with radius="+rad;
}
}
//client.java:
package client;
import Figure.*;
public class client{
public static void main(String[] args)
{
Figure z;
Circle c,c2;
Rect p;
p=new Rect(2,3,5,6);
c=new Circle(1,2,16);
try{
Client a=new Client(5);
a.addTo(p);
a.addTo(c);
a.ret();
System.out.println(a.print());
}
catch (notVerify e){
System.out.println(" "+e.getMessage()+" \n");
}
catch (Same e){
System.out.println(" "+e.getMessage()+" \n");
}
catch (Full e)
{
System.out.println(" "+e.getMessage()+" \n");
}
catch (Empty e)
{
System.out.println(" "+e.getMessage()+" \n");
}
c2=new Circle(1,2,16);
}
}
}A Figure packaget szepen le is forditja a program, de amikro a cleintre raterek, akkor azt mondja, hogy nem publikus a Circle meg a Rect osztalyok. Nincs semmi 5letem, hogy mi lehet a gond.
-
Dirty_Pio
csendes tag
Sziasztok,
Van egy kis problemam a kovetkezo koddal: a foridto leforditja, de amikro futtatom a programot a mainbe arthimetic exeption errort ad es kapa.
class Owner{
private String name;
private int CNP;
private Property[] pr=new Property[16];
private int leng;
public Owner(String name){
this.name=name;
}
public Owner(String name, int CNP)
{
this(name);
this.CNP=CNP;
}
public void buy(Property p[],int len)
{
int i;
for (i=0;i<len;i++)
pr[i]=p[i];
leng=len;
}
public boolean na(String n)
{
if (n==name) return true;
else return false;
}
public boolean cn(int c)
{
if (c==CNP) return true;
else return false;
}
public String toString()
{
String s;
int money=0,i;
s="Owner "+name +"\nProperty:\n";
for (i=0;i<leng;i++)
{
if (pr[i] instanceof Field)
s+="Field:\n"+pr[i].ret();
else
s+="Building:\n"+pr[i].ret();
money+=pr[i].price();
}
s+="\nTotal sum: "+money;
return s;
}
}
abstract class Property{
protected String add;
protected int sur;
public Property(String ad,int s)
{
add=ad;
sur=s;
}
abstract int price();
public String qq()
{
return add+"\nSurface: "+sur+"\n";
}
abstract String ret();
}
class Field extends Property{
private int rank;
public Field (String ad, int s, int r)
{
super(ad,s);
rank=r;
}
public int price ()
{
return 350*sur/rank;
}
public String ret()
{
String s;
s=super.qq();
s+="cost : "+this.price();
return s;
}
}
class Building extends Property{
protected int value;
public Building(String ad,int s)
{
super(ad,s);
}
public int price()
{
return sur*500;
}
public String ret()
{
String s;
s=super.qq();
s+="cost : "+this.price();
return s;
}
}
class Operator{
private String n;
private int nr;
public Operator(String n)
{
this.n=n;
}
public Operator(int nr)
{
this.nr=nr;
}
public int search(Owner[] p,int l)
{
int i;
if (nr==0)
for(i=0;i<l;i++)
{
if (p[i].na(n)) return i;
}
else
for (i=0;i<l;i++)
if (p[i].cn(nr)) return i;
return -1;
}
}
class P5{
public static void main(String [] args)
{
Property[] P;
int i,len=3;
P=new Property[len];
for (i=0;i<len;i++)
{
if (i%2==0) P[i]=new Field("address "+i,i*25,i);
else P[i]=new Building("address "+i,i*75);
}
Owner[] o;
o=new Owner[2];
o[0]=new Owner ("Ion Popescu",225533);
o[1]=new Owner("Gigi",553694);
o[0].buy(P,len);
int q;
Operator op;
op=new Operator("Ion Popescu");
q=op.search(o,2);
if (q!=-1)
System.out.println(o[q]);
}
}
Új hozzászólás Aktív témák
Hirdetés
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Kertészet, mezőgazdaság topik
- Steam, GOG, Epic Store, Humble Store, Xbox PC Game Pass, Origin Access, uPlay+, Apple Arcade felhasználók barátságos izgulós topikja
- Milyen okostelefont vegyek?
- Hobby elektronika
- Autós topik
- Kodi és kiegészítői magyar nyelvű online tartalmakhoz (Linux, Windows)
- Milyen légkondit a lakásba?
- Sütés, főzés és konyhai praktikák
- A Galaxy Z Fold7, minden színben és oldalról
- Opel topik
- További aktív témák...
- Új MSI KATANA 17 Gamer Tervező Laptop 17,3" -35% i7-13620H 10Mag 16/1TB RTX 4060 8GB FHD 144Hz
- Apple Iphone 13 128gb csillagfény színű OLCSÓN . Csere/beszámítás
- OnePlus Pad 2 + OnePlus Pad 2 billentyűzet + Extrák
- AKCIÓ!!! GAMER PC: Új i5-14400F +RTX 4060/5060/4070/5070 +Új 16-64GB DDR4! GAR/SZÁMLA! 50 FÉLE HÁZ!
- HP EliteBook 855 G8, 15,6" FHD, Ryzen5 PRO 5650U CPU, 16GB DDR4, 256GB SSD, WIN 11, ( olvasd végig )
- AKCIÓ! MSI B450 R5 5500 16GB DDR4 512GB SSD RTX 2060 Super 8GB GDDR6 Rampage Shiva Zalman 500W
- Csere-Beszámítás! Számítógép PC Játékra! Intel I7 6700/ RX 580 8GB / 32GB DDR4 / 500GB SSD
- BESZÁMÍTÁS! Gigabyte B550M R7 5700X 32GB DDR4 512GB SSD RX 7700 XT 12GB DeepCool CC560 Seasonic 650W
- ÁRGARANCIA! Épített KomPhone Ryzen 7 9700X 32/64GB RAM RX 9070 16GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! Asus TUF F15 FX506HM Gamer notebook - i5 11400H 16GB DDR4 RAM 512GB SSD RTX 3060 6GB W10
Állásajánlatok
Cég: CAMERA-PRO Hungary Kft
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest