Win a copy of Head First Android this week in the Android forum!

Christopher Goad

Greenhorn
+ Follow
since Mar 25, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christopher Goad

I just used if(candidates[i] == null){} to seperate all the nulls works perfect now! Thanks!
8 years ago
Thanks for the reply! That makes sense..but how would you do it? Could you demonstrate?
8 years ago
What do you mean?

And yes I know... this is just what the directions stated to do.
8 years ago
How could I fix this? I understand the problem but I just don't know what to do about it...

The error is-


Exception in thread "main" java.lang.NullPointerException
at TestCandidate7.getTotal(TestCandidate7.java:14)
at TestCandidate7.printResults(TestCandidate7.java:28)
at TestCandidate7.main(TestCandidate7.java:197)



Here is my code-



8 years ago
Having trouble adding to ArrayList. I have to convert the normal array to an arraylist.


16.01 Assignment Instructions
Instructions: For this assignment, you are going to use traversal methods.
1. Create a folder called 16.01 Assignment in your module 16 assignments folder.
2. Create a class called Candidate.
a. Candidate will need instance variables name and numVotes (of types String
and int, respectively).
b. Candidate will need appropriate methods and constructors. Make sure to have a
toString() method that prints the name of the Candidate along with the
number of votes.
c. Save the class as Candidate.java.
3. Create a class called TestCandidate and save it as TestCandidate.java.
a. Make sure that you create an array called election. Add the following
Candidates with their votes:
Candidate Vote
John Smith 5000
Mary Miller 4000
Michael Duffy 6000
Tim Robinson 2500
Joe Ashtony 1800
b. Create a method called printVotes() that traverses through the array and
prints out each element.
c. Create a method called getTotal() that traverses through the array and counts
the total of the votes for all Candidates. It should return that number.
d. Create a method called printResults() that traverses through the array and
creates a table with columns for Candidate name, followed by votes received, and
then percentage of total votes (you can round these values). Note that this method
will need to call getTotal() to use in constructing the third column. After
printing the table, print a line showing the total number of votes for all
Candidates.
e. Test your methods. Your output should be similar to that shown below: 4. Now create a class TestCandidate2 and save it as TestCandidate2.java.
a. Create the same items as for TestCandidate; however, use an ArrayList
instead.
b. Output should still look the same as for TestCandidate.



I have done all of this fine. Just the last step is giving me trouble.

Here is my code.





Any help would be great...

8 years ago
Is there any way you could show me what you mean?
8 years ago
Is there any way you could show me what you mean?
8 years ago
I know that's the problem... what should go into the getQuiz and setQuiz method?
What data structure?
8 years ago
I use eclipse so it does let me..

Anyway how would I go about getting that variable?
8 years ago
Okay,

Problem 1: The percent is always 0

Problem 2: I am getting a compiler error

Problem 3: it just looks weird
8 years ago
I almost have this project completed just getting a few errors and would like a check over to see if I have got all of this correctly.

Here are the Assignment Instructions.


16.05 Assignment Instructions
Instructions: For this assignment, you are going to use all your standard algorithm methods.
1. Create a folder called 16.05 Assignment in your module 16 assignments folder.
2. Create a class called Student.
a. Student will need instance variables name , qz1, qz2, qz3, qz4, and
qz5 (of types String and int, respectively).
b. Student will need appropriate methods and constructors. To make things
interesting, create a getQuiz() method that takes in a quiz number as input and
then returns the appropriate quiz value. Likewise, setQuiz() will take as input
a quiz number and quiz score, and then put the value into the right variable. Make
sure to have a toString() method that prints the name of the student along
with the quiz scores.
c. Save the class as Student.java.
3. You are to create a class called TestStudent and save it as TestStudent.java.
a. In this assignment you may choose to use either an array or an ArrayList; there is
no need to do two versions of the program.
b. Make sure that you create data structure called myClass. Add the following
students with their quiz scores.
Candidate Q1 Q2 Q3 Q4 Q5
Mark Kennedy 70 80 90 100 90
Max Gerard 80 85 90 85 80
Jean Smith 50 79 89 99 100
Betty Farm 85 80 85 88 89
Dilbert Gamma 70 70 90 70 80
c. Create a method called printBook() that traverses through the data structure
and prints out each element.
d. Create a method called replaceName() that replaces a student’s name with a
new one.
e. Create a method called replaceQuiz() that replaces a student’s quiz grade
with a new one. It should replace only one quiz grade, as indicated, when it is
called. It will have the data structure, quiz number, and quiz value as input.
f. Create a method called replaceStudent() that replaces a student with
another one. It will have the data structure, name to replace, new student name,
and quiz scores as input.
g. Create a method called insertStudent() that inserts a new student before
another student in the data structure. It will have the data structure, name to find,
new student name, and quiz scores as input.
h. Create a method called deleteStudent() that finds a student by name and
then deletes that student.
i. Remember to make sure your methods handle there being null elements in the
data structure. j. Test your met



Here is my code:



8 years ago
Having just a few problems. So close to finishing this assignment.

Problem 1: Percent of votes not coming out correctly

Problem 2: Total is not printing

Problem 3: Table allignment is weird.

Here is my code



8 years ago
I just do not know where to start off at. I'm getting confused...
8 years ago
I'm sorry I forget to post the assignment instructions. Here they are.

15.05 Assignment Instructions
1. Create a folder called 15.05 Assignment in your module 15 assignments folder.
2. Create an interface named Product .
a. Add a method called getName() that returns a string.
b. Add a method called getCost() that returns a double.
3. Create abstract class Vehicle that implements Product.
a. It should have string variable name and double cost, that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods
4. Create classes Car and Truck that extend Vehicle.
a. No other methods are needed.
5. Create class Tool that implements Product and Comparable<T> .
a. It should have string variable name and double cost that are initialized in the constructor.
b. Add appropriate getName() and getCost() methods.
c. Add a compareTo() method that compares tools based upon cost .
6. Create class InventoryDemo.
a. Test your classes by using ArrayList products of following products (Remember to declare it properly using List):
Name
Cost
Jaguar
1000000.00
Neon
17000.00
JigSaw
149.18
Jaguar
110000.00
Neon
17500.00
Neon
17875.32
RAM
35700.00
CircularSaw
200.00
CircularSaw
150.00
b. Create a static method takeInventory that, when passed the name of a product, will go through the list and print out <item name>: Quantity = <quantity>, Total cost = <totalcost>. <item name> is the name of the product, <quantity> and <totalcost> are the values you calculate by going through the list for the product with name that was passed to takeInventory.
c. To test the compareTo() method, create two Tools, saw1 , and saw2 . Give them different prices and then test the compareTo() method you made, by displaying which one is more expensive.
8 years ago
Could you possibly help me with my code?
8 years ago