Calculate GPA And Sort A Column In CSV File
Jan 30, 2015
I am having a hard time compiling this code: I need to calculate the gpa of each student in the csv file which looks like this:
ID First Name Last NameClass LevelDesired ClassCreditsPoints GPA
9410917 Reagan Walls SophomoreCOMP 18275 77 1.026667
13498070 Stewart Fry Senior COMP 10070 92 1.314286
37500410 Talon Witt Junior COMP 100107 389 3.635514
47845461 Ciara Beard Grad COMP 11097 196 2.020619
The GPA column needs to be added by dividing the points by credits. I also need to sort the class level column by class level. For example:
ID First NameLast NameClass LevelDesired ClassCreditsPointsGPA
9410917 Reagan Walls SophomoreCOMP 18275 77 1.026667
46309070 Ivy Valdez SophomoreCOMP 1006 16 2.666667
37405616 Miriam Welch SophomoreCOMP 11057 179 3.140351
Here is my code:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.String;
import java.io.File;
import java.io.PrintStream;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.util.Comparator;
[code]...
I am taking the two things that needed to be outputted, one at a time. Working on the GPA portion.
View Replies
ADVERTISEMENT
Feb 19, 2015
I am trying to sort a JTable on an all numeric (integer) column. From what I read, if the sorter knows the type is integer it should sort correctly. This is my code:
public class ActorTableModel extends DefaultTableModel {
private static final long serialVersionUID = 1005352603826663105L;
public ActorTableModel (Object data[][],Object columnNames[]) {
super(data,columnNames);
}
public Class<?> getColumnClass (int column) {
if (column==0) {
return(Integer.class);
}
return(String.class);
}
}
The result is when I sort on that column (0), it sorts alphabetically not numerically.
View Replies
View Related
Mar 3, 2014
personid gender height class
1 female 1.6 short
2 male 2.0 tall
3 male 1.85 medium
4 female 1.9 medium
5 male 1.7 short
6 female 1.8 medium
7 female 1.95 medium
for eg i have to find minimum and maximum height from column height.
View Replies
View Related
Dec 19, 2014
I am trying to merge two files together using the Apache Commons CSV library. I figured it was easier to use this than to write my own implementation.
The first problem is that the output contains the underlying class logic and as a results my output contains a bunch of un-needed data. How do I get rid of this? I just want the column and row data, nothing else.
Example
I want this:
customerNo, firstName, lastName, birthDate, mailingAddress, married, numberOfKids, favouriteQuote, email, loyaltyPoints
1, John, Dunbar, 13/06/1945, 1600 Amphitheatre Parkway Mountain View, CA 94043
But I get this:
CSVRecord [comment=null, mapping=null, recordNumber=1, values=[customerNo, firstName, lastName, birthDate, mailingAddress, married, numberOfKids, favouriteQuote, email, loyaltyPoints]]
CSVRecord [comment=null, mapping=null, recordNumber=2, values=[1, John, Dunbar, 13/06/1945, 1600 Amphitheatre Parkway
Mountain View, CA 94043
The second problem is that I just want the row Headers from the first file, but the row headers from my second file are still being included in my output. I used withSkipHeaderRecord(true), but it didn't have the desired results.
Code is below.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.ArrayList;
[Code] .....
View Replies
View Related
Apr 13, 2014
I have to write a program that reads from a file like this( in attached file)
after line 28 ,column 5 have H,G,S...,
I WANT TO READ THIS COLUMN AND SPLIT THE 4 AND MORE H SAME HHHH AND MORE IN ONE SEPARATE FILE AND IN ANOTHER FILE HAVE EEEE AND MORE ....
View Replies
View Related
May 25, 2013
how to set the columnwidth in csv file using javacode.
I used FileWriter class to upload data into the csv file but csv file is taking default width while showing content. Is there a way to set the fixed column width or set width dinamically based on value?
View Replies
View Related
Sep 25, 2014
I want to read this csv file and store contents on column basis; as date (single array) for all dates. open, high, low and close and be able to manipulate individual elements of the array such as Sum += close[i];
public void pratice() throws Exception {
// Create a File instance
BufferedReader br=new BufferedReader(new FileReader("gtk.csv"));
content = new String[1000];
while(content !=null) {
content[++count] = br.readLine();
[Code] .....
the file looks like this
date Open high low close
12-12-2011 15.00 15.40 14.5 15.2
11-12-2011 15.02 15.70 14.9 15.00
10-12-2011 14.70 16.00 14.70 15.02
...
View Replies
View Related
Dec 17, 2014
I need to print contents of database to excel file.Apache POI is the solution but I am not finding a way to print the DB column names/headers into the excel.
E.g.:
incase csv we have opencsv CSVWriter writer = new CSVWriter(new FileWriter(fileName));
System.out.println("writer");
writer.writeAll(rs, true);
will print the db contents with the column headers dynamically whatever the query may be.
Any solution where we can print data and column names without know the query previously as we are getting query at the run time and each time the query is different.
INPUT
DATABASE
Emp Id. Emp Name
111 Mr.Test
EXCEL
Emp Id. Emp Name
111 Mr.Test
View Replies
View Related
Nov 27, 2014
I working on a bank program that gets a user id, name and balance from a text file. I need to be able to sort based on each field. I'm using Collection.sort and Comparator. I'm using String[] array = file.toFile().list(); to get the values for the array from the text file. I can't figure out how to make this into an arraylist. I understand the concept when hardcoding the data but having trouble doing it from a text file.
View Replies
View Related
Jun 30, 2014
I'm supposed to write a program, which reads float numbers from a file, puts them in an array and sorts the array. After that I'm suppose to add the numbers so that when I add the 1 and 2 number of the array, I'm suppose to save the sum on the position of number 1, then I add number 3 and 4 and save the sum on position 2 etc. Also if my array has an uneven number of floats it's suppose to add the last 3 and not 2 numbers in the last iteration. The problem is the method throws an ArrayOutOfBounds Exception but I can't seem to find my mistake.
That's the second method. The first one just stores the sum in another variable and then returns it. Also is there a way in that I can Scanner/File/array etc. and initialize the array only once so I don't write the same code two times like it is now.
package sumOfFloats;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class SumOfFloats {
public static float sumFloats() throws FileNotFoundException{
[Code[ ....
View Replies
View Related
Dec 9, 2014
I am catching an error in my driver class that reads from a file and sorts the data based on a person's GPA. Here is my code:
import java.io.*;
import java.util.*;
public class Driver {
public static void main(String[] args) {
new Driver(args[0]);
[Code] ....
Why throwing this exception?
View Replies
View Related
Oct 30, 2014
I have to calculate auto and cross-correlation from a file, like this:
Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))
and after
Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))
I've 600 x an y,
k = the numbers of x (N is the last one)
n = 0....N-1
View Replies
View Related
Oct 26, 2014
I have to calculate auto and cross-correlation from a file, like this:
Rxx(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*x(k+n)-x(mean))
and after
Rxy(n)= 1/N* SUM[from k=1 to N-n]((x(k)-x(mean))*y(k+n)-y(mean))
I've 600 x an y,
k = the numbers of x (N is the last one)
n = 0....N-1
already calculated mean, and I've tried the following (but it doesnt work):
String sor;
int i=0;
while ((sor = br.readLine()) != null) {
String [] adatok =sor.trim().split(",");
[Code] ....
View Replies
View Related
Feb 1, 2014
My assignment is to make GUI to calculate orders and to save the calculation to .csv file.I have solved "save" button and it really does save my input to .csv file.But, my problem is "Load button" When I press it, how to load .csv file to my existing JTextFields?
View Replies
View Related
Oct 21, 2014
Write a method that returns the sum of all the elements in a specified column ina matrix using the following header:
Public static double sumColumn(double[][] m, int columnIndex)
Write a test program that reads a 3 by 4 matrix and displays the sum of each column.
import java.util.*;
public class SumColumns {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
final int ROW = 3;
final int COLUMN = 4;
[Code] .....
View Replies
View Related
Apr 22, 2015
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt
Displays Data with calculation
Creates a file called "Newbalance.txt" with the following values:
111
251.41
222
402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Output {
public static void main(String[]args) throws IOException {
[Code] .....
View Replies
View Related
Mar 11, 2014
How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.
View Replies
View Related
Jun 9, 2014
how can i get id from db table for each column values with java or oracle query? i did get before each column content from file and now i need get the id of this column values from db. I read csv files from folder and then load the data from these files into subfolder, and here with line li = line.split(","); i get the values that i have in csv file and split them and become in li the value name, and then in else block i create a P objekt where i set this values from csv files, and with [I]p.setLid(li);
I set the value for all valuenames, and then get these valuenames in separate column with other content from this csv, and my question is, i need to do this with db, and write these csv file values to the table in db (it will be done with another java class), what i need, that to write the ids of these values into the table in db, instead of valuename, and while there is no ids for valuenames in csv files, i need to get the id from the table in db where these are already listed with sequences.
I don't know how can i write in data table the id of this valuenames and other content, this data table should contain the ids of valuenames timestamp values and the ids of the csv files name, i don't know how to do this with the ids, i must get the ids from the db table and then set these on [I]p.setLid(li); where i set early the valuenames, instead of valuenames i should set ids, that will set ids automatically for all these valuenames.
try {
while ((line = br.readLine()) != null) {
if (lc == 0) {
li = line.split(",");
} else {
String[] temp = line.split(",");
for (int i = 1; i < temp.length; i++) {
p = new P();
[code]....
i got the values that then will be given to [I]p.setLid(li); and iterate, but now i want to get id from the table in db where this values stored with id instead of this column values, how can i do it?
View Replies
View Related
Mar 29, 2014
Since the array is always passed by refrence, it should have been modified, but it did not.
This is my code:
import java.util.Random;
class DiceRolling {
public void processDice() {
int [] frequency = new int [ 13 ];//frequency of every occurence of sum
[Code] ....
View Replies
View Related
Jan 14, 2014
i want to write a program have a array 2d like that :
int array [][] = new int [3][3]
after that the user input value by using scanner then give summation of each column in matrix , i wrote this one
Java Code:
class MatrixSum{
public static void main(String[] args) {
int matrix1[][]= {{7,8,9},{1,5,2}};
int matrix2[][]= {{1,6,4},{2,7,3}};
System.out.println("Number of Row= " + matrix1.length);
System.out.println("Number of Column= " + matrix1[1].length);
int l = matrix1.length;
System.out.println("Matrix 1 : ");
for(int i = 0; i < l; i++) {
[code]...
but i want to change that the user input the value by using scanner.
View Replies
View Related
Sep 28, 2014
I need to add a column to my array and copy an old array and then fill the new array with another array..However, unfortunately it does not work. I found this code online..but it seems it does not work.
static float[][] temperatures = new float[5][6];
static float[] d=new float[5];
float[][] neww;
int am,am1,am2,am3,res1,res2;
public static void main(String[] args) {
float[][] neww= Arrays.copyOf(temperatures, temperatures.length+1);
neww[temperatures.length]= new float[temperatures.length];
for (int i = 0; i < temperatures.length; i++) {
neww[temperatures.length][i] = Float.valueOf(d[i]);
}
View Replies
View Related
Oct 6, 2014
i have to read a text doc that has 149392014080186 (station# year/month/day temp) many more following but i have to read the temp and determine if it is under 80 degress my code so far is the second scanner reads the text file i need the 1st scanner reads the user info
/******************************************************************************
*
* Filename : ClimateSummary.java.
* Description: This program computes summaries of climate data and reads if it is rainy/not rainy or cold/hot.
*
******************************************************************************/
//imports everything needed to run the program
import java.util.Scanner;
import java.io.*;
[code]....
View Replies
View Related
Mar 23, 2014
Is it possible to pass column name as a parameter using servlets?
I tried using the following code but it doesnt work
String date=request.getParameter("date");
String sql="alter table cs1_cn add " +date+ " boolean";
PreparedStatement ps=conn.prepareStatement(sql);
View Replies
View Related
Nov 5, 2014
i am trying to code the averages across column but I end up with the wrong averages.
My test cases:
name 0 1 2 3 overall grade
Badger,Bradley 37 70 51 48 68.66666666666667
Emu,Emma 35 81 75 40 72.83333333333334
Aardvark,Alice 42 85 22 0 65.11111111111111
Dodo,Donald exc 12 25 0 54.17391304347826
Cassowary,Cassie 50 97 72 68 62.758620689655174
My code:
public static double[] computeAllGrades(int[][] scoreTable, int[] itemPointValues) {
{
double totalPoints = 0;
double totalPointsPossible = 0;
double allGrades[];
double grade =0;
[code]....
View Replies
View Related
Feb 9, 2015
I've been creating a jTable where I can add / edit /delete new entries. Now i have 2 Questions :
1) My column 0 is filled with the row-number. I created a variable and with each "add" it adds +1 to the variable. That works, but as soon as i delete 1 row there is a gap ( 1..2..4..5..).
My question: Is there another way then mine to handle this?
2) The table is/should be working as some kind of database. The user is able to add Information (height, width,...). Now I want to sum the entries of 1 column (length,...). But as they´re objects I didn´t find a way.
My question: How can I sum the entries of 1 column of a table?
View Replies
View Related
Jan 6, 2015
how I can highlight one column with color? When i add color to a column the entire table is colored.
View Replies
View Related