Question

Matches based on preferred criteria (Matching application java based) Create a PersonProfile java class with the...

Matches based on preferred criteria (Matching application java based)
Create a PersonProfile java class with the following attributes
firstName | LastName | Nickname | age | genre |weight | height | picture | Preferences
Create a preferences java class with the following attributes:
minAge | maxAge | genre | minWeight | maxWeight | minHeight | maxHeight
Create a StackLinkedListPerson class (P.S. The object we use in the node is a person) {Node(PersonProfile)})
StackedLinkedList Male
StackedLinkedList Female
Create a MatchesProfile class
Node specificNode
StackedLinkedList Matches
Display the matesProfile of each node
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class PersonProfile{
private String firstName;
private String lastName;
private String nickName;
private int age;
private String genre;
private int weight;
private int height;
private String photo;
private Preferences preferences;
  

// constructor
PersonProfile(String firstName,String lastName, String nickName, int age, String genre, int weight, int height, String photo, Preferences preferences){
this.firstName = firstName;
this.lastName = lastName;
this.nickName = nickName;
this.age = age;
this.genre = genre;
this.weight = weight;
this.height = height;
this.photo = photo;
this.preferences = preferences;
}
  

// setters and getters
public String getFirstName(){
return firstName;
}
  
public String getLastName(){
return lastName;
}
  
public String getNickName(){
return nickName;
}
  
public int getAge(){
return age;
}
  
public String getGenre(){
return genre;
}
  
public int getWeight(){
return weight;
}
  
public int getHeight(){
return height;
}
  
public String getPhoto(){
return photo;
}
  
public Preferences getPreferences(){
return preferences;
}
}

class Preferences{
private int minAge;
private int maxAge;
private String genre;
private int minHeight;
private int maxHeight;
private int minWeight;
private int maxWeight;
  
Preferences(int minAge, int maxAge, String genre, int minHeight, int maxHeight, int minWeight, int maxWeight){
this.minAge = minAge;
this.maxAge = maxAge;
this.genre = genre;
this.minHeight = minHeight;
this.maxHeight = maxHeight;
this.minWeight = minWeight;
this.maxWeight = maxWeight;
}
  
public int getMinAge(){
return minAge;
}
  
public int getMaxAge(){
return maxAge;
}
  
public String getGenre(){
return genre;
}
  
public int getMinHeight(){
return minHeight;
}
  
public int getMaxHeight(){
return maxHeight;
}
  
public int getMinWeight(){
return minWeight;
}
  
public int getMaxWeight(){
return maxWeight;
}
}

class StackedLinkedListPerson {
  
private class Node{
PersonProfile personProfile;
Node nextProfile;
}
  
Node firstProfile;
  
StackedLinkedListPerson(){
this.firstProfile = null;
}
  
public void push(PersonProfile profile) // insert at the beginning
{
// create new node tempProfile
Node tempProfile = new Node();
  
if (tempProfile == null) {
System.out.print("\nHeap Overflow");
return;
}
  
// initialise profile into temp personProfile field
tempProfile.personProfile = profile;
  
// put firstProfile reference into temp nextProfile
tempProfile.nextProfile = firstProfile;
  
// update firstProfile reference
firstProfile = tempProfile;
}
  

// method to get profile at a given position
public PersonProfile getProfile(int count){
Node temp = firstProfile;
int tempCount = 0;
while (temp != null && tempCount!= count) {
temp = temp.nextProfile;
}
return temp.personProfile;
}
  

// method to get size
public int size(){
Node temp = firstProfile;
int tempCount = 0;
if(firstProfile != null)
tempCount++;
while (temp.nextProfile != null) {
temp = temp.nextProfile;
tempCount++;
}
return tempCount;
}
}


public class MatchesProfile{
  
public static void main(String...args){

  
System.out.println("Enter first male : ");
Scanner scan = new Scanner(System.in);
System.out.println("Enter first name : ");
String firstName = scan.next();
System.out.println("Enter last name : ");
String lastName = scan.next();
System.out.println("Enter nick name : ");
String nickName = scan.next();
System.out.println("Enter genre : ");
String genre = scan.next();
System.out.println("Enter age : ");
int age = scan.nextInt();
System.out.println("Enter weight : ");
int weight = scan.nextInt();
System.out.println("Enter height : ");
int height = scan.nextInt();
System.out.println("Enter photo : ");
String photo = scan.next();
System.out.println("Enter preferred minAge : ");
int minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
int maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
int minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
int maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
int minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
int maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
String preferredGenre = scan.next();
  
Preferences preferences1 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile male1 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences1);
  
System.out.println("Enter second male : ");
System.out.println("Enter first name : ");
firstName = scan.next();
System.out.println("Enter last name : ");
lastName = scan.next();
System.out.println("Enter nick name : ");
nickName = scan.next();
System.out.println("Enter genre : ");
genre = scan.next();
System.out.println("Enter age : ");
age = scan.nextInt();
System.out.println("Enter weight : ");
weight = scan.nextInt();
System.out.println("Enter height : ");
height = scan.nextInt();
System.out.println("Enter photo : ");
photo = scan.nextLine();
System.out.println("Enter preferred minAge : ");
minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
preferredGenre = scan.next();
  
Preferences preferences2 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile male2 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences2);
  
  
System.out.println("Enter third male : ");
System.out.println("Enter first name : ");
firstName = scan.next();
System.out.println("Enter last name : ");
lastName = scan.next();
System.out.println("Enter nick name : ");
nickName = scan.next();
System.out.println("Enter genre : ");
genre = scan.next();
System.out.println("Enter age : ");
age = scan.nextInt();
System.out.println("Enter weight : ");
weight = scan.nextInt();
System.out.println("Enter height : ");
height = scan.nextInt();
System.out.println("Enter photo : ");
photo = scan.nextLine();
System.out.println("Enter preferred minAge : ");
minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
preferredGenre = scan.next();
  
Preferences preferences3 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile male3 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences3);
  
  
StackedLinkedListPerson male = new StackedLinkedListPerson();
male.push(male1);
male.push(male2);
male.push(male3);
  
  
  
  
System.out.println("Enter first female : ");
System.out.println("Enter first name : ");
firstName = scan.next();
System.out.println("Enter last name : ");
lastName = scan.next();
System.out.println("Enter nick name : ");
nickName = scan.next();
System.out.println("Enter genre : ");
genre = scan.next();
System.out.println("Enter age : ");
age = scan.nextInt();
System.out.println("Enter weight : ");
weight = scan.nextInt();
System.out.println("Enter height : ");
height = scan.nextInt();
System.out.println("Enter photo : ");
photo = scan.nextLine();
System.out.println("Enter preferred minAge : ");
minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
preferredGenre = scan.next();
  
Preferences preferences4 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile female1 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences4);
  
System.out.println("Enter second female : ");
System.out.println("Enter first name : ");
firstName = scan.next();
System.out.println("Enter last name : ");
lastName = scan.next();
System.out.println("Enter nick name : ");
nickName = scan.next();
System.out.println("Enter genre : ");
genre = scan.next();
System.out.println("Enter age : ");
age = scan.nextInt();
System.out.println("Enter weight : ");
weight = scan.nextInt();
System.out.println("Enter height : ");
height = scan.nextInt();
System.out.println("Enter photo : ");
photo = scan.nextLine();
System.out.println("Enter preferred minAge : ");
minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
preferredGenre = scan.next();
  
Preferences preferences5 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile female2 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences5);
  
System.out.println("Enter third female : ");
System.out.println("Enter first name : ");
firstName = scan.next();
System.out.println("Enter last name : ");
lastName = scan.next();
System.out.println("Enter nick name : ");
nickName = scan.next();
System.out.println("Enter genre : ");
genre = scan.next();
System.out.println("Enter age : ");
age = scan.nextInt();
System.out.println("Enter weight : ");
weight = scan.nextInt();
System.out.println("Enter height : ");
height = scan.nextInt();
System.out.println("Enter photo : ");
photo = scan.nextLine();
System.out.println("Enter preferred minAge : ");
minAge = scan.nextInt();
System.out.println("Enter preferred maxAge : ");
maxAge = scan.nextInt();
System.out.println("Enter preferred minHeight : ");
minHeight = scan.nextInt();
System.out.println("Enter preferred maxHeight : ");
maxHeight = scan.nextInt();
System.out.println("Enter preferred minWeight : ");
minWeight = scan.nextInt();
System.out.println("Enter preferred maxWeight : ");
maxWeight = scan.nextInt();
System.out.println("Enter preferred genre : ");
preferredGenre = scan.next();
  
Preferences preferences6 = new Preferences(minAge,maxAge,preferredGenre,minHeight,maxHeight,minWeight,maxWeight);
PersonProfile female3 = new PersonProfile(firstName,lastName,nickName,age,genre,weight,height,photo,preferences6);
  
  
StackedLinkedListPerson female = new StackedLinkedListPerson();
female.push(female1);
female.push(female2);
female.push(female3);
  
StackedLinkedListPerson matchesMale = new StackedLinkedListPerson();
StackedLinkedListPerson matchesFemale = new StackedLinkedListPerson();
  

// compare male and female linkedlist and match preferences
for(int i = 0; i < male.size(); i++){
for(int j = 0; j < female.size();j++){
PersonProfile maleProfile = male.getProfile(i);
PersonProfile femaleProfile = female.getProfile(j);
  
if(maleProfile.getAge() >= femaleProfile.getPreferences().getMinAge() && maleProfile.getAge() <= femaleProfile.getPreferences().getMaxAge()
&& maleProfile.getWeight() >= femaleProfile.getPreferences().getMinWeight() && maleProfile.getWeight() <= femaleProfile.getPreferences().getMaxWeight()
&& maleProfile.getHeight() >= femaleProfile.getPreferences().getMinHeight() && maleProfile.getHeight() <= femaleProfile.getPreferences().getMaxHeight()
&& maleProfile.getGenre().equals(femaleProfile.getPreferences().getGenre())){
if(femaleProfile.getAge() >= maleProfile.getPreferences().getMinAge() && femaleProfile.getAge() <= maleProfile.getPreferences().getMaxAge()
&& femaleProfile.getWeight() >= maleProfile.getPreferences().getMinWeight() && femaleProfile.getWeight() <= maleProfile.getPreferences().getMaxWeight()
&& femaleProfile.getHeight() >= maleProfile.getPreferences().getMinHeight() && femaleProfile.getHeight() <= maleProfile.getPreferences().getMaxHeight()
&& femaleProfile.getGenre().equals(maleProfile.getPreferences().getGenre())){
  
matchesMale.push(maleProfile);
matchesFemale.push(femaleProfile); // if matched add to list
  
  
}
}
}
}
  

// Display the matched mates data
if(matchesMale.size() > 0) {
for(int i = 0; i < matchesMale.size(); i++){
System.out.println("Matched Male Profile details : ");
PersonProfile maleProfile = matchesMale.getProfile(i);
PersonProfile femaleProfile = matchesFemale.getProfile(i);
System.out.println(maleProfile.getFirstName() +" "+ maleProfile.getLastName() +" "+maleProfile.getAge() + " "+maleProfile.getNickName() + " "+maleProfile.getGenre()+
" "+ maleProfile.getWeight()+" "+maleProfile.getHeight()+" ");
  
System.out.println(femaleProfile.getFirstName() +" "+ femaleProfile.getLastName() +" "+femaleProfile.getAge() + " "+femaleProfile.getNickName() + " "+femaleProfile.getGenre()+
" "+ femaleProfile.getWeight()+" "+femaleProfile.getHeight()+" ");
}
  
}
}
}

// Output

Enter first male : Enter first name : sam Enter last name : curran Enter nick name : curry Enter genre : rocky Enter age : En

// Check screenshots below for indentation

class PersonProfile private String firstName; private String lastName; private String nickName; private int age; private Stri

public int getWeight({ return weight; public int getHeight { return height; public String getPhotoO{ return photo; public Pre

public PersonProfile getProfile(int count) { Node temp = firstProfile; int tempCount = 0; while (temp != null && temp Count !

Add a comment
Know the answer?
Add Answer to:
Matches based on preferred criteria (Matching application java based) Create a PersonProfile java class with the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create a java class named Person that has 3 attributes: name, age and weight. include a...

    create a java class named Person that has 3 attributes: name, age and weight. include a default and parametrize constructor. include all setters and getters needed and a method that is used to display the information about the person

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • answer in c# console application. File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use...

    answer in c# console application. File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use radioButtons for gender in the GUI) ) Create a List<Person> Create a GUI that will collect the Person information from the user and have 3 buttons: Add, Display, Read. Add button Add the just created person to List<Person>, and append to a text file Display button > print out all persons currently in the List<Person> in a label in a visually attractive way Read...

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • In NetBeans Create a new Java Application to manage Linked Lists: (Note: Do not use java.util.LinkedList)...

    In NetBeans Create a new Java Application to manage Linked Lists: (Note: Do not use java.util.LinkedList) a) Create a DateTime class 1. Add day, month, year, hours, minutes as attributes 2. Add a constructor and a toString() method 3. Implement the Comparable interface, and add a CompareTo() method 4. Add methods to get and set all attributes. b) Add to MyLinkedList class the following methods: 1. Insert a Node to a particular position in the List 2. Insert a Node...

  • In Python a class can inherit from more than one class (Java does not allow this)....

    In Python a class can inherit from more than one class (Java does not allow this). The resulting class will have all the methods and attributes from the parent classes. Do the following: • Create a class called Person. In the class, define variables for storing date of birth, place of birth, and male/female attributes. In the class, define the constructor method, as well as methods for returning current values of the class attributes. • Create a class called Employee....

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides...

    Question 1 (24 Marks] 1. (4 marks) Write an immutable Person class in Java which provides the following. • Two attributes: lastName and first Name of type String. • Appropriate initialization, accessors/mutator methods. 2. (6 marks) Write a Student class that is a subclass of Person class (in the previous question) which provides the following. • Two attributes: A unique student ID of type String and GPA of type float; the student ID is initialized when a Student object gets...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT