Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4608438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:50:42+00:00 2026-05-22T00:50:42+00:00

I wrote this simple script that reads a text file and then adds the

  • 0

I wrote this simple script that reads a text file and then adds the data to an array however i only want to print the first and last name of the students that have over 90 credits

Student[] student = new Student[50];

        Scanner userin, filein;
        String filename;
        int numStudents;

        // Get the filename from the user, with exception handling to deal with incorrect file names
        userin = new Scanner(System.in);
        filename = null;
        filein = null;
            filename =  Students.txt;
            try {
                filein = new Scanner(new FileReader(filename)); // try to open the file
            } catch (FileNotFoundException e) { // failed to open the file
                System.out.println("Invalid file - try again");
                filename = null;
            }

numStudents = 0;
        while (filein.hasNext()){
String lastName = filein.next();
String firstName = filein.next();            
double gpa = filein.next();
int Credits = filein.next();

            student[numStudents++] = new Student(lastName,firstName,gpa,Credits);    

        }     

int i=0;  
      do
      {


            System.out.println(student[i].toString());

            i++;


      }
    while ((student[i] != null)&&(i <= student.length)); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:50:43+00:00Added an answer on May 22, 2026 at 12:50 am

    “script”?

    This is some ugly code. Formatting and structure matter. I’d recommend paying more attention to it in the future. It’ll make your maintenance life easier as your programs (aka “scripts”) become more complex.

    Learn the Sun Java coding standards. You aren’t following them now.

    Everything in Java has to be a part of a class. I’ll assume that you know that. This must be a snippet you cut out of your class.

    Your code is too chaotic to worry about making it nice. This’ll work:

       if (student[i].getCredits() >= 90)
           System.out.println(student[i].toString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very simple bash script I wrote: #!/bin/bash ITEM_LIST=items.txt LOG_FILE=log.log TOTAL_ITEMS=$(wc -l
I wrote a simple script that add extra form fields when needed by the
So I wrote this simple console app to aid in my question asking. What
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
I am trying to write a powershell script that will take in a text
I'm currently trying to write a simple script that looks in a folder, and
I have a simple python script that just takes in a filename, and spits
I wrote this simple code in python to calculate a given number of primes.
I wrote a script in Python 2.6.2 that scans a directory for SVG's and
Hey guys.. Quick question: I wrote a simple JS that opens lightBox for image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.