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. ...
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;
}
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();