SlideShare a Scribd company logo
1 of 4
Download to read offline
I need hlep I have posted this proble 4 times have gotten no help can come re write my code so
that It works
//import statemnts for Random, Scanner and IO
import java.util.Random;
import java.util.Scanner;
import java.io.*;
public class Hobbits
{
public static void main(String[] args) throws IOException
{
final int NUM_HOBBITS = 5;
final int NUM_COLUMNS = 2;
String fileName = "hobbits.csv";
//call populateHobbits() to create the two-dimensional array
double[][] hobbits = populateHobbits(NUM_HOBBITS, NUM_COLUMNS);
//display the number of hobbits
System.out.println(hobbits.length + " hobbits accepted Gandalf's invitation to lunchn");
//calculate the means of the columns
double[] hobbitMeans = getColMeans(hobbits);
//write hobbits array to file
writeHobbits(hobbits, fileName);
//read and display the file that has been read
readHobbitses(fileName);
//call displayColMeans to display hobbit means
displayColMeans(hobbitMeans);
}
//method to populate hobbits array with random double values
public static double[][] populateHobbits(int numHobbits, int numCols) {
final double HT_MULTIPLIER = 10.0; //multiplier for the hobbit height
final double WT_MULTIPLIER = 250.0; //multiplier for the hobbit weight
//instantiate Random object
Random rand = new Random();
//declare two-dim array with numHobbits rows numCols columns
double[][] hobbitArray = new double[numHobbits][numCols];
//assign random double values to all elements
for (int i = 0; i < numHobbits; i++) //outer loop is for rows
{
for (int j = 0; j < numCols; j++) //inner loop is for columns
{
//get a random double value in range [0.2, 0.4]
double randDouble = getRandDouble(rand);
//assign this double to the current array element
hobbitArray[i][j] = randDouble;
//determine which multiplier to use
if (j == 0) //this is column for height
hobbitArray[i][j] *= HT_MULTIPLIER;
else //this is column for weight
hobbitArray[i][j] *= WT_MULTIPLIER;
}
}
return hobbitArray; //return the two-dimensional array
}
//method to write hobbits array to file
public static void writeHobbits(double[][] ar, String fileName) throws IOException
{
PrintWriter outFile = new PrintWriter(new FileWriter(fileName));
//print column heading of the array of stats
outFile.println("HEIGHT,WEIGHT");
for (int i = 0; i < ar.length; i++) {
for (int j = 0; j < ar[i].length; j++)
{
outFile.print(ar[i][j]);
//if at end of a row, add newline char
if (j == ar[i].length - 1)
outFile.print("n");
else //add the "," delimiter
outFile.print(",");
} //end of inner loop
} //end of outer loop
outFile.close(); //close outfile
System.out.println("The file was successfully writtenn");
} //end of method
//method to reads the hobbits file
public static void readHobbitses(String fileName) throws IOException {
//open the file to read
File dataFile = new File(fileName);
Scanner inFile = new Scanner(dataFile);
//variable to contain the substrings of one line of file
String[] oneLine = new String[2];
int counter = 0; //keep track of line numbers
System.out.println("Data read from the " + fileName + " file:");
//read file, one line at a time
while (inFile.hasNext()) {
String dataLine = inFile.nextLine();
oneLine = dataLine.split(","); //split line with delimiter
if (counter > 0) //for second line and beyond, format doubles
{
System.out.printf("%.2ftt%.2fn", Double.parseDouble(oneLine[0]),
Double.parseDouble(oneLine[1]));
} else //if this first line, display the column heading
System.out.println(oneLine[0] + "t" + oneLine[1]);
if (inFile.hasNext())
counter++; //keep track of how many lines
} //end while loop read file
inFile.close(); //close the file
System.out.println("The file has now been successfully read.n");
} //end of method
//method to determine average values of columns two dim array
public static double[] getColMeans(double[][] ar) {
//local array to store means
//array is sized according to length second dimension of parameter
//first element is mean of first cplumn
//second element is mean of second column, etc
double[] meanAr = new double[ar[0].length];
//nested for loop to iterate through elements in parameter
for (int i = 0; i < ar.length; i++) {
for (int j = 0; j < ar[i].length; j++) {
//sum the elements in the current column
meanAr[j] += ar[i][j];
}
} //end of outer loop
//replace the sum with the average; i.e. divide by number of rows
for (int i = 0; i < meanAr.length; i++)
meanAr[i] /= ar.length;
return meanAr;
return meansAr;
} //end of method
Lab16 Sample output

More Related Content

Similar to I need hlep I have posted this proble 4 times have gotten no help can.pdf

cant figure out how to add $20 to variables if it equals one of the .pdf
cant figure out how to add $20 to variables if it equals one of the .pdfcant figure out how to add $20 to variables if it equals one of the .pdf
cant figure out how to add $20 to variables if it equals one of the .pdfxlynettalampleyxc
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCIS321
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageESUG
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdfanandatalapatra
 
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdffederaleyecare
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfmohdjakirfb
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageAnıl Sözeri
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
Core c sharp and .net quick reference
Core c sharp and .net quick referenceCore c sharp and .net quick reference
Core c sharp and .net quick referenceArduino Aficionado
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick referenceilesh raval
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 

Similar to I need hlep I have posted this proble 4 times have gotten no help can.pdf (20)

cant figure out how to add $20 to variables if it equals one of the .pdf
cant figure out how to add $20 to variables if it equals one of the .pdfcant figure out how to add $20 to variables if it equals one of the .pdf
cant figure out how to add $20 to variables if it equals one of the .pdf
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
ES6 and BEYOND
ES6 and BEYONDES6 and BEYOND
ES6 and BEYOND
 
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdf
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Having Fun Programming!
Having Fun Programming!Having Fun Programming!
Having Fun Programming!
 
Core c sharp and .net quick reference
Core c sharp and .net quick referenceCore c sharp and .net quick reference
Core c sharp and .net quick reference
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick reference
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Txjs
TxjsTxjs
Txjs
 

More from shreeaadithyaacellso

In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdfIn c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdfshreeaadithyaacellso
 
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdfIn Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdfshreeaadithyaacellso
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdfshreeaadithyaacellso
 
In C Programming- not C++ Write a function which takes two formal pa.pdf
In C Programming- not C++   Write a function which takes two formal pa.pdfIn C Programming- not C++   Write a function which takes two formal pa.pdf
In C Programming- not C++ Write a function which takes two formal pa.pdfshreeaadithyaacellso
 
In chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdfIn chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdfshreeaadithyaacellso
 
In cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdfIn cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdfshreeaadithyaacellso
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdfshreeaadithyaacellso
 
In C++ Complete the program with the bold requirements #include #i.pdf
In C++  Complete the program with the bold requirements   #include  #i.pdfIn C++  Complete the program with the bold requirements   #include  #i.pdf
In C++ Complete the program with the bold requirements #include #i.pdfshreeaadithyaacellso
 
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdfI am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdfshreeaadithyaacellso
 
I got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdfI got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdfshreeaadithyaacellso
 
I am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdfI am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdfshreeaadithyaacellso
 
I am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdfI am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdfshreeaadithyaacellso
 
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdfI et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdfshreeaadithyaacellso
 
I am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdfI am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdfshreeaadithyaacellso
 
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdfI am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdfshreeaadithyaacellso
 
i cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdfi cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdfshreeaadithyaacellso
 
I am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdfI am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdfshreeaadithyaacellso
 
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdfI need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdfshreeaadithyaacellso
 
I need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdfI need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdfshreeaadithyaacellso
 
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdf
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdfI need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdf
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdfshreeaadithyaacellso
 

More from shreeaadithyaacellso (20)

In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdfIn c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
In c++ Polymorphism is one of the hallmarks of OOP languages- What are (1).pdf
 
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdfIn Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
In Chapter 4 of LS- there is a case of Zappos and it describes how Zap.pdf
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
 
In C Programming- not C++ Write a function which takes two formal pa.pdf
In C Programming- not C++   Write a function which takes two formal pa.pdfIn C Programming- not C++   Write a function which takes two formal pa.pdf
In C Programming- not C++ Write a function which takes two formal pa.pdf
 
In chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdfIn chapter 17 you learned about the big picture of circulation through.pdf
In chapter 17 you learned about the big picture of circulation through.pdf
 
In cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdfIn cell M11- enter a formula that will calculate the total amount due.pdf
In cell M11- enter a formula that will calculate the total amount due.pdf
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
 
In C++ Complete the program with the bold requirements #include #i.pdf
In C++  Complete the program with the bold requirements   #include  #i.pdfIn C++  Complete the program with the bold requirements   #include  #i.pdf
In C++ Complete the program with the bold requirements #include #i.pdf
 
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdfI am studying for a test tomorrow in my 494 Population Biology class-.pdf
I am studying for a test tomorrow in my 494 Population Biology class-.pdf
 
I got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdfI got the codes written down below- Basically- I am trying to implemen.pdf
I got the codes written down below- Basically- I am trying to implemen.pdf
 
I am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdfI am trying to write a program that will converts a 32bit float number.pdf
I am trying to write a program that will converts a 32bit float number.pdf
 
I am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdfI am stuck on this question- please show the solution step by step- Re.pdf
I am stuck on this question- please show the solution step by step- Re.pdf
 
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdfI et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
I et X and Y he two indenendent R(3n-1-3) random variables- Calculate.pdf
 
I am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdfI am working on a coding project- and it asked me to combine five sets.pdf
I am working on a coding project- and it asked me to combine five sets.pdf
 
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdfI am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
I am needing to do a Point Factor Job Evaluation for a IT Company whos.pdf
 
i cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdfi cant figure out this excel equation For the Year Ended December 31-.pdf
i cant figure out this excel equation For the Year Ended December 31-.pdf
 
I am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdfI am writing a program that will allow the user to move the crosshairs.pdf
I am writing a program that will allow the user to move the crosshairs.pdf
 
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdfI need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
I need simple java code for the below scenario- UML Diagrams(Class-Use.pdf
 
I need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdfI need question 1 answer in java language- question 1)Create an applic.pdf
I need question 1 answer in java language- question 1)Create an applic.pdf
 
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdf
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdfI need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdf
I need help with this question- Thank you! Problem -#1- (5pts) - Nutri.pdf
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

I need hlep I have posted this proble 4 times have gotten no help can.pdf

  • 1. I need hlep I have posted this proble 4 times have gotten no help can come re write my code so that It works //import statemnts for Random, Scanner and IO import java.util.Random; import java.util.Scanner; import java.io.*; public class Hobbits { public static void main(String[] args) throws IOException { final int NUM_HOBBITS = 5; final int NUM_COLUMNS = 2; String fileName = "hobbits.csv"; //call populateHobbits() to create the two-dimensional array double[][] hobbits = populateHobbits(NUM_HOBBITS, NUM_COLUMNS); //display the number of hobbits System.out.println(hobbits.length + " hobbits accepted Gandalf's invitation to lunchn"); //calculate the means of the columns double[] hobbitMeans = getColMeans(hobbits); //write hobbits array to file writeHobbits(hobbits, fileName); //read and display the file that has been read readHobbitses(fileName); //call displayColMeans to display hobbit means displayColMeans(hobbitMeans); } //method to populate hobbits array with random double values public static double[][] populateHobbits(int numHobbits, int numCols) { final double HT_MULTIPLIER = 10.0; //multiplier for the hobbit height final double WT_MULTIPLIER = 250.0; //multiplier for the hobbit weight //instantiate Random object Random rand = new Random(); //declare two-dim array with numHobbits rows numCols columns double[][] hobbitArray = new double[numHobbits][numCols];
  • 2. //assign random double values to all elements for (int i = 0; i < numHobbits; i++) //outer loop is for rows { for (int j = 0; j < numCols; j++) //inner loop is for columns { //get a random double value in range [0.2, 0.4] double randDouble = getRandDouble(rand); //assign this double to the current array element hobbitArray[i][j] = randDouble; //determine which multiplier to use if (j == 0) //this is column for height hobbitArray[i][j] *= HT_MULTIPLIER; else //this is column for weight hobbitArray[i][j] *= WT_MULTIPLIER; } } return hobbitArray; //return the two-dimensional array } //method to write hobbits array to file public static void writeHobbits(double[][] ar, String fileName) throws IOException { PrintWriter outFile = new PrintWriter(new FileWriter(fileName)); //print column heading of the array of stats outFile.println("HEIGHT,WEIGHT"); for (int i = 0; i < ar.length; i++) { for (int j = 0; j < ar[i].length; j++) { outFile.print(ar[i][j]); //if at end of a row, add newline char if (j == ar[i].length - 1) outFile.print("n"); else //add the "," delimiter outFile.print(","); } //end of inner loop } //end of outer loop outFile.close(); //close outfile System.out.println("The file was successfully writtenn");
  • 3. } //end of method //method to reads the hobbits file public static void readHobbitses(String fileName) throws IOException { //open the file to read File dataFile = new File(fileName); Scanner inFile = new Scanner(dataFile); //variable to contain the substrings of one line of file String[] oneLine = new String[2]; int counter = 0; //keep track of line numbers System.out.println("Data read from the " + fileName + " file:"); //read file, one line at a time while (inFile.hasNext()) { String dataLine = inFile.nextLine(); oneLine = dataLine.split(","); //split line with delimiter if (counter > 0) //for second line and beyond, format doubles { System.out.printf("%.2ftt%.2fn", Double.parseDouble(oneLine[0]), Double.parseDouble(oneLine[1])); } else //if this first line, display the column heading System.out.println(oneLine[0] + "t" + oneLine[1]); if (inFile.hasNext()) counter++; //keep track of how many lines } //end while loop read file inFile.close(); //close the file System.out.println("The file has now been successfully read.n"); } //end of method //method to determine average values of columns two dim array public static double[] getColMeans(double[][] ar) { //local array to store means //array is sized according to length second dimension of parameter //first element is mean of first cplumn //second element is mean of second column, etc double[] meanAr = new double[ar[0].length]; //nested for loop to iterate through elements in parameter for (int i = 0; i < ar.length; i++) { for (int j = 0; j < ar[i].length; j++) {
  • 4. //sum the elements in the current column meanAr[j] += ar[i][j]; } } //end of outer loop //replace the sum with the average; i.e. divide by number of rows for (int i = 0; i < meanAr.length; i++) meanAr[i] /= ar.length; return meanAr; return meansAr; } //end of method Lab16 Sample output