Question

In: Computer Science

Specifications: This project will have two data classes and a tester class. Design: Create a solution...

Specifications:

This project will have two data classes and a tester class.

Design:

Create a solution for this programming task. You will need to have the following parts:

  • Text file to store data between runs.
  • Two classes that implement the given interfaces. You may add methods beyond those in the interfaces
  • A tester class that tests all of the methods of the data classes.

Here are the interfaces for your data classes:

package project1;

import java.util.ArrayList;

public interface Person {

      

       public void setId (String id);

       public String getId ();

       public void setName (String name);  

       public String getName ();

       public void addTHING (String THING);

       public void removeTHING (String THING);

       public ArrayList<String> getTHINGs ();

       public String toString();

}

package project1;

import java.util.ArrayList;

public interface PersonDataManager {

       public void addPerson (Person p);

       public Person getPerson (String id);
       public ArrayList<String> getTHINGSDESCRIPTION (ArrayList<String> THINGs); //for this, its just a set of descriptions for THINGs (just use THINGdescription1, 2, 3 for each one and ill do the rest

       public void writeToFile ();

       public void writeToFile (String fn);

       public String toString();

}

For ace's, they are either going to be a 1 or 0 for 10 different attributes. I only need a basic skeleton for the code and can do the rest but I am struggling with the starting point

Solutions

Expert Solution

Try to edit code, its simple code to understand how interface will be implemented..

/*****************************Person1.java************************/

package project1;

import java.util.ArrayList;
import java.util.Iterator;


/**
* The Class Person1.
*/
public class Person1 implements Person {

   /** The id. */
   private String id;

   /** The name. */
   private String name;

   /** The things. */
   private ArrayList<String> things;

   /**
   * Instantiates a new person 1.
   *
   * @param id the id
   * @param name the name
   */
   public Person1(String id, String name) {
       super();
       this.id = id;
       this.name = name;
       things = new ArrayList<>();
   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#setId(java.lang.String)
   */
   @Override
   public void setId(String id) {

       this.id = id;
   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#getId()
   */
   @Override
   public String getId() {

       return id;
   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#setName(java.lang.String)
   */
   @Override
   public void setName(String name) {

       this.name = name;

   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#getName()
   */
   @Override
   public String getName() {

       return name;
   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#addTHING(java.lang.String)
   */
   @Override
   public void addTHING(String THING) {

       this.things.add(THING);
   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#removeTHING(java.lang.String)
   */
   @Override
   public void removeTHING(String THING) {

       Iterator<String> itr = things.iterator();
       while (itr.hasNext()) {

           String thing = itr.next();

           if (thing.equalsIgnoreCase(THING)) {

               itr.remove();
           }
       }

   }

   /*
   * (non-Javadoc)
   *
   * @see project1.Person#getTHINGs()
   */
   @Override
   public ArrayList<String> getTHINGs() {

       return things;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Person1 [id=" + id + ", name=" + name + ", things=" + things + "]";
   }

}
/**************************************PersonData.java**********************/

package project1;

import java.io.File;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;

/**
* The Class PersonData.
*/
public class PersonData implements PersonDataManager {

   /** The persons. */
   private ArrayList<Person> persons;

   /**
   * Instantiates a new person data.
   */
   public PersonData() {
       persons = new ArrayList<>();
   }

   /* (non-Javadoc)
   * @see project1.PersonDataManager#addPerson(project1.Person)
   */
   @Override
   public void addPerson(Person p) {

       persons.add(p);
   }

   /* (non-Javadoc)
   * @see project1.PersonDataManager#getPerson(java.lang.String)
   */
   @Override
   public Person getPerson(String id) {

       Person actPerson = null;
       for (Person person : persons) {

           if (person.getId().equalsIgnoreCase(id)) {

               actPerson = person;
           }
       }

       return actPerson;
   }

   /* (non-Javadoc)
   * @see project1.PersonDataManager#getTHINGSDESCRIPTION(java.util.ArrayList)
   */
   @Override
   public ArrayList<String> getTHINGSDESCRIPTION(ArrayList<String> THINGs) {

       return null;
   }

   /* (non-Javadoc)
   * @see project1.PersonDataManager#writeToFile()
   */
   @Override
   public void writeToFile() {

   }

   /* (non-Javadoc)
   * @see project1.PersonDataManager#writeToFile(java.lang.String)
   */
   @Override
   public void writeToFile(String fn) throws Exception {

       Writer rw = new PrintWriter(new File(fn));
       for (Person person : persons) {

           rw.write(person.toString());
       }

   }
}
/*************************************TestPerson.java*********************/

package project1;

public class TestPerson {

   public static void main(String[] args) {
      
       Person1 person1 = new Person1("A101", "Virat");
       person1.addTHING("Thing1");
       person1.addTHING("Thing2");
       person1.addTHING("Thing3");
      
       PersonData personData = new PersonData();
      
       personData.addPerson(person1);
       personData.writeToFile("out.txt");
       System.out.println(personData.getPerson("A101"));
   }
}
/***************output***************/

Person1 [id=A101, name=Virat, things=[Thing1, Thing2, Thing3]]
/****************out.txt********************/

Person1 [id=A101, name=Virat, things=[Thing1, Thing2, Thing3]]

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Specifications: This project will have two data classes and a tester class. Design: Create a solution...
Specifications: This project will have two data classes and a tester class. Design: Create a solution for this programming task. You will need to have the following parts: Text file to store data between runs. Two classes that implement the given interfaces. You may add methods beyond those in the interfaces A tester class that tests all of the methods of the data classes. Here are the interfaces for your data classes: package project1; import java.util.ArrayList; public interface Person {...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape,...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape, Two Dimensional Shape, Three Dimensional Shape, Square, Circle, Cube, Rectangular Prism, and Sphere. Cube should inherit from Rectangular Prism. The two dimensional shapes should include methods to calculate Area. The three dimensional shapes should include methods to calculate surface area and volume. Use as little methods as possible (total, across all classes) to accomplish this, think about what logic should be written at which...
Create a new project in BlueJ. Create two new classes in the project, with the following...
Create a new project in BlueJ. Create two new classes in the project, with the following specifications: Class name: Part Fields: id (int) description (String) price (double) onSale (boolean) 1 Constructor: takes parameters partId, partDescrip, and partPrice to initialize fields id, description, and price; sets onSale field to false. Methods: Write get-methods (getters) for all four fields. The getters should be named getId, getDescription, getPrice, and isOnSale.
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
Design You will need to have at least four classes: a parent class, a child class,...
Design You will need to have at least four classes: a parent class, a child class, a component class, and an unrelated class. The component object can be included as a field in any of the other three classes. Think about what each of the classes will represent. What added or modified methods will the child class have? What added fields will the child class have? Where does the component belong? How will the unrelated class interact with the others?...
How can the classes be modified to satisfy the comments & example tester: public class InvalidIntegerException...
How can the classes be modified to satisfy the comments & example tester: public class InvalidIntegerException extends Exception{ // Write a class for an InvalidIntegerException here //Constructor that takes no arguments public InvalidIntegerException (){ super(); } //Constructor that takes a string message public InvalidIntegerException (String message){ super(message); } } import java.io.InputStream; import java.io.IOException; public class Parser { private InputStream in; public static final int CHAR_ZERO = (int) '0'; public Parser (InputStream in) { this.in = in; } // Complete the...
Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours...
Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type double. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type double. For each class, provide its getter and setter functions, a default constructor, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for the Services class...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and  numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which...
Design c++ program so that it correctly meets the program specifications given below.   Specifications: Create a...
Design c++ program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT