Vorige onderwerp :: Volgende onderwerp |
Auteur |
Bericht |
stekkew

Geregistreerd op: 06 Okt 2010 Berichten: 44 Woonplaats: Herent
|
Geplaatst: 21-10-2010 16:41:29 Onderwerp: Klasse euro |
|
|
public class Euro {
private int euro;
private int cent;
public Euro(){
setEuro(0);
setCent(0);
}
public Euro(int euro, int cent){
setEuro(euro);
setCent(cent);
}
public int getEuro(){
return euro;
}
public int getEC(){
return cent;
}
public void setEuro(int e){
if(e >= 0 && e < 100){
this.euro = e;
}
else if(e > 100){
this.euro = this.euro + (e/100);
this.cent = this.cent + (e%100);
}
else{
System.out.println("Je kan geen negatief getal hebben");
this.cent = 0;
this.euro = 0;
}
}
public void setCent(int c){
if (c >= 0 && c<100){
this.cent = this.cent + c;
}
else if(c >= 100 && this.euro!=0){
this.euro = this.euro + (c/100);
this.cent = this.cent + (c%100);
}
else{
System.out.println("Je kan niet minder dan 0 cent hebben...");
this.euro = 0;
this.cent = 0;
}
}
public int zetOmInCent(){
int aantalCent = this.cent + this.euro*100;
return aantalCent;
}
public String toString(){
String uitvoer = new String("Je hebt " + this.euro + " euro en " + this.cent + " cent.");
return uitvoer;
}
public Euro addEuro(Euro bedrag){
Euro nieuwBedrag = new Euro();
int nieuwEuro = 0;
int nieuwCent = 0;
if(bedrag == null){
nieuwBedrag = null;
}
else{
nieuwEuro = this.euro + bedrag.getEuro();
nieuwCent = this.cent + bedrag.getEC();
nieuwBedrag = new Euro(nieuwEuro, nieuwCent);
}
return nieuwBedrag;
}
public Euro subtractEuro(Euro bedrag){
int nieuwEuro = 0;
int nieuwCent = 0;
if bedrag
if(this.euro >= bedrag.getEuro()){
nieuwEuro = this.euro - bedrag.getEuro();
}
else{
System.out.println("Je hebt te weinig euro's...");
}
if(this.cent >= bedrag.getEC()){
nieuwCent = this.cent - bedrag.getEC();
}
else{
System.out.println("Je hebt te weinig centen...");
}
Euro nieuwBedrag = new Euro(nieuwEuro, nieuwCent);
return nieuwBedrag;
}
public boolean isMinder(Euro bedrag){
boolean test = false;
if(bedrag == null){
test = false;
}
else{
if (this.zetOmInCent() < bedrag.zetOmInCent()){
test = true;
}
else{
test = false;
}
}
return test;
}
public boolean isZelfde(Euro bedrag){
boolean test = false;
if(bedrag == null){
test = false;
}
else{ if(this.zetOmInCent() == bedrag.zetOmInCent()){
test = true;
}
else{
test = false;
}
}
return test;
}
} |
|
Terug naar boven |
|
 |
berghmansseppe Site Admin

Geregistreerd op: 06 Okt 2010 Berichten: 17 Woonplaats: wezelhoevenweg 41a
|
Geplaatst: 21-10-2010 16:47:38 Onderwerp: Re: Klasse euro |
|
|
stekkew schreef: |
public class Euro {
private int euro;
private int cent;
public Euro(){
setEuro(0);
setCent(0);
}
public Euro(int euro, int cent){
setEuro(euro);
setCent(cent);
}
public int getEuro(){
return euro;
}
public int getEC(){
return cent;
}
public void setEuro(int e){
if(e >= 0 && e < 100){
this.euro = e;
}
else if(e > 100){
this.euro = this.euro + (e/100);
this.cent = this.cent + (e%100);
}
else{
System.out.println("Je kan geen negatief getal hebben");
this.cent = 0;
this.euro = 0;
}
}
public void setCent(int c){
if (c >= 0 && c<100){
this.cent = this.cent + c;
}
else if(c >= 100 && this.euro!=0){
this.euro = this.euro + (c/100);
this.cent = this.cent + (c%100);
}
else{
System.out.println("Je kan niet minder dan 0 cent hebben...");
this.euro = 0;
this.cent = 0;
}
}
public int zetOmInCent(){
int aantalCent = this.cent + this.euro*100;
return aantalCent;
}
public String toString(){
String uitvoer = new String("Je hebt " + this.euro + " euro en " + this.cent + " cent.");
return uitvoer;
}
public Euro addEuro(Euro bedrag){
Euro nieuwBedrag = new Euro();
int nieuwEuro = 0;
int nieuwCent = 0;
if(bedrag == null){
nieuwBedrag = null;
}
else{
nieuwEuro = this.euro + bedrag.getEuro();
nieuwCent = this.cent + bedrag.getEC();
nieuwBedrag = new Euro(nieuwEuro, nieuwCent);
}
return nieuwBedrag;
}
public Euro subtractEuro(Euro bedrag){
int nieuwEuro = 0;
int nieuwCent = 0;
if bedrag
if(this.euro >= bedrag.getEuro()){
nieuwEuro = this.euro - bedrag.getEuro();
}
else{
System.out.println("Je hebt te weinig euro's...");
}
if(this.cent >= bedrag.getEC()){
nieuwCent = this.cent - bedrag.getEC();
}
else{
System.out.println("Je hebt te weinig centen...");
}
Euro nieuwBedrag = new Euro(nieuwEuro, nieuwCent);
return nieuwBedrag;
}
public boolean isMinder(Euro bedrag){
boolean test = false;
if(bedrag == null){
test = false;
}
else{
if (this.zetOmInCent() < bedrag.zetOmInCent()){
test = true;
}
else{
test = false;
}
}
return test;
}
public boolean isZelfde(Euro bedrag){
boolean test = false;
if(bedrag == null){
test = false;
}
else{ if(this.zetOmInCent() == bedrag.zetOmInCent()){
test = true;
}
else{
test = false;
}
}
return test;
}
} |
subustract is nog NIE af ! |
|
Terug naar boven |
|
 |
|