Question
I Need this code but working in C++ ------------------------------------------------------ // dogs.txt (Input file) German Shepherd,Furs,yes Pug,Emma,no Goldendoodle,Ketchup,yes ================================= // Dog.java public class Dog { private
I Need this code but working in C++ ------------------------------------------------------
// dogs.txt (Input file)
German Shepherd,Furs,yes Pug,Emma,no Goldendoodle,Ketchup,yes
=================================
// Dog.java
public class Dog { private String breed; private String name; private boolean isScaryOfCat;
/** * @param breed * @param name * @param isScaryOfCat */ public Dog(String breed, String name, boolean isScaryOfCat) { this.breed = breed; this.name = name; this.isScaryOfCat = isScaryOfCat; }
/** * @return the breed */ public String getBreed() { return breed; }
/** * @param breed * the breed to set */ public void setBreed(String breed) { this.breed = breed; }
/** * @return the name */ public String getName() { return name; }
/** * @param name * the name to set */ public void setName(String name) { this.name = name; }
/** * @return the isScaryOfCat */ public boolean isScaryOfCat() { return isScaryOfCat; }
/** * @param isScaryOfCat * the isScaryOfCat to set */ public void setScaryOfCat(boolean isScaryOfCat) { this.isScaryOfCat = isScaryOfCat; }
/* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "Dog [breed=" + breed + ", name=" + name + ", isScaryOfCat=" + isScaryOfCat + "]"; }
}
===========================================
// Dog_Park.java
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner;
public class Dog_Park {
public static void main(String[] args) throws IOException { Dog d=null; ArrayList
int res=isCatScary(d);
if(res==1) { dog_park2.add(d); } } sc.close(); writeToFile("Pug"); System.out.println("Displaying the Dogs Info which are not scary of Cats :"); for(int i=0;i
}
private static void writeToFile(String breed) throws IOException { Dog d=null; Scanner sc=new Scanner(new File("dogs.txt")); FileWriter fw=new FileWriter(new File("DogData.txt")); while(sc.hasNext()) { String line=sc.nextLine(); String arr[]=line.split(","); if(arr[2].equalsIgnoreCase("no")) { d=new Dog(arr[0],arr[1],false); } else { d=new Dog(arr[0],arr[1],true); } if(d.getBreed().equalsIgnoreCase(breed)) { fw.write(d.getName()+" "); } } sc.close(); fw.close(); }
private static int isCatScary(Dog d) {
if(!d.isScaryOfCat()) { return 1; } return 0; }
}
========================================
Output:
Displaying the Dogs Info which are not scary of Cats : Dog [breed=Pug, name=Emma, isScaryOfCat=false] ========================================
// DogsData.txt (Output file)
Canvas - Question pos Problem 2: Code (82 points) Using the Dog class below (0 points if you do not use the Dog class below to hold dog infol. create a Dog parkclass. The Dog park class should have a constructor that takes a filename parameter (10 points and creates the dogs in the file (see sample fle-YOUR CODE SHOULD HANDLE ANY FILE, NOT JUST THE SAMPLE FILE) (20 points. The Dog park class should have two public functions: -a function to allow dogs to enter the dog park if they aren't scaredy cats. This function should take a Dos parameter and have an int return type (10 points). If the dog is not a scaredy cat, it should be added to the other dogs in the park (from the file) and 1 should be returned (10 points). It should return otherwise (5 points). -a function to output a nie of dogs of a specific breed. This function should take a string parameter (10 points the breed to output and output a file of the names of all dogs in the park of that breed (15 points). It should have a vald return type 12 points) Sample file: German Shepherd.Furs.yes Pug Emma.no//breed, name, scaredy_cat fyestrue, nowfalse) Goldendoodle Ketchup yes F6 F7 FBStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started