13 Replies - 1342 Views - Last Post: 16 December 2013 - 12:16 PM Rate Topic: -----

#1 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Urgent code help needed

Posted 16 December 2013 - 10:01 AM

I have my final assignment due in two hours, the code I needed didn't save and all the data I had on Eclipse was erased. I had help doing it before so I don't remember it all. A quick run down of the basic functions of the code needed: It reads this file, then out puts however many students it is asked to read. Using this code:
import java.util.Scanner;


public class Finalassignment{
	public static void main(String[] args) throws Exception {
		Scanner input = new Scanner(System.in);
		String fileName;

		System.out.print("Enter file name: ");
		fileName = input.nextLine();
		System.out.print("Enter number of Students: ");

		int limit = input.nextInt();

		java.io.File file = new java.io.File(fileName + ".txt");
		Scanner fInput = new Scanner(file);
		int numLines = 0;

		while (fInput.hasNextLine()) {
			System.out.println(fInput.nextLine());

			if (++numLines == limit + 2) {
				break;
			}
		}

		fInput.close();
		input.close();
		
		System.out.println("");



The second part of the code is supposed to ask the user to enter a Student ID, then out put their Last Name, First Name, Average, and Letter Grade. Entering the number 0 would end the run, and an ID that doesn't exist should produce "Invalid ID". This second part of the code is what I lost. I have no idea how to approach it because I was helped on this part before. I'm turning to you amazing people of D.I.C. I need your help.

-Screwed College Student

Is This A Good Question/Topic? 0
  • +

Replies To: Urgent code help needed

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 10:07 AM

Quote

I have no idea how to approach it because I was helped on this part before.

Would you be more specific on what you need help on.
Was This Post Helpful? 0
  • +
  • -

#3 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 10:24 AM

The second part of this code should ask the user to enter a student ID after asking how many student record they'd like to see. After Entering a student's ID, if it exists, it should output: Lastname, First Name, Average, Letter Grade. If they ID doesn't exist, it should output "Invalid ID". If the user enters 0, it should end the run. Something like this:
Enter file name: data
Enter number of Students: 5
No.   St ID	Last name	First name	Quiz 1	Quiz 2	Quiz 3	Quiz 4	Final  Avg   Grd
------------------------------------------------------------------------------------------------
 1    32998	Benway		Eileen		76	98	80	75	95     90.3   A-
 2    15246	Berling		Danielle	85	64	0	69	85     78.8   C+
 3    94304	Bowdy		James		0	57	70	92	98     84.5   B
 4    50838	Burr		Jermiah		83	84	94	77	63     80.2   B-
 5    84511	Calluari	Henry		72	84	97	73	74     83.2   B-

Enter Student ID: 32998
Benway, Eileen. Average: 90.3 Grade:A-
Enter Student ID: 23232
Invalid ID
Enter a Student ID: 0
End of run



I have no idea how to get it to do that.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3687
  • View blog
  • Posts: 16,920
  • Joined: 20-September 08

Re: Urgent code help needed

Posted 16 December 2013 - 10:25 AM

Quote

I have my final assignment due in two hours, the code I needed didn't save and all the data I had on Eclipse was erased.

tbh it sounds a bit like an 'Eclipse ate my homework' story. As it happens, Eclipse takes auto-backups by default
Was This Post Helpful? 0
  • +
  • -

#5 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 10:29 AM

I checked the folder where they're normally saved and nothing was there. As far as I can tell a lot of stuff is missing from my computer. I had to reinstall chrome to post here because that was gone. I'm taking my SSD into repairs to see if something happened to it.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 10:56 AM

I have no idea how to get it to do that. [/quote]
Okay.. I am unclear if you are asking for folks to just do the work for you, or what.

You did this work before.. you solved this problem before.. yet you come back at the problem and are unsure where to start? I am not seeing how that follows.

You seem to have a handle on reading each line of the file in.. then just scan the line for logical breaks (tables, X number of spaces, etc).. store the data in (I assume for this class) a custom class with members that are all the required fields.. searching is a matter of looping through this collection of your custom class.
Was This Post Helpful? 0
  • +
  • -

#7 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 11:00 AM

The code that reads the file is the part I did. I had a friend help me on the second part (the part that sorts through the IDs, matches them, and outputs the desired info) but now that I don't have it I can't do it because I didn't know how to do it in the first place. I know it says "We won't do your homework for you" but a little help would be amazing right now.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 11:06 AM

Quote

but a little help would be amazing right now

Okay then put forth some effort, or I'll chalk this up to someone who wants the work done for them (as it sounds like it was original done for them). To put it another way folks get super duper generic on what help they need as a cover/code phrase for "just give me the completed work". I am looking to see which category you fall into..

Have you investigated anything from my previous post? A custom class? A generic collection of that class? A for loop to cycle through the collection?

http://docs.oracle.c.../util/List.html
Was This Post Helpful? 0
  • +
  • -

#9 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 11:11 AM

I know this needs a huge array with every piece of data that the file has in it. I'm terrible with strings and arrays which is why I don't know how to approach it. I have to leave in an hour, there's no way I can get this done. I appreciate your response and efforts. Sorry about this post
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 11:15 AM

No.. it doesn't need a huge array.. I mean.. sure I could use one, but a custom class that holds a string for each column of data.. then when you read in each line you would parse it and fill in a new instance of your custom class.. then add that custom class to the list<> collection.

No need for brittle or hardsized arrays.

http://www.dreaminco...igning-classes/
http://www.dreaminco...ing-classes-ii/
Was This Post Helpful? 0
  • +
  • -

#11 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 11:26 AM

I'm in an intro to programming class, I don't know how to do what you're suggesting. This is all I've got.

import java.util.Scanner;


public class Finalexam{
	public static void main(String[] args) throws Exception {
		Scanner input = new Scanner(System.in);
		String fileName;

		System.out.print("Enter file name: ");
		fileName = input.nextLine();
		System.out.print("Enter number of Students: ");

		int limit = input.nextInt();

		java.io.File file = new java.io.File(fileName + ".txt");
		Scanner fInput = new Scanner(file);
		int numLines = 0;

		while (fInput.hasNextLine()) {
			System.out.println(fInput.nextLine());

			if (++numLines == limit + 2) {
				break;
			}
		}

		fInput.close();
		input.close();
		
		System.out.println("");
		System.out.print("Enter Student ID: ");
		
		}

	
		String[][] studentArray = 
			{ 
				{"32998" }, { "Benway","Eileen","76","98","80","75","95","90.3","" },
				{"15246" }, { "Berling","Danielle","85","64","0","69","85","78.8","" },
				{"94304"}, { "Bowdy","James","76","98","80","75","90","90.3","" },
				{"50838"}, { "Burr","Jerimiah","85","64","0","69","85","78.8","" },
				{"84511"}, { "Calluari","Henry","72","84","97","73","74","83.2","" },
				{"77921"}, { "Connrs","Sarah","72","84","97","73","74","83.2","" },
				{"24609"}, { "Cooper","Camille","62","93","92","58","66","78.7","" },
				{"28248"}, { "Courville","David","81","88","89","84","87","8608","" },
				{"61084"}, { "Cruz","Waldemar","70","68","76","100","86","86.3","" },
				{"10364"}, { "Denaro","Tony","73","85","55","68","89","81.5","" },
				{"17600"}, { "DeNinno","David","62","68","93","84","75","81.3","" },
				{"54321"}, { "Doe","John","0","0","0","0","50","16.7","" },
				{"61316"}, { "Eaton","John","80","51","93","90","69","61.0","" },
				{"44520"}, { "Ecklord","Ryan","0","61","56","98","83","76.2","" },
				{"58751"}, { "Flores","Jose","0","80","0","87","69","61.0","" },
				{"54378"}, { "Franco-Banks","Nixaliz","99","58","80","63","83","81.6","" },
				{"18140"}, { "Galotti","Salvator","78","65","90","88","98","90.4","" },
				{"36278"}, { "Hartman","Kristine","100","62","71","69","55","82.4","" },
				{"85736"}, { "Hepburn","Spencer","71","0","62","52","51","57","" },
				{"43865"}, { "Hildebrandt","Stphenson","97","94","93","82","100","96.8","" },
				{"72054"}, { "Houde","Jessica","72","66","71","75","100","83.6","" },
				{"10984"}, { "Juste","Kerlande","97","73","98","96","57","81.0","" },
				{"55937"}, { "Kantzios","Angela","55","0","78","93","76","75.6","" },
				{"39473"}, { "Kenyon","Patricia","65","54","90","94","97","88.6","" },
				{"59640"}, { "Knieriem","Brandon","52","87","97","97","56","79.0","" },
				{"80886"}, { "Laflamme","Nicole","76","51","71","69","91","79.6","" },
				{"16137"}, { "Littlefield","Arionna","71","85","74","69","95","84.0","" },
				{"12137"}, { "McCabe","Kelly","51","96","0","54","94","77.8","" },
				{"65328"}, { "Middleton","Middle","75","0","75","75","75","75.0","" },
				{"87129"}, { "Morang","Nicholas","77","67","57","88","78","75.6","" },
				{"28810"}, { "Navin","Joshua","94","75","62","64","94","84.2","" },
				{"62631"}, { "Niedojadlo","Evan","73","66","83","97","88","85.8","" },
				{"87361"}, { "Perlmutter","Diadre","96","60","81","81","74","81.2","" },
				{"73984"}, { "Phaneuf","Lesley","78","85","57","68","83","79.4","" },
				{"45256"}, { "Rodrigues","Joana","58","75","58","59","92","75.2","" },
				{"42331"}, { "Rose","Nicole","83","50","96","54","93","83.8","" },
				{"21705"}, { "Roy","Jake","86","0","89","82","98","90.6","" },
				{"39234"}, { "Spaulding","Nicholas","61","0","76","92","54","67.4","" },
				{"44102"}, { "Spence","Arthur","85","84","100","91","62","80.0","" },
				{"14508"}, { "Stronach","Kur","80","95","96","78","59","77.8","" },
				{"78575"}, { "Suslovic","Vikilynn","65","54","74","61","76","70.4","" },
				{"31571"}, { "Toprowski","Crystal","93","0","77","63","58","69.8","" },
				{"99189"}, { "Vasquez","Osakr","66","60","0","63","52","58.6","" },
				{"12345"}, { "Volkov","George","100","100","100","100","100","100","" },
				{"77463"}, { "Weber","Jessica","60","56","77","81","69","71.2","" },
				{"52458"}, { "Whitten","Sarah","99","58","94","81","70","82.8","" },
				{"81984"}, { "Williams","Jenny","55","67","54","89","75","72.2","" },
				{"37915"}, { "Wright","Michelle","98","83","56","63","67","75.6","" },
				{"33580"}, { "Ziolko","John","74","64","98","98","79","85.6","" },
			};{
	

		for(String[] student : studentArray)
		{ 
			double average = 0.0;
			for(int i=2; i <= 6; i++)
			{
				average += Integer.parseInt(student[i]);


			student[7] = "" + (average/5);

			if(Double.parseDouble(student[i]) > 96 + (2/3)) { student[8] = "A+"; }
			if(Double.parseDouble(student[i]) > 93 + (1/3)) { student[8] = "A"; }
			if(Double.parseDouble(student[i]) > 90) { student[8] = "A-"; }
			if(Double.parseDouble(student[i]) > 86 + (2/3)) { student[8] = "B+"; }
			if(Double.parseDouble(student[i]) > 83 + (1/3)) { student[8] = "B"; }
			if(Double.parseDouble(student[i]) > 80) { student[8] = "B-"; }
			if(Double.parseDouble(student[i]) > 76 + (2/3)) { student[8] = "C+"; }
			if(Double.parseDouble(student[i]) > 73 + (1/3)) { student[8] = "C"; }
			if(Double.parseDouble(student[i]) > 70) { student[8] = "C-"; }
			if(Double.parseDouble(student[i]) > 66 + (2/3)) { student[8] = "D+"; }
			if(Double.parseDouble(student[i]) > 63 + (1/3)) { student[8] = "D"; }
			if(Double.parseDouble(student[i]) > 60) { student[8] = "D-"; }
			if(Double.parseDouble(student[i]) < 56 + (2/3)) { student[8] = "F"; }
			if(Double.parseDouble(student[i]) == 0) { student[8] = "F-"; }
		} 
			System.out.println("")
			System.out.println("Invalid Student ID");
			if (studentID == 0) {
				System.out.println("End of run");


			}

		}
			}
	}




And I'm out of time, unless a miracle happens in 10 minutes
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 11:27 AM

So you.. don't need to read the file? It sure as heck looks like you are hard coding all the values..
Was This Post Helpful? 0
  • +
  • -

#13 skerd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 12-December 13

Re: Urgent code help needed

Posted 16 December 2013 - 11:51 AM

View Postmodi123_1, on 16 December 2013 - 11:27 AM, said:

So you.. don't need to read the file? It sure as heck looks like you are hard coding all the values..
I do need the file but I'm awful at coding and that's the only way I know how to do it, it's completely wrong
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15697
  • View blog
  • Posts: 62,861
  • Joined: 12-June 08

Re: Urgent code help needed

Posted 16 December 2013 - 12:16 PM

Well.. that's a bummer.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1