(create a dataset) file with 1000 lines. each line in the file consists of a fac
ID: 3533802 • Letter: #
Question
(create a dataset) file with 1000 lines. each line in the file consists of a faculty member's first name, last name, rank, and salary. the faculty member's first name and last name for the ith line are FirstNamei and LastNamei. The rank is randomly generated as a number with two digits after the decimal point. The salary for an assistant professor should be in the range frin 50,000 to 80,000, fir associate professor from 60,000 to 100,000, and for full professor from 75,000 to 130,000. Save the file in Salary.txt. Here are some sample data.
FirstName1 LastName1 assistant 60055.95
FirstName2 LastName2 assistant 81112.45
Explanation / Answer
import java.io.*;
import java.util.*;
public class Dataset
{
public static void main(String[] args) throws FileNotFoundException
{
String rank[]={ "assistant" , "associate", "full" };
PrintWriter outFile = new PrintWriter("Salary.txt");
double s=0;
for(int i=0;i<1000;i++)
{
String first="FirstName"+i;
String last="LastName"+i;
int r= ((int)(Math.random()*3))%3;
if( r==0)
{ s = 50000.0 + (Math.random() * (80000-50000)); }
else if(r==1)
{ s = 60000.0 + (Math.random() * (100000-60000)); }
else if(r==2)
{ s = 75000.0 + (Math.random() * (130000-75000)); }
outFile.printf("%s %s %s %6.2f %n",first,last,rank[r],s);
}
outFile.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.