SlideShare a Scribd company logo
My code is not matching up with the results.
The output for the code should be:
>>> Test Teacher class
Teacher: Paul Tan(8 sunset way)
IM101 added.
IM102 added.
IM101 cannot be added.
IM101 removed.
IM101 removed.
IM102 removed.
IM102 cannot be removed.
Person class:
public class Person {
private String name;
private String address;
public Person(String name, String address) {
this.name = name;
this.address = address;
}
public Person(String address){
this.address = address;
}
public String getName(){
return name;
}
public String getAddress(){
return address;
}
public void setAddress(String address){
this.address = address;
}
public String toString() {
return name + "(" + address + ")";
}
}
Teacher sub class
import java.util.ArrayList;
public class Teacher extends Person {
private int numCourses = 0;
private ArrayList courses = new ArrayList();
public Teacher(String name, String address){
super(name,address);
}
@Override
public String toString() {
return "Teacher: " + super.toString();
}
public boolean addCourse (String course){
for (int i = 0; i < numCourses; i++) {
if (courses.get(i).equals(course))
return false;
}
courses.add(course);
numCourses++;
return true;
}
public boolean removeCourse (String course){
boolean found = false;
int courseIndex = -1;
for (int j = 0; j < numCourses; j++) {
if (courses.get(j).equals(course)) {
courseIndex = j;
found = true;
break;
}
}
if (found) {
for (int k = courseIndex; k < numCourses-1; k++) {
courses.get(k+1);
}
numCourses--;
return true;
}
else {
return false;
}
}
}
Person Launcer
System.out.println(" ");
System.out.println(">>> Test Teacher class");
Teacher tch = new Teacher ("Paul Tan", "8 sunset way");
System.out.println(tch);
String[] courses = {"IM101", "IM102", "IM101"};
for (String course: courses) {
if (tch.addCourse(course)) {
System.out.println(course + " added.");
} else {
System.out.println(course + " cannot be added.");
}
}
for (String course: courses) {
if (tch.removeCourse(course)) {
System.out.println(course + " removed.");
} else {
System.out.println(course + " cannot be removed.");
}
}
System.out.println(" ");
Solution
// edit the below method like this :
public boolean removeCourse (String course){
boolean found = false;
int courseIndex = -1;
for (int j = 0; j < numCourses; j++) {
if (courses.get(j).equals(course)) {
courseIndex = j;
found = true;
break;
}
}
if (found) {
courses.remove(course);
numCourses--;
return true;
}
else {
return false;
}
}

More Related Content

Similar to My code is not matching up with the results.The output for the cod.pdf

public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
arjuncp10
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
ArafatSahinAfridi
 
Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)Yugeswary
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
Filip Ekberg
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
Sagie Davidovich
 
source-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaisource-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawai
Kang Fatur
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
arishmarketing21
 
Add a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdfAdd a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdf
SebastianRzuHarrisw
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
Ganesh Samarthyam
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
fatoryoutlets
 
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdfProblem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
mumnesh
 
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
why will it not display all of the entries--  output -nMenu n-Add Entr.pdfwhy will it not display all of the entries--  output -nMenu n-Add Entr.pdf
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
abc2232
 
Groovy
GroovyGroovy
Day_2.1.pptx
Day_2.1.pptxDay_2.1.pptx
Day_2.1.pptx
ishasharma835109
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existente
Mariano Sánchez
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
pnaran46
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simple
leonsabr
 

Similar to My code is not matching up with the results.The output for the cod.pdf (20)

public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
Rd
RdRd
Rd
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
Refactoring
RefactoringRefactoring
Refactoring
 
source-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaisource-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawai
 
please help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdfplease help with java questionsJAVA CODEplease check my code and.pdf
please help with java questionsJAVA CODEplease check my code and.pdf
 
Add a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdfAdd a private variable SSN to the person class- Add a private variable.pdf
Add a private variable SSN to the person class- Add a private variable.pdf
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdfProblem 1 Create Node class (or use what you have done in Lab4)• .pdf
Problem 1 Create Node class (or use what you have done in Lab4)• .pdf
 
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
why will it not display all of the entries--  output -nMenu n-Add Entr.pdfwhy will it not display all of the entries--  output -nMenu n-Add Entr.pdf
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
 
Groovy
GroovyGroovy
Groovy
 
Day_2.1.pptx
Day_2.1.pptxDay_2.1.pptx
Day_2.1.pptx
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existente
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simple
 

More from solimankellymattwe60

What are the products of the secondary metabolism in plants Terpeno.pdf
What are the products of the secondary metabolism in plants  Terpeno.pdfWhat are the products of the secondary metabolism in plants  Terpeno.pdf
What are the products of the secondary metabolism in plants Terpeno.pdf
solimankellymattwe60
 
Which of the following is incorrect about emergent propertiesA. T.pdf
Which of the following is incorrect about emergent propertiesA. T.pdfWhich of the following is incorrect about emergent propertiesA. T.pdf
Which of the following is incorrect about emergent propertiesA. T.pdf
solimankellymattwe60
 
Which sensor i can use it for my robot when i dont want it to fil.pdf
Which sensor i can use it for my robot when i dont want it to fil.pdfWhich sensor i can use it for my robot when i dont want it to fil.pdf
Which sensor i can use it for my robot when i dont want it to fil.pdf
solimankellymattwe60
 
Why might firms consider issuing stock in foreign countries Why mig.pdf
Why might firms consider issuing stock in foreign countries Why mig.pdfWhy might firms consider issuing stock in foreign countries Why mig.pdf
Why might firms consider issuing stock in foreign countries Why mig.pdf
solimankellymattwe60
 
What were the Spanish soldiers who fought in the conquests in the Ne.pdf
What were the Spanish soldiers who fought in the conquests in the Ne.pdfWhat were the Spanish soldiers who fought in the conquests in the Ne.pdf
What were the Spanish soldiers who fought in the conquests in the Ne.pdf
solimankellymattwe60
 
What is forecasting Explain the different techniques of forecasting.pdf
What is forecasting Explain the different techniques of forecasting.pdfWhat is forecasting Explain the different techniques of forecasting.pdf
What is forecasting Explain the different techniques of forecasting.pdf
solimankellymattwe60
 
Ventura Capital is a financier who specializes in capitalizing start.pdf
Ventura Capital is a financier who specializes in capitalizing start.pdfVentura Capital is a financier who specializes in capitalizing start.pdf
Ventura Capital is a financier who specializes in capitalizing start.pdf
solimankellymattwe60
 
True or False1. A basidium is a cell of the Basidiomycota in whic.pdf
True or False1. A basidium is a cell of the Basidiomycota in whic.pdfTrue or False1. A basidium is a cell of the Basidiomycota in whic.pdf
True or False1. A basidium is a cell of the Basidiomycota in whic.pdf
solimankellymattwe60
 
The mitochondrial electron transport system (METS) and the photos.pdf
The mitochondrial electron transport system (METS) and the photos.pdfThe mitochondrial electron transport system (METS) and the photos.pdf
The mitochondrial electron transport system (METS) and the photos.pdf
solimankellymattwe60
 
The disclosure of a contingent liability in the footnotes and on t.pdf
The disclosure of a contingent liability in the footnotes and on t.pdfThe disclosure of a contingent liability in the footnotes and on t.pdf
The disclosure of a contingent liability in the footnotes and on t.pdf
solimankellymattwe60
 
The application architeture is design by the application developer a.pdf
The application architeture is design by the application developer a.pdfThe application architeture is design by the application developer a.pdf
The application architeture is design by the application developer a.pdf
solimankellymattwe60
 
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdfSuppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
solimankellymattwe60
 
Some historians have referred to many of the self-proclaimed “Darwin.pdf
Some historians have referred to many of the self-proclaimed “Darwin.pdfSome historians have referred to many of the self-proclaimed “Darwin.pdf
Some historians have referred to many of the self-proclaimed “Darwin.pdf
solimankellymattwe60
 
Please research Meaningful Use. Prepare a brief report on its origin.pdf
Please research Meaningful Use. Prepare a brief report on its origin.pdfPlease research Meaningful Use. Prepare a brief report on its origin.pdf
Please research Meaningful Use. Prepare a brief report on its origin.pdf
solimankellymattwe60
 
Mention the major difference in the physical phenomena occurring rel.pdf
Mention the major difference in the physical phenomena occurring rel.pdfMention the major difference in the physical phenomena occurring rel.pdf
Mention the major difference in the physical phenomena occurring rel.pdf
solimankellymattwe60
 
Logical FallociesP1 All college students have pet monkeys.P2 J.pdf
Logical FallociesP1 All college students have pet monkeys.P2 J.pdfLogical FallociesP1 All college students have pet monkeys.P2 J.pdf
Logical FallociesP1 All college students have pet monkeys.P2 J.pdf
solimankellymattwe60
 
IP Security One problem with Internet protocol (IP) is that it has.pdf
IP Security One problem with Internet protocol (IP) is that it has.pdfIP Security One problem with Internet protocol (IP) is that it has.pdf
IP Security One problem with Internet protocol (IP) is that it has.pdf
solimankellymattwe60
 
Genmo CorporationOn the night of February 27, 2012, certain recor.pdf
Genmo CorporationOn the night of February 27, 2012, certain recor.pdfGenmo CorporationOn the night of February 27, 2012, certain recor.pdf
Genmo CorporationOn the night of February 27, 2012, certain recor.pdf
solimankellymattwe60
 
In the formula for determining a populations genotype frequencies, .pdf
In the formula for determining a populations genotype frequencies, .pdfIn the formula for determining a populations genotype frequencies, .pdf
In the formula for determining a populations genotype frequencies, .pdf
solimankellymattwe60
 
How is a cell membrane selectively permeable - what permeates and.pdf
How is a cell membrane selectively permeable - what permeates and.pdfHow is a cell membrane selectively permeable - what permeates and.pdf
How is a cell membrane selectively permeable - what permeates and.pdf
solimankellymattwe60
 

More from solimankellymattwe60 (20)

What are the products of the secondary metabolism in plants Terpeno.pdf
What are the products of the secondary metabolism in plants  Terpeno.pdfWhat are the products of the secondary metabolism in plants  Terpeno.pdf
What are the products of the secondary metabolism in plants Terpeno.pdf
 
Which of the following is incorrect about emergent propertiesA. T.pdf
Which of the following is incorrect about emergent propertiesA. T.pdfWhich of the following is incorrect about emergent propertiesA. T.pdf
Which of the following is incorrect about emergent propertiesA. T.pdf
 
Which sensor i can use it for my robot when i dont want it to fil.pdf
Which sensor i can use it for my robot when i dont want it to fil.pdfWhich sensor i can use it for my robot when i dont want it to fil.pdf
Which sensor i can use it for my robot when i dont want it to fil.pdf
 
Why might firms consider issuing stock in foreign countries Why mig.pdf
Why might firms consider issuing stock in foreign countries Why mig.pdfWhy might firms consider issuing stock in foreign countries Why mig.pdf
Why might firms consider issuing stock in foreign countries Why mig.pdf
 
What were the Spanish soldiers who fought in the conquests in the Ne.pdf
What were the Spanish soldiers who fought in the conquests in the Ne.pdfWhat were the Spanish soldiers who fought in the conquests in the Ne.pdf
What were the Spanish soldiers who fought in the conquests in the Ne.pdf
 
What is forecasting Explain the different techniques of forecasting.pdf
What is forecasting Explain the different techniques of forecasting.pdfWhat is forecasting Explain the different techniques of forecasting.pdf
What is forecasting Explain the different techniques of forecasting.pdf
 
Ventura Capital is a financier who specializes in capitalizing start.pdf
Ventura Capital is a financier who specializes in capitalizing start.pdfVentura Capital is a financier who specializes in capitalizing start.pdf
Ventura Capital is a financier who specializes in capitalizing start.pdf
 
True or False1. A basidium is a cell of the Basidiomycota in whic.pdf
True or False1. A basidium is a cell of the Basidiomycota in whic.pdfTrue or False1. A basidium is a cell of the Basidiomycota in whic.pdf
True or False1. A basidium is a cell of the Basidiomycota in whic.pdf
 
The mitochondrial electron transport system (METS) and the photos.pdf
The mitochondrial electron transport system (METS) and the photos.pdfThe mitochondrial electron transport system (METS) and the photos.pdf
The mitochondrial electron transport system (METS) and the photos.pdf
 
The disclosure of a contingent liability in the footnotes and on t.pdf
The disclosure of a contingent liability in the footnotes and on t.pdfThe disclosure of a contingent liability in the footnotes and on t.pdf
The disclosure of a contingent liability in the footnotes and on t.pdf
 
The application architeture is design by the application developer a.pdf
The application architeture is design by the application developer a.pdfThe application architeture is design by the application developer a.pdf
The application architeture is design by the application developer a.pdf
 
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdfSuppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
Suppose a company’s ROE is 16. This company’s payout ratio is 40. .pdf
 
Some historians have referred to many of the self-proclaimed “Darwin.pdf
Some historians have referred to many of the self-proclaimed “Darwin.pdfSome historians have referred to many of the self-proclaimed “Darwin.pdf
Some historians have referred to many of the self-proclaimed “Darwin.pdf
 
Please research Meaningful Use. Prepare a brief report on its origin.pdf
Please research Meaningful Use. Prepare a brief report on its origin.pdfPlease research Meaningful Use. Prepare a brief report on its origin.pdf
Please research Meaningful Use. Prepare a brief report on its origin.pdf
 
Mention the major difference in the physical phenomena occurring rel.pdf
Mention the major difference in the physical phenomena occurring rel.pdfMention the major difference in the physical phenomena occurring rel.pdf
Mention the major difference in the physical phenomena occurring rel.pdf
 
Logical FallociesP1 All college students have pet monkeys.P2 J.pdf
Logical FallociesP1 All college students have pet monkeys.P2 J.pdfLogical FallociesP1 All college students have pet monkeys.P2 J.pdf
Logical FallociesP1 All college students have pet monkeys.P2 J.pdf
 
IP Security One problem with Internet protocol (IP) is that it has.pdf
IP Security One problem with Internet protocol (IP) is that it has.pdfIP Security One problem with Internet protocol (IP) is that it has.pdf
IP Security One problem with Internet protocol (IP) is that it has.pdf
 
Genmo CorporationOn the night of February 27, 2012, certain recor.pdf
Genmo CorporationOn the night of February 27, 2012, certain recor.pdfGenmo CorporationOn the night of February 27, 2012, certain recor.pdf
Genmo CorporationOn the night of February 27, 2012, certain recor.pdf
 
In the formula for determining a populations genotype frequencies, .pdf
In the formula for determining a populations genotype frequencies, .pdfIn the formula for determining a populations genotype frequencies, .pdf
In the formula for determining a populations genotype frequencies, .pdf
 
How is a cell membrane selectively permeable - what permeates and.pdf
How is a cell membrane selectively permeable - what permeates and.pdfHow is a cell membrane selectively permeable - what permeates and.pdf
How is a cell membrane selectively permeable - what permeates and.pdf
 

Recently uploaded

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

My code is not matching up with the results.The output for the cod.pdf

  • 1. My code is not matching up with the results. The output for the code should be: >>> Test Teacher class Teacher: Paul Tan(8 sunset way) IM101 added. IM102 added. IM101 cannot be added. IM101 removed. IM101 removed. IM102 removed. IM102 cannot be removed. Person class: public class Person { private String name; private String address; public Person(String name, String address) { this.name = name; this.address = address; } public Person(String address){ this.address = address; } public String getName(){ return name; } public String getAddress(){ return address; } public void setAddress(String address){ this.address = address;
  • 2. } public String toString() { return name + "(" + address + ")"; } } Teacher sub class import java.util.ArrayList; public class Teacher extends Person { private int numCourses = 0; private ArrayList courses = new ArrayList(); public Teacher(String name, String address){ super(name,address); } @Override public String toString() { return "Teacher: " + super.toString(); } public boolean addCourse (String course){ for (int i = 0; i < numCourses; i++) { if (courses.get(i).equals(course)) return false; } courses.add(course); numCourses++; return true; } public boolean removeCourse (String course){ boolean found = false; int courseIndex = -1; for (int j = 0; j < numCourses; j++) { if (courses.get(j).equals(course)) { courseIndex = j; found = true; break;
  • 3. } } if (found) { for (int k = courseIndex; k < numCourses-1; k++) { courses.get(k+1); } numCourses--; return true; } else { return false; } } } Person Launcer System.out.println(" "); System.out.println(">>> Test Teacher class"); Teacher tch = new Teacher ("Paul Tan", "8 sunset way"); System.out.println(tch); String[] courses = {"IM101", "IM102", "IM101"}; for (String course: courses) { if (tch.addCourse(course)) { System.out.println(course + " added."); } else { System.out.println(course + " cannot be added."); } } for (String course: courses) { if (tch.removeCourse(course)) { System.out.println(course + " removed."); } else { System.out.println(course + " cannot be removed."); } } System.out.println(" ");
  • 4. Solution // edit the below method like this : public boolean removeCourse (String course){ boolean found = false; int courseIndex = -1; for (int j = 0; j < numCourses; j++) { if (courses.get(j).equals(course)) { courseIndex = j; found = true; break; } } if (found) { courses.remove(course); numCourses--; return true; } else { return false; } }