- Intel Core Ultra 3, Core Ultra 5, Ultra 7, Ultra 9 "Arrow Lake" LGA 1851
- Milyen videókártyát?
- Milyen billentyűzetet vegyek?
- RAM topik
- Megjöttek a be quiet! Pure Loop 3 sorozatú kompakt AIO-i
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- Notebook hibák
- Projektor topic
- Apple MacBook
- Azonnali fotós kérdések órája
Ú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?:))
- Goddess of Victory:Nikke
- Intel Core Ultra 3, Core Ultra 5, Ultra 7, Ultra 9 "Arrow Lake" LGA 1851
- Milyen videókártyát?
- Gitáros topic
- Milyen billentyűzetet vegyek?
- Telekom otthoni szolgáltatások (TV, internet, telefon)
- RAM topik
- LEGO klub
- Anglia - élmények, tapasztalatok
- Párizsi ősz, új Huawei órák
- További aktív témák...
- Bomba ár! Dell Latitude E7450 - i5-5GEN I 8GB I 250GB I 14" FHD I HDMI I Cam I W10 I Garancia!
- BESZÁMÍTÁS! Gigabyte H610M i3 12100F 16GB DDR4 512GB SSD RX 6600 8GB Zalman Z1 Plus ADATA 600W
- GeForce RTX 2060 (OEM HP) Garanciával
- BESZÁMÍTÁS! Apple Macbook Pro 13 2020 M1 16GB 1TB SSD macbook garanciával hibátlan működéssel
- HIBÁTLAN iPhone 14 128GB Red -1 ÉV GARANCIA - Kártyafüggetlen, MS3159
Állásajánlatok
Cég: FOTC
Város: Budapest