• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Make methods

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't figure out how to make the methods I need for these ...

readAndStore
printClass
computeGrades




this is the tester for the above class
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are they supposed to do? Surely someone has given you some idea or specs regarding how they need to be implemented.

And technically, the methods have been made. They are all right there on lines 31-40. Granted, they have probably not been properly IMPLEMENTED, but we have no way to know what they are supposed to do.

If you explain that to us, then you'll know how to implement them yourself.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are still at the stage of knowing how to make methods, you ought only to write a few lines. Create some class to practise on. Create a few methods and make another class with a main method to test them out. Here’s a possible classAdd some methods. How about a void celebrateBirthday() method, which makes you one year older? How about int getYoungestPartnerAge(), which returns age ÷ 2 + 7 ? How about a Party class, and a Couple class? How about a method in the Party class, which creates two Person objects and sees whether age ÷ 2 + 7  applies, and if so, creates a Couple object from them? (Work out what to do if it doesn’t apply. Maybe return null?)

I shall stop making such silly suggestions and refer you to the Java Tutorials, where you will find a little more about methods.
 
Tom Cummings
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the output needs to look like this ...

Sample input data file
Michael 70
Dondiego 80
Troy 100
Derrick 55
Richard11 60 //name is invalid
Jamel 80.50 //score is invalid
David 99
Thomas 85
JohnAnthony 10
Devin 25
Antwann 66
Christopher 55
Erin 82
Sample output of the program

<Your name here>
Class Name: <Enter your class name here>
Instructor Name: <Enter your instructor>
Semester: <Enter current Semester
School Name: <Enter your school here>
Class Size: 0
Highest Score: -999
Lowest Score: 999
Average Score: 0.0
Ï
<Your name here>
Class Name: CS3410
Instructor Name: Smith
Semester: Spring
School Name: Georgia Institute of Technology
Class Size: 10
Highest Score: 100
Lowest Score: 10
Average Score: 64.5

Ï
NUMBER NAME SCORE GRADE

1 Michael 70 C
2 Dondiego 80 B
3 Troy 100 A
4 Derrick 55 F
5 David 99 A
6 Thomas 85 B
7 JohnAnthony 10 F
8 Devin 25 F
9 Antwann 66 D
10 Christopher 55


That's all I was given I made the methods but ,yes I do not know how to implement them correctly.
 
Tom Cummings
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have came up with this ....



But it still is not working right
 
Tom Cummings
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- This project should accomplish the following tasks:
1. Reading from a text file data13.txt (entered as an argument). The file contains names and integer scores. One name and a score per line. Names are supposed to be alphabet and scores are supposed to be integers. Assume the input file has up to 100 names and scores.
2. Scan each token from the file. If name or score is invalid, do not store them in names and scores arrays. .
3. Implement MyArrays13 class as specified in the UML diagram below. NAME IT MyArrays13.java

- name : String
- className: String
- instructorName : String
- semesterName: String
- schoolName: String
- highestScore: int
- lowestScore:int
- averageScore: double
- size: int
- integerPattern: String
- alphbaetPattern: String “Your name>
“Your class”
“Your Instructor”
“Fall”
“Valdosta State University
-999
999
0.0
0
"^[0-9]*$"
"^[a-zA-Z]*$"


+MyArrays13()
+MyArrays13(className: String, instructorName:String, semesterName:String, schoolName:String)
+readAndStore (file:Scanner,names:String [], scores[]:int) : void
+printClass (names:String[], scores: int[], grades: char[]):void
+computeGrades (scores:int [], grades: char []):void
+highestScore (scores: int []):void
+lowestScore (scores: int []):void
+averageScore (scores: int []):void
+toString():String





 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom Cummings wrote:I have came up with this .... . . .

I am afraid I didn’t even read it all. When people say that sort of thing, I get all suspicious and think they are guessing. You can guess a million times and maybe hit the right answer.


Or you can work it out and get the right answer first time.
Get yourself a pencil and paper and go through exactly how you are going to achieve that. If you are using a switch on percentage / 10 (not a good idea until you are familiar with methods and division), write down exactly what you get if you divide the limiting marks. After the end of that switch block and before the end of the loop, put in some testing code, eg
System.out.printf("At score %3d%% the grade was %s%n", scores[i], grades[i]); //test
When you are happy that bit is working all right, you can move on to the next bit.
Look for declarations. You can tell a declaration whenever it has a type, eg int written in. Make sure you never declare the same thing twice by mistake.
Have you been told to use parallel arrays? That is usually a very bad idea. Why did they not tell you to create Student objects to encapsulate the mark, grade and name?
There is some poor formatting; you have two }} on the same line. That is a sure-fire way to lose count of your braces and get errors you cannot understand.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
more advice: work on only ONE method at a time. The whole point of having methods is that they are independent of each other. Your computeGrades method really doesn't care how you get the data - you could read it from a file, pull from a database, open a socket to a different server, or just about anything else.

So pick one of those three methods. Get it to work before you consider writing any of the others.

Whichever you work on first, you will write a lot of code you eventually throw away to prove that it works. I probably write 5 System.out.println() statements for every line of code I end up keeping. I validate methods get called, and what they return. I prove that my computations are correct. I show that the data is being stored.

So, perhaps you should start with the readAndStore method. What does it need to do? Break it down into discrete steps (which might imply you need additional methods). Once that works, then you can use it to build/test the next method.
reply
    Bookmark Topic Watch Topic
  • New Topic