Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2009, 10:36 PM
ahamza7 ahamza7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 6 ahamza7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 35 sec
Reputation Power: 0
Question HELP please! Java code is making me go insane

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!!!

Reply With Quote
  #2  
Old November 6th, 2009, 03:47 AM
Winters Winters is offline
Bad Coder
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,835 Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 11 h 39 m 44 sec
Reputation Power: 1577
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:
Original - Java Code
  1. import java.util.Scanner;
  2.  
  3. public class BasketballGame {
  4.  
  5.   Basketball game = new Basketball;
  6.   public static void main (String[]args) {
  7.     String team;
  8.     int score;
  9.     int hScore;
  10.     while (team.equals("end")) {
  11.       System.out.println("Enter Team and Score!");
  12.       Scanner keyboard = new Scanner(System.in);
  13.       team = keyboard.next();
  14.       score = keyboard.nextInt();
  15.  
  16.       if (score == 1) {
  17.         hScore = game.Onepoint (team);
  18.       }
  19.       else if (score == 2) {
  20.         game.Twopoint (team);
  21.       }
  22.       else {
  23.         game.threepoint (team);
  24.       }
  25.  
  26.       Home = game.gethScore();
  27.       Away = game.getaScore();
  28.       string winteam = game.getWin();
  29.     }
  30.  
  31.     public string getwin (){
  32.     return team;
  33.   }
  34. }
Java Code:
Original - Java Code
  1. public class Basketball {
  2. public String hTeam;
  3. public String aTeam;
  4. public static int hScore;
  5. public static int aScore;
  6.  
  7. public void getWin() {
  8.   if (hScore > aScore) {
  9.     System.out.println("Home team is winning");
  10.   }
  11.   else if (hScore < aScore) {
  12.     System.out.println ("Away team is winning");
  13.   }
  14. }
  15.  
  16. public int getHomeScore {
  17.   return hScore;
  18. }
  19.  
  20. public int getAwayScore {
  21.   return aScore;
  22. }
  23.  
  24. public void Onepoint (String team) {
  25.   if (team.equals(("home")) {
  26.     hScore = hScore+1;
  27.   }
  28.   else {
  29.     aScore = aScore +1;
  30.   }
  31. }
  32.  
  33. public void Twopoint(String team) {
  34.  
  35. }
  36.  
  37. public void Threepoint(String team) {
  38.  
  39. }
__________________
[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

Reply With Quote
  #3  
Old November 6th, 2009, 04:09 AM
Wetmelon Wetmelon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: London, ON
Posts: 67 Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 13 h 40 m 2 sec
Reputation Power: 32
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.

Reply With Quote
  #4  
Old November 6th, 2009, 04:24 AM
Winters Winters is offline
Bad Coder
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,835 Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level)Winters User rank is General 9th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 11 h 39 m 44 sec
Reputation Power: 1577
You also appear to have a strange amount of parenthesis in the following line. You will either need to add a closing parenthesis or remove an opening one.
Java Code:
Original - Java Code
  1. if (team.equals(("home")) {

Reply With Quote
  #5  
Old November 6th, 2009, 06:39 AM
tvc3mye's Avatar
tvc3mye tvc3mye is offline
Daniel Schildsky
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 949 tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level)tvc3mye User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 1 h 58 m 51 sec
Reputation Power: 542
Send a message via ICQ to tvc3mye Send a message via MSN to tvc3mye Send a message via Yahoo to tvc3mye
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.

Reply With Quote
  #6  
Old November 6th, 2009, 08:42 AM
ahamza7 ahamza7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 6 ahamza7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by Winters
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:
Original - Java Code
  1. import java.util.Scanner;
  2.  
  3. public class BasketballGame {
  4.  
  5.   Basketball game = new Basketball;
  6.   public static void main (String[]args) {
  7.     String team;
  8.     int score;
  9.     int hScore;
  10.     while (team.equals("end")) {
  11.       System.out.println("Enter Team and Score!");
  12.       Scanner keyboard = new Scanner(System.in);
  13.       team = keyboard.next();
  14.       score = keyboard.nextInt();
  15.  
  16.       if (score == 1) {
  17.         hScore = game.Onepoint (team);
  18.       }
  19.       else if (score == 2) {
  20.         game.Twopoint (team);
  21.       }
  22.       else {
  23.         game.threepoint (team);
  24.       }
  25.  
  26.       Home = game.gethScore();
  27.       Away = game.getaScore();
  28.       string winteam = game.getWin();
  29.     }
  30.  
  31.     public string getwin (){
  32.     return team;
  33.   }
  34. }
Java Code:
Original - Java Code
  1. public class Basketball {
  2. public String hTeam;
  3. public String aTeam;
  4. public static int hScore;
  5. public static int aScore;
  6.  
  7. public void getWin() {
  8.   if (hScore > aScore) {
  9.     System.out.println("Home team is winning");
  10.   }
  11.   else if (hScore < aScore) {
  12.     System.out.println ("Away team is winning");
  13.   }
  14. }
  15.  
  16. public int getHomeScore {
  17.   return hScore;
  18. }
  19.  
  20. public int getAwayScore {
  21.   return aScore;
  22. }
  23.  
  24. public void Onepoint (String team) {
  25.   if (team.equals(("home")) {
  26.     hScore = hScore+1;
  27.   }
  28.   else {
  29.     aScore = aScore +1;
  30.   }
  31. }
  32.  
  33. public void Twopoint(String team) {
  34.  
  35. }
  36.  
  37. public void Threepoint(String team) {
  38.  
  39. }



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 =]

Reply With Quote
  #7  
Old November 6th, 2009, 10:17 AM
ahamza7 ahamza7 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 6 ahamza7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by Wetmelon
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.


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

Reply With Quote
  #8  
Old November 6th, 2009, 02:18 PM
Wetmelon Wetmelon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Location: London, ON
Posts: 67 Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level)Wetmelon User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 13 h 40 m 2 sec
Reputation Power: 32
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > HELP please! Java code is making me go insane


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek