Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Please provide coding for following problem

Have Programming Question? Ask it here!
 
 
 


Bryan Noll
Please provide coding for following problem
1 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


Please provide the coding for the following problem:

You will write a java program that will read data from a file. The data in the file will be: John Doe 75 Joe Blow 65 Mary Smith 80 John Green 82 Jill White 97

The program will rad the data into three separate arrays: Firstname array, LastName array, and a score array. The output will be the initials followed by their score in sorted order from top score to lowest score:

So the output will be: JW 97 JG 82 MS 80 JD 75 JB 65

I have the data file already written up, just unsure of as to how I am to write the program to run it.

Appreciate any assistance.


Advertisement
View Answers

April 21, 2011 at 11:29 AM


import java.io.*;
import java.util.*;
class ShowData implements Comparable {
    String fname;
    String lname;
    int score;

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getFname() {
        return fname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getLname() {
        return lname;
    }


    public void setScore(int score) {
        this.score = score;
    }

    public int getScore() {
        return score;
    }


    public int compareTo(Object ob) throws ClassCastException {
        if (!(ob instanceof ShowData))
            throw new ClassCastException("Error");
        int marks = ((ShowData) ob).getScore();
        return this.score - marks;
    }
}


class FileData{
    public static void main(String[] args){
        int j = 0;
        ShowData data[] = new ShowData[5];
        try {
            FileInputStream fstream = new FileInputStream("C:/file.txt");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            ArrayList list = new ArrayList();
            while ((strLine = br.readLine()) != null) {
                list.add(strLine);
            }
            Iterator itr;
            for (itr = list.iterator(); itr.hasNext();) {
                String str = itr.next().toString();
                String[] splitSt = str.split(" ");
                String  firstname = "", lastname = "", score = "";
                for (int i = 0; i < splitSt.length; i++) {
                    firstname = splitSt[0];
                    lastname = splitSt[1];
                    score = splitSt[2];
                }
                data[j] = new ShowData();
                data[j].setFname(firstname);
                data[j].setLname(lastname);
                data[j].setScore(Integer.parseInt(score));
                j++;
            }
            Arrays.sort(data,Collections.reverseOrder());
            String strVal = "";
            for (int i = 0; i < 5; i++) {
                ShowData show = data[i];
                String fname = show.getFname();
                int score = show.getScore();
                String lname = show.getLname();
                String fn=fname.substring(0,1).toUpperCase();
                String ln=lname.substring(0,1).toUpperCase();
                String fl=fn+ln;
                System.out.println(fl + "\t " + score);
            }
          } catch (Exception e) {
        }
    }
    }


Related Tutorials/Questions & Answers:
Please provide coding for following problem
Please provide coding for following problem  Please provide the coding for the following problem: You will write a java program that will read data from a file. The data in the file will be: John Doe 75 Joe Blow 65 Mary Smith 80
Please provide the coding for this problem
Please provide the coding for this problem  Please provide the coding for the following problem. Write a "hangman" game that randomly generates a word and prompts the user to guess one letter at a time. Each letter in the word
Advertisements
problem in writing coding. Please help me.
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments. Actually I'm doing a Voting System. I need to know how to write JSP coding
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each student‚??s name and score, and finally displays the name of the students
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches... that invokes these methods to display the following table: Inches Centimeters
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters
please provide the code
please provide the code   Develop a multi-client chat application
Please provide the code
Please provide the code   Write a program to recursively download the web pages available in the given site URL
Please provide the code
Please provide the code   Program to find depth of the file in a directory and list all files those are having more number of parent directories
Please provide the code
Please provide the code   Create a file system: We just have one file on the hard disk. But we can create directories, sub-directories and files in that file only
Provide the code please
Provide the code please   Program to calculate the sum of two big numbers (the numbers can contain more than 1000 digits). Don't use any library classes or methods (BigInteger etc
problem in coding
problem in coding  i have a following code which display the contents of the text file but not other program like java or any c program is there any handler to open the program files other than Filereader. FileReader fr = new
jsp coding please.
jsp coding please.  hi sir, my name is logeswaran. I have a problem... list. please show me how to do it? thank you. By the way, I'm using access database and coding JSP.   Follow these steps: 1)Go to the start->
please provide code - Java Beginners
please provide code  provide code to snake game in J2SE
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
problem i coding
problem i coding  i have a problem in coding a combobox containing a number of *.java program on click one of them that program should compile and run and display the result in other window
Problem about coding in ajvascript
Problem about coding in ajvascript  I created a three radio buttons in the following way How many iphone styles are present in the image... the option selected is true or false. Can please help me in getting a code using
Please provide option for full materials download...
Please provide option for full materials download...   Please provide option for full materials download ... i dont have internet connection in my home. plz provide offline tutorial option
Begineer in coding please help me
Begineer in coding please help me  I have Person class{ int pid; String Pname; //and have a Address filed of type Address not String!!! Address... address to a person object.. please help me
How to build .XML file, please provide an example.
How to build .XML file, please provide an example.  Hello, I want to know how to build .XML file. If you can provide an example, that would be great... Thanks
coding problem - JSP-Servlet
coding problem  Dear sir i m very new to JSP .I am using two conbobox .if any option is selected in first combobox then only its data from...' keyword in the combobox to call the function in javascript. the following code
coding problem - Java Beginners
coding problem  i used netbeans software to develop frame.now i need to add values to JList from ArrayList object  Hi Friend, Try the following code: import java.util.*; import javax.swing.*; public class
coding problem - JSP-Servlet
coding problem  dear sir i m very new to JSP sir i m getting problem in dynamically changing the option of combobox from database(ms acess) .and after that option being selected for that the record from the databse should
Please..please provide me a good Hibernate in Spring example
Please..please provide me a good Hibernate in Spring example  Hi, Can anyone please provide me a Hibernate in Spring example with simple explanation... hope the following links would be very useful to you: Hibernate Spring Example
coding problem - Java Beginners
coding problem  hi friend! Im new to jasper reports.how can i start that coding inorder to generate reports.can u send some sample programs for reporting?im badly need some clearly mentioned example because im new to jasper
coding problem - Java Beginners
coding problem  hi! i declared date as date datatype in oracle now i need to retrieve date from database to my java code.how can i please help me urgent   Hi Friend, We are providing you a code that will retrieve
coding problem - JSP-Servlet
coding problem  dear sir will u plz tell me how can we delete a record from the database(MSaccess) when option in the combobox is selected(jsp)  If u want to delete the record from database, by seleting
coding problem - Java Beginners
coding problem  i had a big doubt. public ArrayList readExpenseType() throws ClassNotFoundException, SQLException,Exception { DBConnection dbc = new DBConnection(); Connection con = dbc.getConnection(); ArrayList
Problem in coding - Java Beginners
Problem in coding  How many times do you have to roll a pair of dice before they come up snake eyes? You could do the experiment by rolling the dice... friend, Code to help in solving the problem. public class Stimulates
Please provide the java code for the given program.
Please provide the java code for the given program.   We need an application for managing an educational institute. That application should provide the details of Students Courses Faculty Fee details etc..,   
Please provide jquery inline form validation for the code
Please provide jquery inline form validation for the code   <...; </table> </form></body></html>   Please visit the following link: http://www.roseindia.net/tutorial/jquery
Please Provide jquery inline form validation
Please Provide jquery inline form validation  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content
please help me to this problem..
please help me to this problem..  i wrote a program like keyboard and i used [JTextFiled] means that just you can write inside the program (i.e inside the JTextField) but i want to make this program to let me write where i
please give me a java program for the following question
please give me a java program for the following question  Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  example java coding that reads in the radius and length of cylinder and computes volume. formula: Area = radius * radius * PI Volume = area * length
PLEASE HELP CAPTCHA PROBLEM
PLEASE HELP CAPTCHA PROBLEM  how can i make the captcha refresh autometically ???? please help this is <%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing"%> <%@ Import Namespace
coding problem in netbeans - Java Beginners
coding problem in netbeans  hi, i have just started programming in netbeans,i'm facing a problem in a java application i create a jframe class and jbutton and jtextfeild inside it now i have created another class c1
Coding errors for printing function, please help
Coding errors for printing function, please help  Hello, We, my...; Please visit the following link: http://www.roseindia.net/java/example/java.... Can someone please take a look and help me to fix this. Although
have any one tried ajaxanywhere with jsp/servlet please provide sample
have any one tried ajaxanywhere with jsp/servlet please provide sample ... AAUtil but gives error on compile.   Hi Friend, Please visit the following links: Example1 Example2 Thanks
Java Coding Problem - Java Beginners
Java Coding Problem  Q.1 How to write a while loop that displays all even numbers till 40? Q.2 How to write a method that accepts an integer parameter and displays the divisors of that integer?  Hi friend
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  Write a java program that reads the following information and prints a payroll statement: Employee‚??s name (e.g: Sam) Number of hours worked in a week (e.g: 10
hi... pls give me the example of java coding for following question
hi... pls give me the example of java coding for following question   Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest
Please Provide the direct Downloadable source code for better understanding
Please Provide the direct Downloadable source code for better understanding  Hello Roseindia Team, This is Mohammed Vaseem. Am very much impressed.... I kindly request you to please provide the direct downloadable source code so
coding problem using vb and access - Security
coding problem using vb and access  i have problem on coding using vb... that program.so hard for me.i have no idea. then i also have problem on update,delete and add... please help me.as soon as possible..please
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok button. 6 Textbox to Add the 6 Team Name. Each Team Name In String(Like- A,B,C,D,E,F... This Problem With If...Else If...Else Statement But When the More Team
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
Advertisements
 

 

 

DMCA.com