Question

In this assignment you will practice using Data Structures and Object Oriented concepts in Java. Your implementation should target the most efficient algorithms and data structures. You will be graded...

In this assignment you will practice using Data Structures and Object Oriented concepts in Java. Your implementation should target the most efficient algorithms and data structures. You will be graded based on the efficiency of your implementation. You will not be awarded any points if you use simple nested loops to implement the below tasks. You should use one or more of the below data structures: - ArrayList : - JavaDoc: http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html - Tutorial: http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html Question You are provided with the Data class that contains a users array (Data.users) which is an array of users. Each element in the array represents a single user record. Each record is a string formatted as : firstname, lastname, age,email, gender, city, state. You are asked to perform the following tasks: 1. YourimplementationforthisquestionshouldbeincludedinMainPart1.javafile. 2. Create a User class that should parse all the parameters for each user. Hint: extract each value from a user's record using Java's String.split() method and set the delimiter to a comma. Each user record should to be assigned to a User object. 3. YourgoalistoPrintouttheTOP10oldestusers. 4. Hint: To sort use the Collections.sort(). http://docs.oracle.com/javase/6/docs/api/java/util/ Collections.html

also I shared the file in goolgle drive: https://drive.google.com/file/d/1YJiug2s21mzYoXkeoQocZeNg-yz5AOZt/view?usp=sharing
https://drive.google.com/file/d/1pylRrOhNUFthzzK-ZCs5Uh5I4DyeMDBW/view?usp=sharing

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//code screenshot

MainPart1.java Data.java 1 package edu.sfsu.cs.datastructures; 3e import java.util.* 4 import java. lang. 5 import java.io.*System.out.printlnGstr; 61 63 65 67 for (String str : Data.users) String[ userval-str.split(,; //System.out.println userval

//code to copy

package edu.sfsu.cs.datastructures;

import java.util.*;

import java.lang.*;

import java.io.*;

class User

{

private String firstName,lastName,email,gender,city,profession;

private int age;

public User(String firstName,String lastName,int age,String email,String gender, String city,String profession)

{

this.firstName=firstName;

this.lastName=lastName;

this.age=age;

this.email=email;

this.gender=gender;

this.city=city;

this.profession=profession;

}

String getfirstName()

{

return firstName;

}

int getAge()

{

return age;

}

public String toString()

{

return firstName+","+lastName+","+age+","+email+","+gender+","+city+","+profession;

}

};

class Sortbyage implements Comparator<User>

{

// Used for sorting in ascending order of

// roll number

public int compare(User a, User b)

{

return (b.getAge() - a.getAge()); //desending order

}

};

public class MainPart1 {

/*

* Question 1:

* - In this question you will use the Data.users array that includes

* a list of users. Formatted as : firstname,lastname,age,email,gender,city,state

* - Create a User class that should parse all the parameters for each user.

* - Insert each of the users in a list.

* - Print out the TOP 10 oldest users.

* */

private static ArrayList<User> userlist = new ArrayList<User>();

public static void main(String[] args) {

//example on how to access the Data.users array.

/* for (String str : Data.users) {

System.out.println(str);

}*/

for (String str : Data.users) {

String[] userval=str.split(",");

//System.out.println(userval[0]);

User newuser=new User(userval[0],userval[1],Integer.parseInt(userval[2]),userval[3],userval[4],userval[5],userval[6]);

userlist.add(newuser);

}

Collections.sort(userlist, new Sortbyage());

for(int i=0;i<10;i++)

{

System.out.println(userlist.get(i));

}

}

};

//output screenshot

Camala, MacMorland, 100, ㎝a㎝orland5deredcross . org, Female, Charlotte, NC Addie, Swatten, 108,aswattenSp@icio.us,Male,Winter

Add a comment
Know the answer?
Add Answer to:
In this assignment you will practice using Data Structures and Object Oriented concepts in Java. Your implementation should target the most efficient algorithms and data structures. You will be graded...
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
  • For practice using exceptions, this exercise will use a try/catch block to validate integer input from...

    For practice using exceptions, this exercise will use a try/catch block to validate integer input from a user. Write a brief program to test the user input. Use a try/catch block, request user entry of an integer, use Scanner to read the input, throw an InputMismatchException if the input is not valid, and display "This is an invalid entry, please enter an integer" when an exception is thrown. InputMismatchException is one of the existing Java exceptions thrown by the Scanner...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • Could I get some help with this assignment In this assignment, you'll write a program which...

    Could I get some help with this assignment In this assignment, you'll write a program which reads a text file, and prints a histogram of its word sizes. So, for example, the historgram should show the number of words of length 1, of length 2, etc., up to the number of words of length n, where n is some constant defined in your program. To obtain text files that are suitably long, you could try Project Gutenberg, a site containing...

  • Source material: Object-Oriented Data Structures Using Java, 3rd Edition by Nell Dale. What is the answer...

    Source material: Object-Oriented Data Structures Using Java, 3rd Edition by Nell Dale. What is the answer to exercise 13 in chapter 3 (page 232)?? "A. Create a "standard" exception class called ThirteenException. B. Write a program that repeatedly prompts the user to enter a string. After each string is entered the program outputs the length of the string, unless the length of the string is 13, in which case the ThirteenException is thrown with the message "Use thirteen letter words...

  • JAVA, please You must write a robust program meaning that your program should not crash with...

    JAVA, please You must write a robust program meaning that your program should not crash with any given data. Data validation must be done any time that user enters an input. Write a program that 1. Gets an infix expression form the user and evaluate the expression using stack ADT a. Finds the postfix equivalent of the given infix expression b. Evaluate the created postfix expression. c. Note: your program should not crash when you enter an invalid expression such...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

  • JAVA - Please follow ALL instructions, thank you!! Here is the API, for a Point class...

    JAVA - Please follow ALL instructions, thank you!! Here is the API, for a Point class representing a 2-dimensional point. https://docs.oracle.com/javase/7/docs/api/java/awt/Point.html Code an application class: 1.) (i.e., a class containing a main method), 2.) named PointApp that reads point data from the file points.text. This data is then used to create pairs of Point objects which are then used to flex (i.e, illustrate) the methods of the class. The format of the points.text file is: x1 y1 x2 y2 …...

  • Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you...

    Objective In this assignment, you will practice solving a problem using object-oriented programming and specifically, you will use the concept of object aggregation (i.e., has-a relationship between objects). You will implement a Java application, called MovieApplication that could be used in the movie industry. You are asked to implement three classes: Movie, Distributor, and MovieDriver. Each of these classes is described below. Problem Description The Movie class represents a movie and has the following attributes: name (of type String), directorName...

  • Suppose that we want to help physicians to diagnose illnesses. A physician observes a patient's symptoms and considers the illnesses that could be associated with those symptoms. Design and implem...

    Suppose that we want to help physicians to diagnose illnesses. A physician observes a patient's symptoms and considers the illnesses that could be associated with those symptoms. Design and implement a class PhysiciansHelper thatprovide a list of those illnesses. PhysiciansHelper should contain a dictionary of illnesses and symptoms. A method should read a text file of illnesses and their symptoms into the dictionary. See format in sample data file. PhysiciansHelper should read a list of symptoms for a patient. A...

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