I am in a Java Programming class and our instructor has just assigned us our 1st project. The project would not be a problem if I understood the Java Programming Language, from the beginning of my Computer Science Schooling I have yet to understand this code and now that I am 3(three) classes away from graduation it is really important to me to pass these few classes. The projects instructions are long and are pasted below I could not give the actual address, because it would make you log in to view it. I greatly appreciate any help anyone can give me Thank You!!

A local college wants to verify that the candidates for graduation have met the minimum requirements to graduate (120
credit hours completed with a GPA of at least 2.0). Additionally, it wants to identify students who graduate with one of
three levels of honor: cum laude, magna cum laude, and summa cum laude.
The graduation candidates’ information is stored in a file named candidates.txt. Each student’s record is split among
two lines of the file, with the first line containing the student’s full name and the second containing the student’s number of
hours completed and cumulative grade point average. The following is an example:
Student, Ima Bea
130 3.82
Your program should generate four output files listing the students who meet the following criteria:
File Name Contents
cumlaude.txt Graduating students with a GPA of at least 3.5 but less than 3.7
magna.txt Graduating students with a GPA of at least 3.7 but less than 3.9
summa.txt Graduating students with a GPA of at least 3.9
noGrad.txt Students with less than 120 hours completed or a GPA less than 2.0
In the first three files, include each qualifying student’s name and GPA (separated by a space) on a single line. In the last
file, include the student’s name, hours completed, and GPA (separated by spaces) on a single line. Make sure that each
GPA shows two digits after the decimal point. If a student is graduating but does not meet the criteria for one of the
honors designations, the student’s information should not be written to a file. Students who do not meet the required
number of credit hours should not be added to any of the honors designation files regardless of GPA.
The number of candidates in the original file is unknown, so you'll need to read these records until you reach the end of
the file. Remember that you can only open one file at a time with each output file variable, so you'll need at least four
output file variables for this project. Assume that you are permitted to overwrite any file if it already exists (do not append
to the file). Your program does not need to generate any output to the screen, but it would be wise to let the user know
whether the program was successful in processing the input file and generating the output files.
BONUS (5 points): The number of credit hours for each student should not be negative. If the program encounters a
student with a negative number of credit hours, write the student’s name, hours completed, and GPA (separated by
spaces) on a single line in the file hoursError.txt rather than any of the four aforementioned files.
BONUS (5 points): The grade point average of each student should not be negative, nor should it exceed 4.0 (assume
the college is not on the plus / minus system). If the program encounters a student with an erroneous grade point
average, write the student’s name, hours completed, and GPA (separated by spaces) on a single line in the file
gpaError.txt rather than any of the five aforementioned files (but if the student’s number of credit hours was already
indicated as an error in the file hoursError.txt, don’t write the student’s information to this file as well).
BONUS (10 points): Calculate the total number of students written to each file, and write this total on a new line at the
end of the file.
No bonus credit will be given unless the standard requirements of the assignment are met! Make sure that you
have the basic functionality working regardless of whether or not you are able to complete the bonus portion
successfully!
Your code should include comments at the top listing your name, the course, the project number, and a brief description of
the program. It should also include at least five inline comments in your code explaining what your code is doing at that
given point.
No late work will be accepted! If you need assistance with your code, e-mail your instructor at least one day in
advance. You may discuss general details of the assignment with your classmates, but do not look at or borrow
another student’s code!

Recommended Answers

All 18 Replies

Hahaha You must be kidding , no body will read this much for you... Make a small demo so we start helping you. Atleast divide them in small task.

Don't put everything in the main method and don't write everything at once.
First create a Student class with attributes: name, hours, grade.

Then have a single method:
In that method read the file with the students and have the method return a list with the data. The List will have Student objects

First write that method test it and then you can call it, loop the list and have if statements in order to determine which student to write to which new file.

if you only have three more classes to go, you've propably had a lot of classes behind you. what DO you understand? and where are you stuck. don't expect us to start coding for you, because that's not what this forum is ment for.

Ha yeah guess I expected a little much, but I have done a little coding to go along with it I hope its right so far I dont think its near as much as I need to actually finish it, but "javaAddict" helped me the most by giving guidelines to start with. I do not mind doing some work. I'm my own worst critic and I absolutly hate that this coding stuff is defeating me. This is what I got so far.

import java.util.Scanner;
import java.text.decimalFormat;

/** Jonathan Pleasant
	7/19/2011
	CIS255
	Project#1
	Project will show students show qualify for graduation.
*/

public class JPleasant_Project#1
{
	public static void main(String[] args)
	{
		String name;
		double hours;
		double grade;
		if (hours < 120 || grade < 2.0)
			System.out.println("I'm Sorry you will not graduate.");

		else (hours >= 120 && grade >= 2.0)
			System.out.println("Congratulations you will graduate.");

		else (hours >= 120 && grade >= 3.5 && grade <= 3.7)
			System.out.println("Congratulations you will graduate Cum laude.");

		else (hours >= 120 && grade >= 3.7 && grade <= 3.9)
			System.out.println("Congratulations you will graduate Magna Cum laude.");

		else (hours >= 120 && grade >= 3.9)
			System.out.println("Congratulations you will graduate Summa Cum laude.");


		DecimalFormat GPA = new DecimalFormat("#0.00");

You don't give values to the variables hours, name, grade. Also that is not how if statements work. Review your notes.

if () {

} else if () {

} else if () {

} else {

}

Also you will need to read first the file with the candidates and have a list with students, which you will loop.

You will also need to be more specific with your checks.
For example:
You check if the student will graduate:
(hours>=120 && grade>=2.0)
And the you check if the student is Cum laude
(hours >= 120 && grade >= 3.5 && grade <= 3.7)

But with the way you wrote it:

if (hours>=120 && grade>=2.0) {

} else if (hours >= 120 && grade >= 3.5 && grade <= 3.7) {

}

The code will always be going in the first if and it will never enter the second.
And you cannot use different ifs because then you will save the same data to the same file.
You must put the more specific ifs at the top.

Like this

if (hours >= 120 && grade >= 2.0)
			System.out.println("Congratulations you will graduate.");

		else if (hours >= 120 && grade >= 3.5 && grade <= 3.7)
			System.out.println("Congratulations you will graduate Cum laude.");

		else if (hours >= 120 && grade >= 3.7 && grade <= 3.9)
			System.out.println("Congratulations you will graduate Magna Cum laude.");

		else if (hours >= 120 && grade >= 3.9)
			System.out.println("Congratulations you will graduate Summa Cum laude.");

		else (hours < 120 || grade < 2.0)
			System.out.println("I'm Sorry you will not graduate.");

yes, but you still need to assign values to your variables, otherwise they will all have the default values (0 for double, null for String)

also remember, if you want to put several lines of code for each if or else block, you'll have to put brackets ( { } ) around it.

Okay is there any steps you can give me to work on I know I have to create the candidates.txt, cumlaude.txt, magna.txt, summa.txt, noGrad.txt, hoursError.txt and gpaError.txt. Do I put the if statments above by name into these cumlaude.txt and what more do I need to assign to String name; double hours; double grade;... We get all this from the user so its unknown correct? I just need help. Steps, procedures, anything..

Okay is there any steps you can give me to work on I know I have to create the candidates.txt, cumlaude.txt, magna.txt, summa.txt, noGrad.txt, hoursError.txt and gpaError.txt. Do I put the if statments above by name into these cumlaude.txt and what more do I need to assign to String name; double hours; double grade;... We get all this from the user so its unknown correct? I just need help. Steps, procedures, anything..

You have already been given the first steps to start at my first post.

Would it easier to use the switch method?

Switches operate on integers and enums. How do you see that relating to your requirement?

First create a Student class with attributes: name, hours, grade....

public class JPleasant_Project#1
{
public static void main(String[] args)
{
    String name;
    double hours;
    double grade;

candidates.txt has the students name, hours, and gpa
students studentsObject = new students(); this is how the object is suppose to look or am I suppose to put candidtates candidatesObject = new candidates(); and does system.out.println read text but how do I get it to call the names, hours, and GPA?

For reading and writing in classes, you should use BufferedReader and BufferReader

This would be an example of a writer

try {
    	FileWriter fstream = new FileWriter(filename,true);
	BufferedWriter output = new BufferedWriter(fstream);
	output.write(text);
	output.close();
} catch (IOException e) {

We have not even went over BufferedWriter(fstream) yet so I don't know if I should use that. We have went over printwriter outputFile = new PrintWriter("filename");... Do I open a new textpad document and call it candidates.java or .txt and start it printwriter outputFile = new PrintWriter("candidates"); to be able to show it. Because I saved it as a txt file in a new textpad document?

and FileWriter fwriter = new FileWriter("FileName");

PrintWriter is a very impractical way of writing files, you can just copy and paste the code I have provided and import file.io, replace filename with your file name, and output.write(); with your text and you do open a new textpad and call it candidateName or whatever. Hopes this helps!

A Scanner object will not be needed because we are not getting information from the user we are just reading and displaying information correct? What do I put in cumlaude.txt, magna.txt, summa.txt, and noGrad and do I use the set and get method?

Firstly the requirements say that you shouldn't append the results to the new files so don't use the true option:
FileWriter fstream = new FileWriter(filename,true)

Second if you have been taught to use the PrintWriter then use that.

You can use the BufferedReader to read from a file or you can also use the Scanner class. if you pass as argument to its contructor a File object.

As far as your Studnet class: JPleasant_Project#1
You have been told to create a Student class not a JPleasant_Project#1 class.
Also the name,hours,grade need to be the attributes of the class, not local methods inside of a main. Don't put a main inside the Student class. Just the attributes with get/set methods. Surely you have been taught how to create custom classes.

You will use code to write in the new files. That code would be put in the if-else statements and according to each case you will write to the file described by your requirements.
Create different writers outside the loop with the students and use their instances to write to each file.

The code provided by jeffery12109 was just an example. you need to make the right modifications or whatever way you have been told to use

------------------
If your teacher hasn't told you how to create custom classes then things are to become more complicated, because you need in the same main, do the reading and while reading writing to right files as well. The problem is that you will have many operation at the same location of the code and would be difficult to test if something goes wrong. If that is the case, first write the code that reads the candiate.txt file and print its contents and when you are done, just remove the printing part and write the part for writing into the new files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.