• 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

    • I do trust Apple probably more than these other companies with certain data, but I also do think (and it has been demonstrated that) Apple pulls a lot of shenanigans and always has for a long time.
    • Does your iPhone support the latest iOS version? Here's the iOS 27 compatibility list by Aditya Tiwari It's that time of year when we get to know about the latest operating system updates for Apple devices. For iPhone, Apple previewed the iOS 27 update at WWDC 2026, where the company finally introduced an upgraded version of Siri. Apple typically supports iPhone models for up to five years. But it has been making exceptions in recent years (read iPhone 11). If you're wondering whether your iPhone is compatible with the iOS 27 update, here is the official list of devices: iPhone 17 Pro Max, iPhone 17 Pro, iPhone 17, iPhone 17e, iPhone Air iPhone 16 Pro Max, iPhone 16 Pro, iPhone 16, iPhone 16 Plus, iPhone 16e iPhone 15 Pro Max, iPhone 15 Pro, iPhone 15 Plus, iPhone 15 iPhone 14 Pro Max, iPhone 14 Pro, iPhone 14 Plus, iPhone 14 iPhone 13 Pro Max, iPhone 13 Pro, iPhone 13, iPhone 13 mini iPhone 12 Pro Max, iPhone 12 Pro, iPhone 12, iPhone 12 mini iPhone 11 Pro Max, iPhone 11 Pro, iPhone 11 iPhone SE (2nd generation), iPhone SE (3rd generation) So, you can download the iOS 27 developer beta on up to 31 different iPhone models. There has been no change to the list of supported iPhones since iOS 26. However, it will expand to include more devices when the iPhone 18 series arrives later this year. To download the developer beta on your iPhone, go to Settings > General > Software Update > Beta Updates. Here, select "iOS 27 Developer Beta" from the list of choices to get the new update. In addition to iOS 27, you can try the developer beta versions of macOS 27, iPadOS 27, watchOS 27, tvOS 27, and HomePod software 27 on your supported devices. iOS 27 comes with improved Liquid Glass, which you can adjust using a new transparency slider. Apple said during the keynote that iPhone apps now launch up to 30% faster, new photos appear in the Photos app up to 70% faster, and AirDrop transfers work up to 80% faster. The new update promises to improve performance on older iPhones by introducing a new CPU Scheduler that supports devices all the way back to the iPhone 11. While iOS 27 is supported on older iPhones, it goes without saying that they'll lack several features due to hardware differences. For instance, iPhone 14/14 Plus and older models come with a notch instead of the Dynamic Island. Similarly, Apple Intelligence features are supported on iPhone 15 Pro/Pro Max and later models.
    • The Radeon RX 9070 XT is right up there with the GeForce RTX 5070 Ti
    • I don't know why someone said useless, but it does have that pesky kernel driver bundled, and it's in perennial turmoil. When it goes bad, it goes very bad, and it's impossible to predict when it will due to system differences. I know that they're in the middle of development for a major new version that will include a completely new driver, one that they expect will largely solve the problem, but that's a ways out and it's unproven at this point.
    • doesn't AdGuard let ads through that pay to be let through?
  • Recent Achievements

    • Experienced
      JayZJay went up a rank
      Experienced
    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • Week One Done
      jojodbn earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      526
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      132
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!