Results 1 to 12 of 12
Thread: I need some codes
- 01-25-2011, 12:49 AM #1
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
I need some codes
Example of java codes, student records?
I need some codes in java programming for my students records management.The processes of displaying the records on the output screen, adding new records, searching from the record, editing fields of an existing record and other relevant processes should be involved. Since new records may be added when the program is executed, the program should include a way for the new set of data to be printed in a text file.
- 01-25-2011, 12:52 AM #2
Sure, no problem. You put your feet up and relax while someone else does all your work for you.
-
Hello, and welcome to the forum.
So in essence what you've done is to give us your entire assignment without asking a question and without showing any evidence of effort on your part, and I'm afraid that in this situation there's not much that we can do for you other than to direct you to a tutorial or two.
I suggest that you post your best solution that you've created so far, and ask as specific questions as possible, and we'll be much better able to help. If you really have no idea how to begin here, then please have a look here: Starting Writing a Program. It's a well-written article that can help.
Much luck
- 01-25-2011, 01:02 AM #4
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
sorry but...
i doin it in 2weeks but i cant make it..here whati have gone many errors...
/**
*Prelim Exam Problem Review
*/
package sample1;
import java.util.Scanner;
import java.io.*;
public class SampleFileProcessingA {
private Scanner reader;
private StudentA[] studs;
public SampleFileProcessingA() throws IOException{
// To read the input file
reader = new Scanner (new File("students.txt"));
}
// Read the first line of the text file as basis for the number
// of elements for the array of Students to be declared
public void run() throws Exception{
Scanner scan = new Scanner(System.in);
studs = new StudentA[Integer.parseInt(reader.nextLine())];
readFile();
byte choice=0;
do{
choice=readChoice();
switch (choice){
case 1:
System.out.println("This program deals with students record.");
System.out.println("You may choose to show on screen, \nsort and show, \ncheck if a name is included, or \nprint the records in a file.");
break;
case 2:
showStudents(sortStudentsAccordingToNames(studs));
break;
case 3:
showStudents(sortStudentsAccordingToAverage(studs) );
break;
case 4:
System.out.println("Number of failing students: " +countFailures(studs));
System.out.println("Number of Passing students: " + counts(studs, 75));
break;
case 5:
System.out.print("Enter the name to be searched.");
String searchKey = scan.nextLine();
if (isFound(studs, searchKey))
System.out.println(searchKey + " is in the database.");
else
System.out.println(searchKey + " is not in the database.");
break;
case 6:
printDataToFile(studs);
break;
case 7: addingRecords();
break;
case 8: editRecords();
break;
case 9:
System.out.println("Thank you.");
System.exit(0);
break;
} //End of switch
System.out.println("press enter to continue... ");
scan.nextLine();
} while (choice != 9);
}
// Read each of the records contained in the text file
// and store them as elements of the array called studs
public static void main(String[] args) throws Exception{
SampleFileProcessingA test = new SampleFileProcessingA();
test.run();
}
private int countFailures(StudentA[] s){
int count=0;
for (int x=0; x<s.length; x++){
if (s[x].getAverage()< 75)
count++;
}
return count;
}
private int counts(StudentA[] s, double limit){
int count=0;
for (int x=0; x<s.length; x++){
if (s[x].getAverage()>= limit)
count++;
}
return count;
}
private void showStudents(StudentA[] s){
for (int x=0; x<s.length; x++) {
System.out.println(s[x]); // toString() method is called automatically
}
return;
}
private StudentA[] copyArray(StudentA[] source){
StudentA[] copiedArray = new StudentA[source.length];
for (int x=0; x<source.length; x++){
StudentA sCopy = new StudentA(source[x].getID(), source[x].getName(),source[x].getCourse(),source[x].getAverage(), source[x].getYear(), source[x].getAddress());
copiedArray[x] = sCopy;
}
return copiedArray;
}
private StudentA[] sortStudentsAccordingToNames(StudentA[] array){
StudentA[] s = copyArray(array);
int minIndex=0;
for (int x=0; x < s.length-1; x++){
minIndex = x;
for (int y=x+1; y<s.length; y++)
if (s[minIndex].getName().compareToIgnoreCase(s[y].getName())>0)
minIndex = y;
if (minIndex != x){
StudentA temp = s[x];
s[x] = s[minIndex];
s[minIndex] = temp;
}
}// end of first for
return s;
}
private StudentA[] sortStudentsAccordingToAverage(StudentA[] array){
StudentA[] s = copyArray(array);
int minIndex=0;
for (int x=0; x < s.length-1; x++){
minIndex = x;
for (int y=x+1; y<s.length; y++)
if (s[minIndex].getAverage()<(s[y].getAverage()))
minIndex = y;
if (minIndex != x){
StudentA temp = s[x];
s[x] = s[minIndex];
s[minIndex] = temp;
}
}// end of first for
return s;
}
private void menu() throws Exception{
System.out.println("------------MENU-------------");
System.out.println("1. Show information about the program");
System.out.println("2. Show Sorted Data Based on Names");
System.out.println("3. Show Sorted Data According to Average");
System.out.println("4. Show Number of Failing Students");
System.out.println(" & Show Number of Passing Students");
System.out.println("5. Check if a student is int the database");
System.out.println("6. Print data into a file");
System.out.println("7. Adding New Records");
System.out.println("8. Editing fields of an existing record");
System.out.println("9. Exit");
}
private byte readChoice() throws Exception{
Scanner scan = new Scanner(System.in);
byte choice = 0;
while (choice < 1 || choice > 9) {
menu();
System.out.print("Enter the number corresponding to what you want to do. ");
choice = Byte.parseByte(scan.nextLine());
if (choice<1 || choice > 9){
System.out.println("Invalid choice! You must integer an integer in the range 1 to 8.");
} // end of if
} // end of while
return choice;
}
public void addingRecords(){
}
public void editRecords()throws Exception{
Scanner reader = new Scanner(System.in);
System.out.println("Enter Name of Student: ");
String nameSearch = reader.next();
int index = 0;
String id = "";
String name = "";
String course = "";
double average = 0;
int year = 0;
String address = "";
while (reader.hasNextLine()){
String[] temp = reader.nextLine().split(",");
// Store the values to the following variables
id = temp[0];
name = temp[1];
course = temp[2];
average = Double.parseDouble(temp[4]);
year = Integer.parseInt(temp[3]);
address = temp[5];
// Use the values in instantiating Student object
studs[index++] = new StudentA(id, name, course, average, year, address);
}
reader.close();
for (int x=0; x<studs.length; x++){
if (studs[x].getName().equalsIgnoreCase(nameSearch))
System.out.println("Need to Edit? ");
System.out.println("1 - ID No.");
System.out.println("2 - Name");
System.out.println("3 - Course");
System.out.println("4 - Year");
System.out.println("5 - Grades");
System.out.println("6 - Address");
System.out.println("7 - Back");
int choice2 = reader.nextInt();
switch(choice2){
case 1:
System.out.println("Enter new Name: ");
String newName = reader.next();
studs[x] = new StudentA(id, newName, course, average, year, address);
PrintWriter outFile = new PrintWriter(new FileWriter("outputA.txt"));
for (int i = 0; i < studs.length; i++){
outFile.println(studs[i]);
}
outFile.close();
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
}
}
}
public void printDataToFile(StudentA[] s) throws IOException{
// To output records in an output file: output.txt
PrintWriter outFile = new PrintWriter(new FileWriter("outputA.txt"));
for (int i = 0; i < s.length; i++){
outFile.println(s[i]);
}
outFile.close();
}
public void readFile(){
int index = 0;
while (reader.hasNextLine()){
String[] temp = reader.nextLine().split(",");
// Store the values to the following variables
String id = temp[0];
String name = temp[1];
String course = temp[2];
double average = Double.parseDouble(temp[4]);
int year = Integer.parseInt(temp[3]);
String address = temp[5];
// Use the values in instantiating Student object
studs[index++] = new StudentA(id, name, course, average, year, address);
}
reader.close();
}
private boolean isFound(StudentA[] s, String nameToSearch){
boolean found = false;
for (int x=0; x<s.length && !found; x++){
if (s[x].getName().equalsIgnoreCase(nameToSearch))
found = true;
}
return found;
}
}
in other file...
/**
Prelim Exam Problem Review
*/
package sample1;
public class StudentA {
private String id;
private String name;
private String course;
private double average;
private int year;
private String address;
// Constructor
public StudentA(String id, String name, String course, double average, int year,String address) {
this.id = id;
this.name = name;
this.course = course;
this.average = average;
this.year = year;
this.address = address;
}
// Getter/accessor methods
public String getID(){
return id;
}
public String getName(){
return name;
}
public String getCourse(){
return course;
}
public double getAverage(){
return average;
}
public int getYear(){
return year;
}
public String getAddress(){
return address;
}
// Setter/mutator methods are intentionally not included but it would be
// be good to include them as well...
public String toString(){
return (id + "," + name + "," + course + ","+ year + "," + average +", " + address);
}
}
- 01-25-2011, 01:06 AM #5
Many errors huh? I suppose we have to guess what they are.
- 01-25-2011, 01:07 AM #6
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
i need it today for my idividualproject..i hope theycan help me...
im a beginner in java.. 1st year college.. and i cant understand some lecture about some codes like that ....sorry
- 01-25-2011, 01:07 AM #7
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
thanks anyway......
- 01-25-2011, 01:32 AM #8
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
hey. is there any one willing to help me?
- 01-25-2011, 01:35 AM #9
As soon as you ask a question someone might help you.
- 01-25-2011, 02:48 AM #10
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Suggested reading: How To Ask Questions The Smart Way
- 01-25-2011, 03:17 AM #11
Member
- Join Date
- Jan 2011
- Location
- Baguio City, Philippines
- Posts
- 21
- Rep Power
- 0
hey... sorry but... im not good at english language....im pure tagalog..from philippines...
i need those codes as soon as posible.. thanks to all...
-
This thread is going no-where, just a begging for the codes type thread, and so I will close it.
Similar Threads
-
What do the following codes do?
By javaguy2 in forum New To JavaReplies: 2Last Post: 01-23-2011, 10:23 PM -
How do I integrate these two codes?
By Isong in forum AWT / SwingReplies: 3Last Post: 11-03-2010, 02:44 AM -
two short codes
By Libertyman in forum New To JavaReplies: 7Last Post: 06-21-2010, 03:22 PM -
Assistant on my codes. SOS!!
By sya1912 in forum Java AppletsReplies: 16Last Post: 09-01-2008, 02:23 PM -
What's wrong with my codes?
By ayoood in forum New To JavaReplies: 16Last Post: 09-01-2008, 03:57 AM


LinkBack URL
About LinkBacks

Bookmarks