2
I have the addCurso method that receives a parameter that is a course type object, it has information such as name and area, all within the College class, which has a vector where these courses will be adapted. I have to do the check before if, the vector position is empty, I get, but also if there is no other course within this vector with the same name. How could I do this?
public class Faculdade
{
private String nameFac;
private int yearCreation;
private Cursos []catalogoCursos;
private Cursos[]cursosNovos;
public Faculdade(String nameFacParam, int yearCreationParam){
this.nameFac=nameFacParam;
this.yearCreation=yearCreationParam;
this.catalogoCursos=new Cursos[20];
this.cursosNovos=new Cursos[5];
}
public void setnameFac(String nameAc){
this.nameFac=nameAc;
}
public String getnameFac(){
return this.nameFac;
}
public void setyearCreation(int year){
this.yearCreation=year;
}
public int getyearCreation(){
return this.yearCreation;
}
public void addCurso(Cursos novoCurso){
for(int i=0;i<catalogoCursos.length;i++){
if(catalogoCursos[i]==null){
catalogoCursos[i]=novoCurso;
}
}
}
public void deleteCurso(String nome){
for(int i=0;i<catalogoCursos.length;i++){
if(catalogoCursos[i]!=null){
if(catalogoCursos[i].getname().equals(nome)){
catalogoCursos[i]=null;
break;
}
else
System.out.print("Curso não encontrado, ou não existente.");
}
}
}
public Faculdade(int yearCreation){
this("Facs",yearCreation);
for(int i=0;i<catalogoCursos.length;i++){
if(catalogoCursos[i]!=null){
if(catalogoCursos[i].getyear()>(getyearCreation()+5)){
cursosNovos[i]=catalogoCursos[i];
}
}
}
}
}
The course class:
public class Cursos
{
private String code,name;
private int duration;
private float cost;
private int year;
public Cursos(String code, String name, int duration,float cost, int year){
this.code=code;
this.name=name;
this.duration=duration;
this.cost=cost;
this.year=year;
}
public Cursos(String code, String name,float cost,int year){
this(code,name,8,cost,year);
}
public void setcode(String code){
this.code=code;
}
public String getcode(){
return this.code;
}
public void setname(String name){
this.name=name;
}
public String getname(){
return this.name;
}
public void setduration(int duration){
this.duration=duration;
}
public int getduration(){
return this.duration;
}
public void setcost(float cost){
this.cost=cost;
}
public float getcost(){
return this.cost;
}
public void setyear(int year){
this.year=year;
}
public int getyear(){
return this.year;
}
public void calculateCost(){
float value=0,semestre=6;
value=getcost()/(getduration()*semestre);
}
}
Opa Marcela, insert in the question the basis of your code so far so that we can use to answer.
– André Lins