How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask R.R. Jha Your Own Question

R.R. Jha
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5466
Experience:  B.Tech
20870358
Type Your Homework Question Here...
R.R. Jha is online now
A new question is answered every 9 seconds

I cannot get my program to compile in netbeans. i dont understand

Resolved Question:

I cannot get my program to compile in netbeans. i don't understand the error. all the code is correct.
Submitted: 1 year ago.
Category: Homework
Expert:  Raj replied 1 year ago.
Hi There,

I will be helping you with the solution....
Can you please provide the code?

Thank you
Customer: replied 1 year ago.

Hi, I really need this urgently and you are doing the class diagram for me. Will you be able to get both done by noon?

Expert:  Raj replied 1 year ago.
Call Diagram is already ready for you...
I have posted the message there that the solution is ready....

So I will provide the solution there and you in the mean while post the code here....
Customer: replied 1 year ago.

Yeah I need a better solution. Here is the code but please let me know if you cannot do both ;


 


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package P28_gradesdatabase;

/** a program to illustrate the use of the Random Access File class
*
* @author youngj
*/
import java.io.*;
public class P28_gradesdatabase {

/**
* @param args the command line arguments
*/

static final String FILENAME = "D:\\Documents\\NetBeansProjects\\grades.dat";
private int numRecords = 0;
private RandomAccessFile raFile;
private static BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
static final int QUIT = 5;
static final double MAX_GPA = 4.0;

public static void main(String[] args) throws IOException {

new P28_gradesdatabase();
}

public P28_gradesdatabase() throws IOException
{
if(fileExists())
{
System.out.println ("Data file located and loaded with " + numRecords + "existing records\n");
}
else
{
System.out.println ("No data file found, starting new collection\n");
}

int choice;
do
{
choice = runMenu();
}
while (choice != QUIT);
}

private boolean fileExists()
{
//if the file already exists, open for random access and initialism current number of entries
//if the files does not exist, print error message
try
{
raFile = new RandomAccessFile(FILENAME, "rw");
numRecords = (int)raFile.length() / gradesfile.length();
return true;
}
catch(IOException err)
{
System.out.println ("Error trying to open file " + err.getMessage());
}
return false;
}

private int runMenu() throws IOException
{
System.out.println ("Please choose from the following options:");
System.out.println ("1. Add a new students to file");
System.out.println ("2. Output all students on file");
System.out.println ("3. Search the students on file by first name");
System.out.println ("4. Sort the students on file by first name");
System.out.println ("5. Quit");

int choice = 0;
while(choice < 1 || choice > QUIT)
{
System.out.println ("Please input a number between 1 and " + QUIT + ": ");
choice = validatedIntegerInput();
}

switch(choice)
{
case 1: add();
break;
case 2: display();
break;
case 3: search();
break;
case 4: selectionSort();
break;
default: quit();
}

return choice;
}

private void add() //Method to add a record to the file
{
try
{
gradesfile student = getStudentDetails();
long pos = numRecords * gradesfile.length();
student.writeRecord(raFile, pos);
numRecords++;
}
catch(IOException e)
{
System.out.println ("Error adding record " + e.getMessage());
}
}

private void display()
{
try
{
long pos = 0;
for(int i = 0; i < numRecords; i++)
{
System.out.println (gradesfile.readRecord(raFile, pos));
pos = pos + gradesfile.length();
}
}
catch(IOException e)
{
System.out.println ("Error displaying record " + e.getMessage());
}
}

private gradesfile getStudentDetails() throws IOException
{
//get name details
System.out.println ("Enter the student's name: ");
String name = stdin.readLine();

//get year details
int year = 0;
while (year < 9 || year > 12)
{
System.out.println ("Enter the studen'ts year from 9-12: ");
year = validatedIntegerInput();
}

//get gpa details
double gpa = -1;
while (gpa < 0 || gpa > MAX_GPA)
{
System.out.println ("Enter the student's GPA from 0-" + MAX_GPA + ":");
gpa = validatedDoubleInput();
}
return new gradesfile(name, gpa, year);
}

private void quit()
{
try
{
raFile.close();
}
catch (IOException e)
{
System.out.println ("Error closing the file: " + e.getMessage());
}
finally //finally allows you to specifically what to do after either try or catch
{
System.out.println ("Thank you for using the grades database.");
}
}

private void search() throws IOException
{
gradesfile student;
boolean found = false;
String name;
int i = 0;

System.out.println ("Input the first name you want to search");
name = stdin.readLine();
StringBuilder sb = new StringBuilder(name);
sb.setLength(gradesfile.NAME_BYTES);
name = sb.toString();

while (i < numRecords && !found) //compare the current record in the file to the user input name
{
student = gradesfile.readRecord(raFile, gradesfile.length() * i); //goes in the file and returns the full record
if (name.equals(student.getName()))
{
found = true;
}
else
{
i++;
}
}
if (!found)
{
System.out.println ("not found in file");
}
else
{
searchMenu(gradesfile.length() * i);
}
}

private void searchMenu(int pos) throws IOException
{
System.out.println ("Please choose from the following options:");
System.out.println ("1. Delete selected file");
System.out.println ("2. Edit selected file");
System.out.println ("3. Return to main menu");

int choice = 0;
while(choice < 1 || choice > 3)
{
System.out.println ("Please input a number between 1 and 3");
choice = validatedIntegerInput();
}

switch(choice)
{
case 1: delete(pos);
break;
case 2: edit(pos);
break;
default:
}
}

private void delete(int pos)
{
try
{
gradesfile student;

while(pos + gradesfile.length() < raFile.length())
{
//save the record into student and then rewrite it to the pos.
student = gradesfile.readRecord(raFile, pos + gradesfile.length());
student.writeRecord(raFile, pos);

//increment
pos = pos + gradesfile.length();
}
raFile.setLength(raFile.length() - gradesfile.length());
numRecords--;
}
catch(IOException e)
{
System.out.println ("Error deleting record " + e.getMessage());
}
}

private void edit(long pos)
{
try
{
gradesfile student = getStudentDetails(); //User inputs (info) are saved in student
student.writeRecord(raFile, pos); //writes on top of the position
}
catch(IOException e)
{
System.out.println ("Error editing record " + e.getMessage());
}
}

private void selectionSort()
{
int i, j, least, temp; //first = i, current = j
gradesfile student;

for(i = 0; i < numRecords; i++)
{
least = i;
for(j = i+1; j < numRecords; j++)
{
if(j < j+1)
{
least = i;
}
}
temp = least;
least = i;
i = temp;
}
}


public static int validatedIntegerInput() throws IOException
{
// local variables
int result=0;
boolean ok = false;

while (!ok)
{
ok = true;
try
{
result = Integer.parseInt(stdin.readLine());
}
catch (NumberFormatException error)
{
System.out.println("Please type a number");
ok = false;
}
}

return result;
}

public static double validatedDoubleInput() throws IOException //integer validation method
{
// local variables
double result = 0;
boolean ok = false;

while (!ok)
{
ok = true;
try
{
result = Double.parseDouble(stdin.readLine());
}
catch (NumberFormatException error)
{
System.out.println("Please type a number");
ok = false;
}
}
return result;
}
}


 


 


2nd file:



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package P28_gradesdatabase;

/**
*
* @author youngj
*/
public class Grades {

protected String name;
private int year;
private double gpa;

public Grades(String n, double g, int y)
{
name = n;
gpa = g;
year = y;
}

public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
public int getYear()
{
return year;
}
public void setYear(int y)
{
year = y;
}
public double getGPA()
{
return gpa;
}
public void setGPA(double g)
{
gpa = g;
}

public String toString()
{
return "Student: " + name + "; Year: " + year + "; GPA: " + gpa;
}
}



3rd file



/*
* GradesFile.java
* A class that sets up a record of a student's grades.
* Can read and write records from an open RandomAccessFile
* An example of inheritance (GradeFile EXTENDS the Grades class)
*/
package P28_gradesdatabase;
import java.io.*;

/**
*
* @author youngj
*/
public class GradesFile extends Grades{
//Declares data, also called instance variables

//First define size of each field in bytes
static final int NAME_BYTES = 18;
static final int YEAR_BYTES = 4;
static final int GPA_BYTES = 8;

//How calculate length of the record - used to seek to correct position in the data file
static final int RECORD_BYTES = NAME_BYTES + YEAR_BYTES + GPA_BYTES;

public GradesFile(String n, double g, int y)
{
super(n,g,y);
super.name = fixLength(name, NAME_BYTES); //method to fix the length of the String with the
}
//in order for a fixed-length record to actually be fixed in length.
//all strings must include a buffer to fill out any extra space.

//This method returns the fixed length at one record
//Used in the driver class to calculate the point at which each record starts and ends
private String fixLength(String n, int size)
{
StringBuilder sb = new StringBuilder(n);
sb.setLength(size);
return sb.toString();
}

public void writeRecord(RandomAccessFile raFile, long pos) throws IOException
{
raFile.seek(pos); //moves to the specified position

raFile.writeBytes(this.getName()); //writes the name to the position
raFile.writeInt(this.getYear()); //writes the year
raFile.writeDouble(this.getGPA()); //writes the GPA
}


public static GradesFile readRecord(RandomAccessFile raFile, long pos) throws IOException
{
raFile.seek(pos);

byte[] theName = new byte[NAME_BYTES];
raFile.readFully(theName);
String n = new String(theName);

int y = raFile.readInt();
double g = raFile.readDouble();

return new GradesFile(n, g, y);
}


public static int length()
{
return RECORD_BYTES;
}

//Now that the record has been set up, we want to add it to the file.
//Parameters: the file to write to and the position where to write it
//Return: void, since it is just saving to the file (could return boolean - T/F, was the record




}

Expert:  Raj replied 1 year ago.
I think I will release the code for others to help.... any if no one replies and I solve your Other Question before time than I will have a look into this one....

Expert:  R.R. Jha replied 1 year ago.
Hi,

I'd be glad to help. Please zip entire project folder with all required input files, upload the zip file at wikisend.com or mediafire.com and post download link here.


Thanks
Customer: replied 1 year ago.

Thosethe three are all the files i have now. No longer have the build file so it needs to be recompiled in neatbeans.


 


http://wikisend.com/download/612732/grades.zip


 


Thanks

Expert:  R.R. Jha replied 1 year ago.
Ok, reviewing them.
Expert:  R.R. Jha replied 1 year ago.
Here is the netbeans project. Fixed all compiling errors.

https://www.box.com/s/a2enu7t8egpe1urixd3k


Please leave the rating.

Let me know if you need help with any other problems or projects.

Thanks
Customer: replied 1 year ago.

Hi it is not compiling in my netbeans program. I get the following error:


 


Expert:  R.R. Jha replied 1 year ago.
Image isn't loading in full size. Please send the image through wikisend
Customer: replied 1 year ago.

http://wikisend.com/download/618390/Capture.PNG


 

Expert:  R.R. Jha replied 1 year ago.
Which operating system are you working in? and how are you compiling the project?
Customer: replied 1 year ago.

windows 7, netbeans 7.2. I am opening the project file then going to build

Expert:  R.R. Jha replied 1 year ago.
Its seems netbeans is unable to locate java v1.7. Which version of java are you using?
Expert:  R.R. Jha replied 1 year ago.
Ok, open your original netbeans project and replace your previous codes with these ones

https://www.box.com/s/9jdaj5r04y1b1goow17d
Customer: replied 1 year ago.

Still not working. I get the same error

Expert:  R.R. Jha replied 1 year ago.
Are your other projects compiling correctly? The problem seems with the java version netbeans is looking for. You may check that by compiling code from command line.
Just extract the three code files I last sent and browse to the directory where three java codes are located.
Open codes files with notepad, comment the first line which mentions the package in each of three codes.
Then 'Shift + Right Click' in the code directory and 'open command window here'. Then type in following commands.

javac P28_gradesdatabase.java
java P28_gradesdatabase


Check if it compiles properly using command line.

Thanks
Customer: replied 1 year ago.

Running command line in the directory where the files are stored results i a javac is not recognized as an internal or external command, operable program or batch file - i can compile other programs in netbeans

Expert:  R.R. Jha replied 1 year ago.
THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5466
Experience: B.Tech
R.R. Jha and 3 other Homework Specialists are ready to help you

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience