|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have this Java program to do for Comp 110. I have no idea what im doing because this is the first time ive ever taken a programming course. Someone Please help me. We have to:
Consider a class BasketballGame that represents the state of a basketball game. Its attributes are: - The name of the first team - The name of the second team - The score of the first team - The score of the second team - The status of the game ( finished or in progress) It must have methods to: - Record one point scored for a team - Record two points scored for a team - Record three points scored for a team - change the status of the game to finished - Return the score of a team - Return the name of the team that is currently winning What i have so far: import java.util.Scanner; public class BasketballGame { Basketball game = new Basketball; public static void main (String[]args){ String team; int score; int hScore; while (team.equals("end")) { System.out.println("Enter Team and Score!"); Scanner keyboard= new Scanner(System.in); team= keyboard.next(); score= keyboard.nextInt(); if (score == 1){ hScore= game.Onepoint (team); } else if (score==2){ game.Twopoint (team); } else { game.threepoint (team); } Home= game.gethScore(); Away= game.getaScore(); string winteam= game.getWin(); } public string getwin (){ return team; } } I also have another class which i put in: public class Basketball { public String hTeam; public String aTeam; public static int hScore; public static int aScore; public void getWin(){ if (hScore>aScore){ System.out.println("Home team is winning"); } else if (hScore<aScore){ System.out.println ("Away team is winning"); } } public int getHomeScore{ return hScore; } public int getAwayScore{ return aScore; } public void Onepoint (String team){ if (team.equals(("home")){ hScore= hScore+1; } else { aScore= aScore +1; } } public void Twopoint(String team){ } public void Threepoint(String team){ } } I am thoroughly confused as to why nothing will work. Im not asking anybody to do it for me, just help plz! its due this tomorrow and im getting nowhere!!! |
|
#2
|
||||||||
|
||||||||
|
Javascript is not Java. I have requested to have this thread moved to the Java forum, so please do not make another thread.
When you post code, try to wrap it in either [ code ] [ / code ] tags, or language specific tags [ highlight = java ] [ / highlight ]. Java Code:
Java Code:
__________________
[PHP] | [Perl] | [Python] | [Java] | [Javascript] | [XML] | [ANSI C] | [C++] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS] If it wasn't for C, we'd be using BASI, PASAL and OBOL. Last edited by Winters : November 6th, 2009 at 03:56 AM. Reason: Formatting |
|
#3
|
|||
|
|||
|
Err... there are many things wrong with this code. For one, I don't think it should compile. Does it?
If not, shouldn't Code:
Basketball game = new Basketball; be in your main? Shouldn't it read: Code:
Basketball game = new Basketball(); Does your Basketball class have a constructor? Does Basketball class have a "gethScore()" method?* --> No? How about a "getHomeScore()" method? Does Basketball class have a "getaScore()" method? And that's just a start. I don't think your program would fulfill the requirements given in the outline... If you were having so much trouble writing this, wouldn't your prof be a good person to contact? ![]() I'd like to defer to the more experienced programmers, however, on how to move ahead in your programming comprehension, if they'd be so kind? *Geth Score... rofl. Geth: 0, Commander Shepard: 1864. |
|
#4
|
|||
|
|||
|
|
|
#5
|
||||
|
||||
|
Get yourself a java guide book.
Hence I said in the crossposted thread,
Get yourself a Java Reference when you code your program
__________________
When the programming world turns decent, the real world will turn upside down.
|
|
#6
|
|||||||||
|
|||||||||
|
Quote:
Im sorry, i didnt know. It was my first time using a forum and i had no idea what i was doing. I just wanted help. so it would be nice if i could get some =] |
|
#7
|
|||
|
|||
|
Quote:
yea my program doesnt compile. im trying to fix it so that it does. I had a getscore method, but the TA took it out for some reason when i went to get help |
|
#8
|
|||
|
|||
|
This is what I meant:
This is what you have in your Basketball class: Code:
public int getHomeScore {
return hScore;
}
public int getAwayScore {
return aScore;
}
but in your main, you use "gethScore()" and "getaScore()", which are not methods in "Basketball". Even though you say the program was due today, I suggest that you sit down with your TA or prof for a good while and work through this program. And go to class if you haven't been :P |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > HELP please! Java code is making me go insane |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|