• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays in Java  RSS feed

 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following program I need to code a program that given a list of 5 student names and marks for 5 quizes for each student, loads the names in an ArrayList of type String and the quiz marks, loads the names in an ArrayList of type String and the quiz marks in an ArrayList of type Integer.


with the following input:



should give the output




but i am getting the output


 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does the missing text "Quiz Avg: .." come from?  Where is the code that should add that text to the end of a line come from? 
Is that code being called?  If it is not being called, why not? What controls if that code is called?

with the following input: 

How is that input read by the program?  It looks like the user must enter it all via the keyboard.  Should that input be in a file that the program could read?
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite sure how to fix my problem
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have not covered files yet, only touched on arrays, arraylists, and methods
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the program supposed to get its input?

  how to fix my problem

First you need to define the steps the program is going to do to create the desired output. 
Where is the data?  What does it do with the data?  Then how to print the report.
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it needs to read in the data given and print the output, i do not have answers to your questions i simply dont know how to fix this
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
, i do not have answers to your questions i simply dont know how to fix this 

You need to know what the steps the program should take to be able to fix the problem.  Work out the details of the steps of what the code should do, before trying to write the code to do those steps.

Where does the program get the data for the report?  I see two areas in the code that reads data.
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it needs to read the first 2 columns as a string then the next 5 as a int
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
t needs to read the first 2 columns as a string then the next 5 as a int

There needs to be a bit more details.  
How is the data entered?  5 lines with  7 columns

What does the program do with the first two columns? 
If there are 5 names to be entered, shouldn't program read 5 lines that hold the names?
What does the it do with the names that are read?

Same with the int values.  Does the program read 5 lines with 5 values or does it read 25 values?
What does it do with the values it reads?

Then after all the data is read, what next?
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code reads the first 2 columns and stores in in the arrayList string, then it reads in the next 5 columns of the same row and stores them in the arrayList Int, next the arraylIST String is printed along with the corresponding average of the 5 quizes in that row that are then weighed out of 15
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code reads the first 2 columns and stores in in the arrayList string, then it reads in the next 5 columns of the same row and stores them in the arrayList Int, 

Ok. work on just that part of the program first.  Have it read the input lines and separate them into 2 String values and 5 int values and save them.
After the data is read, add print statements that print out the contents of the two ArrayLists so you can see that the input was read OK.

When you see that ArrayLists contain the correct data, move to the next step.
 
Jeremy Bon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not sure how to do this at all
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im  not sure how to do this at all 

Start at the beginning. 
Get the data.
How is the user supposed to enter the data? 
The code needs a println statement telling the user how to enter the data.
Then read the data.

The code currently does most of the above.

I suggest adding a println statement to print out the contents of the input array after it is created by split():
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy Bon wrote:im not sure how to do this at all
NR is giving you some useful advice. I shall give you a bit more.

For the time being, forget about the List. Use one student object and work at that until you get it running correctly. Find out about the toString method and work out how to implement that; then you can write
System.out.println(s);
and get the output you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!