Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA- I want to edit the following code, taking out the parts involving entering the filename. Data will only need to be read in using

JAVA- I want to edit the following code, taking out the parts involving entering the filename. Data will only need to be read in using Putty using

"java Prog6 < in1.dat/ in2.dat/in3.dat" and so on. There are three different files that are to be read in and printed out, so I am not able to hard code in one specific filename. In previous assignments, I have used reader.next() to pull the correct info from the files. Is there any way to change the lines about reading in a file name into "reader.next()"? I don't need any specific user input asking for a filename since I will only read in data through java Prog6 < in1.dat in Putty.

package parking;

import java.io.File; import java.io.FileNotFoundException; import java.text.DecimalFormat; import java.util.Scanner;

public class Arrays {

public static void main(String args[]) { double highestscore=0; double offset=0; String[] names; double[][] marks;// holds raw marks in first column and curve marks in second column Scanner keyboard=new Scanner(System.in); System.out.println("enter the names of files with space in between"); while(keyboard.hasNext()) { String filename=keyboard.next();

Scanner in;

try { in = new Scanner( new File(filename) ); int size =in.nextInt(); names=new String[size]; marks=new double[size][2]; for(int i=0;i { names[i]=in.next(); marks[i][0]=in.nextDouble(); if(highestscore { highestscore=marks[i][0]; } } offset=100-highestscore; System.out.println("Student Names\t\tRaw score\t\tWith Curve");

DecimalFormat df = new DecimalFormat(".##");

for(int i=0;i { marks[i][1]=marks[i][0]+offset; System.out.println(String.format("%s\t\t\t %s\t\t\t %s",names[i],marks[i][0],df.format(marks[i][1]))); } } catch (FileNotFoundException e) {

System.out.println(e.getMessage()); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions