• 0

Java hw help please


Question

Need help writing a code that reads a file, gathers the tokens, and then gives the user back an awnser based on the information from the tokens. In this case the tokens are names and test scores and the out puts are names and final grades. They are to all be displayed at once and it does not have to use any popup windows. Below are the teachers hw asignment and a piece of program he gave us to get started with

""Homework-2

You do not need to send me your input file. Your program should work with my input file named hw2.txt.

Write a java program FirstnameLastnameHw2.java that reads student info from an external file with the following data, and displays the grades as displayed below.

Input file hw2.txt (be aware of copy/paste issue). Add a record with your own name (and some numbers).

Max Batman 73 83 93 20 20 20 18

Jim Harper 76 88 68 15 20 20 20

Joanna Karr 62 92 91 12 20 20 18

Sue Hammond 75 88 78 20 0 20 20

Mickie Foxx 65 77 91 12 0 0 20

Sue Sirmons 98 52 94 20 20 20 0

Jacqueline Savannah 98 87 99 0 20 20 20

your name . . . .

There are three test scores, out of 100 each, worth 60% and four homework scores, out of 20 each, worth 40% of grade.

Apply 90%, 80%, 70% and 60% (standard) cutoff levels for letter grade computation.

Example output (grades/averages are not accurate):

Student Names Average Letter Grades

--------------------------------------------

Batman, Max 87 B

Harper, Jim 73 C

Karr, Joanna 78 C

Hammond, Sue 82 B

Foxx, Mickie 53 F

Sirmons, Sue 93 A

Savannah, Jacqueline 94 A

Your name .. ..

--------------------------------------------""

""import java.util.scanner;

import java.io.*;

public class FileReader

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

{ File file1 = new File("hw2.txt"); // finds file

Scanner inFile = new Scanner(file1); // reads file

while (inFile.hasNext())

{ String line = inFile.nextLine();

System.out.println(line);

}

}

}""

Link to comment
https://www.neowin.net/forum/topic/1133234-java-hw-help-please/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I would read each line and each line use split string each space. This will return an array with first name, last name and grades in their own spot. Array[0] is first name. Array[1] last name etc. Then you can call a for loop on that array from 2 to array. Length. Then grab each grade and use parse into to return the intended value of that string. Then average the grade.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Chrome is Google's commercial web browser product; it consists of their proprietary features (Googlified everything including profile sync) plus their chromium project barebones web browser. Google developers control the chromium project. The chromium project is the "core" for the web browser product from other vendors including Microsoft Edge (their own proprietary features), Opera (their own features), Brave (their own features), etc... The "downstream" teams at Microsoft, Opera, Brave, etc., can either integrate their original MV2-supporting code into future builds, or they can integrate chromium wholesale and simply add-on their own features/functionalities -- their 'current' build pipeline, so to speak. THIS is why changes at the chromium project affect so many products besides only Google's commercial Chrome browser. -- Edit to add: The chromium project is open-source, and is the piece that's Google's code contribution to the W3C and world wide web at large; there are no licensing fees for others to use the code in their own products... which is what they do. Other browser engines do exist (Firefox's for example) but it's nearly impossible to have both engines bundled into the same 1 browser product.
    • You're comparing settler colonies to colonized war torn nations. It's easy to become the richest by coming in and stealing other people's land, culture and resources.
    • ABP has become "old news" when MV3 started rolling out. They've gone downhill and is now simply irrelevant..... in my experience.
    • About two years ago, I switched to Brave and haven't looked back.
    • FWIW StatCounter has been trash for over 25+ years! Back in the day (circa 2000 and GeoCities pre-Blogger era), it was useful to paste a number on your webpage indicating how many visitors you had. In the ensuing 25+ years, they've grown in reputation and changed their ways... but their overall consumer value has remained abysmal. Serious marketing agencies only cite StatCounter when there's literally no other sources available to support any marketing claims! They are the absolute lowest threshold serious companies use to push any sort of narrative about this-or-that happening. Besides their credibility being what it is, they are forever subject to quality issues. They're so bad that my DNS-level ad-filter prevents me from even viewing their main website! HA!
  • Recent Achievements

    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • One Year In
      jojodbn earned a badge
      One Year In
    • One Month Later
      jojodbn earned a badge
      One Month Later
    • Week One Done
      jojodbn earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      531
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      131
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!