SlideShare a Scribd company logo
1 of 7
package lists;
/**
* This class represents different animal characteristics that are
recorded by the user
*
*
*/
public class Animal {
private String name;
private String color;
private String type; //vertebrate or invertebrate
private boolean canSwim;
//Constructor
public Animal(){
}
/**
* Constructor with values
* @param name name of the animal
* @param color color of the animal
* @param type represents whether its vertebrate or
invertebrate
* @param canSwim whether the animal can swim
*/
public Animal(String name,String color,String
type,boolean canSwim){
this.name=name;
this.color=color;
this.type=type;
this.canSwim=canSwim;
}
String getColor() {
return color;
}
void setColor(String color) {
this.color = color;
}
String getName() {
return name;
}
void setName(String name) {
this.name = name;
}
String getType() {
return type;
}
void setType(String type) {
this.type = type;
}
boolean isCanSwim() {
return canSwim;
}
void setCanSwim(boolean canSwim) {
this.canSwim = canSwim;
}
/**
* String representation of this animal
* @return
*/
@Override
public String toString(){
return
"[name="+name+",type="+type+",color="+color+",Can
Swim="+(canSwim?"Yes":"No");
}
}
Week 4 Discussions
Discussion # 1
Supporting Activity: Virtual Machines
Describe the three types of virtualization and at least two
benefits of virtualization.
Discussion # 2
Supporting Activity: Virtualization
What experiences have you had with virtualization in the past?
What are the benefits of using virtualization? How is it
achieved? What effects would implementing virtualization have
on an organization?
Discussion # 3
Supporting Activity: Fault Tolerance
What are the multiple aspects of a system that fault tolerance
should address? What are some of the methods used to achieve
fault tolerance? How would you make a choice between them?
package lists;
/**
*
* @author
*/
import java.util.* ;
public class ListMain {
public static void main(String[]args){
int choice=0;
Scanner scanner=new Scanner(System.in);
List<Animal> list=new ArrayList<Animal>();
int pos;
while(choice!=5){
printMenu();
System.out.print("Choose a number");
choice=scanner.nextInt();
switch(choice){
case 1:
addOrEditAnimal(list, -1,scanner);
break;
case 2:
int i=0;
for(Animal a:list){
i++;
System.out.println(i+" "+a.toString());
}
break;
case 3:
int j=0;
for(Animal a:list){
j++;
System.out.println(j+" "+a.toString());
}
System.out.println("Select position to edit");
pos=scanner.nextInt();
if(pos>0 && pos<=list.size()){
addOrEditAnimal(list, pos,scanner);
}else{
System.out.println("Animal at the given
position not found");
}
break;
case 4:
int j3=0;
for(Animal a:list){
j3++;
System.out.println(j3+" "+a.toString());
}
System.out.println("Select position to delete");
pos=scanner.nextInt();
if(pos>0 && pos<=list.size()){
list.remove(pos-1); //Actual position is
index-1
}else{
System.out.println("Animal at the given
position not found,could not delete");
}
break;
case 5:
System.out.println("Bye");
break;
default:
System.out.println("Invalid choice
<<"+choice+">>");
}
}
scanner.close();
}
/**
* Prints a list or options for user to select from
*/
public static void printMenu(){
System.out.println("1. Add animal");
System.out.println("2. List animal");
System.out.println("3. Edit animal");
System.out.println("4. Delete");
System.out.println("5. Exit");
}
/**
* Used to add or edit animal
* @param list list to add or edit animal in
* @param position negative for new and animal position for
edit
* @param sc Scanner to read input
*/
public static void addOrEditAnimal(List<Animal> list,int
position,Scanner sc){
Animal animal;
String value="";
sc.nextLine();
boolean v;
if(position>0){
animal=list.get(position-1);
System.out.println("NB:Press ENTER to skip
change");
System.out.println("Animal name:");
value=sc.nextLine();
if(value.length()>0)
animal.setName(value);
System.out.println("Animal color:");
value=sc.nextLine();
if(value.length()>0)
animal.setColor(value);
System.out.println("Vertebrate(V) or
invertebrate(I)");
value=sc.nextLine();
if(value.length()>0)
animal.setType(value);
System.out.println("Animal can swim?(Yes/No)");
value=sc.nextLine();
if(value.length()>0){
v=value.startsWith("y");
animal.setCanSwim(v);
}
}else{
animal=new Animal();
System.out.println("Animal name:");
value=sc.nextLine();
animal.setName(value);
System.out.println("Animal color:");
value=sc.nextLine();
animal.setColor(value);
System.out.println("Vertebrate(V) or
invertebrate(I)");
value=sc.nextLine();
animal.setType(value);
System.out.println("Animal can swim?(Yes/No)");
value=sc.nextLine();
v=value.startsWith("y");
animal.setCanSwim(v);
list.add(animal);
}
}
}

More Related Content

Similar to package lists; This class represents different animal ch.docx

(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdfrbjain2007
 
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;.pdfarjuncp10
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
Can someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfCan someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfarrowvisionoptics
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfcalderoncasto9163
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timekarianneberg
 
Complete skeletonimport java.util.ArrayList; public class My.pdf
Complete skeletonimport java.util.ArrayList; public class My.pdfComplete skeletonimport java.util.ArrayList; public class My.pdf
Complete skeletonimport java.util.ArrayList; public class My.pdfarhamnighty
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfkitty811
 
About java
About javaAbout java
About javaJay Xu
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfakritigallery
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfanupamagarud8
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxandreecapon
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docxKomlin1
 
JAVAAdd to the code at the bottom to do the following two things.pdf
JAVAAdd to the code at the bottom to do the following two things.pdfJAVAAdd to the code at the bottom to do the following two things.pdf
JAVAAdd to the code at the bottom to do the following two things.pdffasttracksunglass
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummiesknutmork
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfanupamagarud8
 

Similar to package lists; This class represents different animal ch.docx (20)

(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.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
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Can someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfCan someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdf
 
Java2
Java2Java2
Java2
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
 
Scala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en timeScala - fra newbie til ninja på en time
Scala - fra newbie til ninja på en time
 
Complete skeletonimport java.util.ArrayList; public class My.pdf
Complete skeletonimport java.util.ArrayList; public class My.pdfComplete skeletonimport java.util.ArrayList; public class My.pdf
Complete skeletonimport java.util.ArrayList; public class My.pdf
 
Please create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdfPlease create the appropriate JUnit test cases to thoroughly.pdf
Please create the appropriate JUnit test cases to thoroughly.pdf
 
About java
About javaAbout java
About java
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdf
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Array list
Array listArray list
Array list
 
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docx
 
JAVAAdd to the code at the bottom to do the following two things.pdf
JAVAAdd to the code at the bottom to do the following two things.pdfJAVAAdd to the code at the bottom to do the following two things.pdf
JAVAAdd to the code at the bottom to do the following two things.pdf
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummies
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
 

More from aryan532920

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxaryan532920
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxaryan532920
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxaryan532920
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxaryan532920
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxaryan532920
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxaryan532920
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxaryan532920
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxaryan532920
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxaryan532920
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxaryan532920
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxaryan532920
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxaryan532920
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxaryan532920
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxaryan532920
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxaryan532920
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxaryan532920
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxaryan532920
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxaryan532920
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxaryan532920
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxaryan532920
 

More from aryan532920 (20)

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docx
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docx
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docx
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docx
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docx
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docx
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docx
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docx
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docx
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docx
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docx
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docx
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docx
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docx
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docx
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docx
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docx
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
 

Recently uploaded

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of PlayPooky Knightsmith
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 

Recently uploaded (20)

VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 

package lists; This class represents different animal ch.docx

  • 1. package lists; /** * This class represents different animal characteristics that are recorded by the user * * */ public class Animal { private String name; private String color; private String type; //vertebrate or invertebrate private boolean canSwim; //Constructor public Animal(){ } /** * Constructor with values * @param name name of the animal * @param color color of the animal * @param type represents whether its vertebrate or invertebrate * @param canSwim whether the animal can swim */ public Animal(String name,String color,String type,boolean canSwim){ this.name=name; this.color=color; this.type=type; this.canSwim=canSwim; } String getColor() { return color; }
  • 2. void setColor(String color) { this.color = color; } String getName() { return name; } void setName(String name) { this.name = name; } String getType() { return type; } void setType(String type) { this.type = type; } boolean isCanSwim() { return canSwim; } void setCanSwim(boolean canSwim) { this.canSwim = canSwim; } /** * String representation of this animal * @return */ @Override public String toString(){ return "[name="+name+",type="+type+",color="+color+",Can Swim="+(canSwim?"Yes":"No"); } } Week 4 Discussions
  • 3. Discussion # 1 Supporting Activity: Virtual Machines Describe the three types of virtualization and at least two benefits of virtualization. Discussion # 2 Supporting Activity: Virtualization What experiences have you had with virtualization in the past? What are the benefits of using virtualization? How is it achieved? What effects would implementing virtualization have on an organization? Discussion # 3 Supporting Activity: Fault Tolerance What are the multiple aspects of a system that fault tolerance should address? What are some of the methods used to achieve fault tolerance? How would you make a choice between them? package lists; /** * * @author */ import java.util.* ; public class ListMain { public static void main(String[]args){ int choice=0; Scanner scanner=new Scanner(System.in);
  • 4. List<Animal> list=new ArrayList<Animal>(); int pos; while(choice!=5){ printMenu(); System.out.print("Choose a number"); choice=scanner.nextInt(); switch(choice){ case 1: addOrEditAnimal(list, -1,scanner); break; case 2: int i=0; for(Animal a:list){ i++; System.out.println(i+" "+a.toString()); } break; case 3: int j=0; for(Animal a:list){ j++; System.out.println(j+" "+a.toString()); } System.out.println("Select position to edit"); pos=scanner.nextInt(); if(pos>0 && pos<=list.size()){ addOrEditAnimal(list, pos,scanner); }else{ System.out.println("Animal at the given position not found"); } break; case 4: int j3=0; for(Animal a:list){
  • 5. j3++; System.out.println(j3+" "+a.toString()); } System.out.println("Select position to delete"); pos=scanner.nextInt(); if(pos>0 && pos<=list.size()){ list.remove(pos-1); //Actual position is index-1 }else{ System.out.println("Animal at the given position not found,could not delete"); } break; case 5: System.out.println("Bye"); break; default: System.out.println("Invalid choice <<"+choice+">>"); } } scanner.close(); } /** * Prints a list or options for user to select from */ public static void printMenu(){ System.out.println("1. Add animal"); System.out.println("2. List animal"); System.out.println("3. Edit animal"); System.out.println("4. Delete"); System.out.println("5. Exit"); } /** * Used to add or edit animal * @param list list to add or edit animal in
  • 6. * @param position negative for new and animal position for edit * @param sc Scanner to read input */ public static void addOrEditAnimal(List<Animal> list,int position,Scanner sc){ Animal animal; String value=""; sc.nextLine(); boolean v; if(position>0){ animal=list.get(position-1); System.out.println("NB:Press ENTER to skip change"); System.out.println("Animal name:"); value=sc.nextLine(); if(value.length()>0) animal.setName(value); System.out.println("Animal color:"); value=sc.nextLine(); if(value.length()>0) animal.setColor(value); System.out.println("Vertebrate(V) or invertebrate(I)"); value=sc.nextLine(); if(value.length()>0) animal.setType(value); System.out.println("Animal can swim?(Yes/No)"); value=sc.nextLine(); if(value.length()>0){ v=value.startsWith("y"); animal.setCanSwim(v); } }else{ animal=new Animal();
  • 7. System.out.println("Animal name:"); value=sc.nextLine(); animal.setName(value); System.out.println("Animal color:"); value=sc.nextLine(); animal.setColor(value); System.out.println("Vertebrate(V) or invertebrate(I)"); value=sc.nextLine(); animal.setType(value); System.out.println("Animal can swim?(Yes/No)"); value=sc.nextLine(); v=value.startsWith("y"); animal.setCanSwim(v); list.add(animal); } } }