
//java code
import org.codehaus.jackson.map.ObjectMapper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
public class Student implements {
private String name;
private int age;
private float height;
private float weight;
public Student() {
}
public Student(String name, int age, float height, float weight) {
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public static void main(String args[]) throws Exception {
//creating a list of objects
File file = new File("<pathToFile>/information.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
int i=0;
HashMap <String, Object> temp = new HashMap<>();
ArrayList<HashMap<String, Object> > h = new ArrayList<>();
while ((st = br.readLine()) != null) {
temp.clear();
String[] split = st.split(" ");
String name = (split[0]);
int age = Integer.parseInt(split[1]);
float height = Float.parseFloat(split[2]);
float weight = Float.parseFloat(split[3]);
//System.out.println(st);
Student s= new Student();
s.setAge(age);
s.setHeight(height);
s.setName(name);
s.setWeight(weight);
temp.put("age", s.getAge());
temp.put("height", s.getHeight());
temp.put("name", s.getName());
temp.put("weight", s.getWeight());
}
if(i<5){
h.set(i, temp );
i++;
}
//sorting to be done
ArrayList<HashMap<String, Object>> sorted_list = new ArrayList<>();
sorted_list = sort("age");
sorted_list = sort("name");
sorted_list = sort("height");
sorted_list = sort("weight");
}
public ArrayList<HashMap<String, Object>> sort (String sortBy){
ArrayList<HashMap<String, Object>> h = new ArrayList<>();
HashMap<String, Object> temporary;
for (int c = 0; c < (h.size() - 1); c++) {
for (int d = 0; d < (h.size() - c - 1); d++) {
if ((h.get(d).get(sortBy)).compareTo((h.get(d + 1).get(sortBy)))>0 ) {
temporary = h.get(d);
h.set(d, h.get(d + 1));
h.set(d + 1, temporary);
}
}
}
return h;
}
}
//information.txt file
john, 23, 6.3, 70 mona, 22, 5.8, 55 lisa, 30, 4.9, 44 joey, 33, 5.8, 60 ram, 21, 6, 77
Visual C# Homework 2 You are to write a program which will create a class called...
C++ There is a class called Person which has name and age as private variables. Another class called Student, which is derived from person with gpa and id as variables. name is a string, age and id are integers and gpa is a double... All of them are private variables. age, gpa and id should be generated randomly when the object is created with the following ranges: age 20 to 32 gpa 0.0 to 4.0 // this one is tricky...
*** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long). 1. Include a member function called get_data( ) to get data from the user for insertion into the object, 2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...
VISUAL BASIC- create a program for managing a "To Do" list. The program will need to read and update a text file named ToDoList.txt. The record structure of the file must be: 1) sort order, 2) task name and 3) desired completion date. When the program starts, it should read the contents file into a structure. The information should then be displayed in a data grid view. The data should be initially sorted by the sort order value. Afterwards, the...
FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...
Write a program that will maintain a personal phonebook. The program should be menu driven. Create a new phonebook Print the phonebook Add person to the phonebook Remove a person from the phonebook Sort Modify a person Search for a person by name Save to a data file (Can't be done but leave an error message if the user selects) Retreive phonebook from data file (Can't be done but leave an error message if the user selects) Quit Create a...
You will be designing and creating a Java GUI-based course application. Create a “Student” class. You need to have at least 3 instance variables (student characteristics like name,…), at least 2 constructors (1 should be a no-arg constructor), set and get methods. Create a “Course” class that consists of 2 instance variables: the course name and an array of Students (using your Student class). Design and create a JavaFX-based GUI interface that allows you to : INPUT information for Course...
Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...
Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...
Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{ char name[50]; int id; float...
You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...