[Show all top banners]

devilwithin999
Replies to this thread:

More by devilwithin999
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 HELP HELP
[VIEWED 1247 TIMES]
SAVE! for ease of future access.
Posted on 04-01-08 7:19 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Hey guys I am having a problem with my java program which consists of a huge score. Please solve that program for me. I would be very thankful. Here is the question :

Q)For research purposes and to assist students, the admission office of your local university wants to know how well female and male students perform in certain courses. You receive a file that contains female and male students GPAs  for certain courses. The letter code f is used for female students;m is used for male students . Every file entry consists of a letter code followed by a GPA. Each line has one entry. The number  of entries in the file is unknown. Write a program  that computes and output the average GPA for female and male students. Format your results to two decimal places.

 

Thank you in advance...

Jai Nepal


 
Posted on 04-01-08 7:29 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I am working on it. Will post you the solution in nnext 1 hour.
 
Posted on 04-01-08 8:06 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

dude rn't u supposed to solve this on ur own, try solving on ur own from next time, here is the code, just create a file with following info in it

m   20

f     30

f    20

........ something like that and save it in c:\file.txt or u can rename or change the path too. 

 

import java.io.*;

public class jayNepal

{

public static void main(String[] args)

{

//..initialize

String sex="";

//..total marks form male

int mMarks=0;

//..total number of male student

int mCount=0;

//.. total marks of female

int fMarks=0;

//.. total number of female

int fCount=0;

int marks;

try {

BufferedReader in = new BufferedReader(new FileReader("c:\\file.txt"));

String str;

while ((str = in.readLine()) != null)

{

int spacePosition=str.indexOf(" ");

sex=str.substring(0, spacePosition);

marks=Integer.parseInt(str.substring(spacePosition+1));

System.out.println("sex"+ sex + " and marks " + marks);

if(sex.equals("m") || (sex.equals("M")))

{

mMarks=mMarks+marks;

mCount++;

}

else

{

fMarks=fMarks+marks;

fCount++;

}

}

System.out.println("Average male mark is " + mMarks/mCount +" Average Female Mark is " + fMarks/fCount);

in.close();

}

catch (IOException e)

{

}

}

}


 
Posted on 04-01-08 8:10 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I tried it too many times but cannot find out the solution.

As well as, I dont know th way to import the text file so balbahadur plz post the complete program of it.

Plz dont miss any steps coz I am a newbie in programs.

Thanks for your help.


 
Posted on 04-01-08 8:13 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

oh , didnt seee the GPA (thought it was just marks) part so u might have to change all the marks from int to double, and also dont give space at the start of the file.
 
Posted on 04-01-08 8:18 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

hey did u try the program i sent u ? do u even know how to run a java code? let me know if u need instruction on running the above code and 666 is the devil's code.
 
Posted on 04-01-08 8:31 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Plz correct it yourself and give me a final program as well as tell me the procedures to run it in  a notebook.

Sun's computer sucks!!!


 
Posted on 04-01-08 8:49 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

ke ho mitra!! hope u r not  a computer student, ok this is what u do, and this is java so deosnt matter wheather its notebook, or desktop or linux, or windows. So, hope you have atleast run  "Hello world " program in your notebook ever.

1. Create a file with the info ur teacher asked u to enter. Save it as file.txt in c: (Hope I dont have to teach you this)

m   3.5

f     2.5

f    4.0

2. Create one file and copy paste the below code in that  and save it as jayNepal.java

import java.io.*;

public class jayNepal

{

public static void main(String[] args)

{

//..initialize

String sex="";

//..total marks of male

double mMarks=0.0;

//..total number of male student

int mCount=0;

//.. total marks of female

double fMarks=0.0;

//.. total number of female

int fCount=0;

double marks;

try {

BufferedReader in = new BufferedReader(new FileReader("c:\\file.txt"));

String str;

while ((str = in.readLine()) != null)

{

int spacePosition=str.indexOf(" ");

sex=str.substring(0, spacePosition);

marks=Double.parseDouble(str.substring(spacePosition+1));

System.out.println("sex "+ sex + " and marks " + marks);

if(sex.equals("m") || (sex.equals("M")))

{

mMarks=mMarks+marks;

mCount++;

}

else

{

fMarks=fMarks+marks;

fCount++;

}

}

System.out.println("Average male GPA is " + mMarks/mCount +" Average Female GPA is " + fMarks/fCount);

in.close();

}

catch (IOException e)

{

}

}

}

3. compile this code

javac jayNepal.java

4. run jayNepal using

java jayNepal


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 7 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
nrn citizenship
ढ्याउ गर्दा दसैँको खसी गनाउच
मन भित्र को पत्रै पत्र!
emergency donation needed
जाडो, बा र म……
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters