Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: BASIC program help

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default BASIC program help

    I`m Having some trouble with some extremely basic Java code for school. For the assignment we have to write code that will ask questions then spit the responses out. My variables are null and the stadium part runs into the year part. The are problems with the return part too.
    Help would be appreciated. Thanks.

    import static java.lang.System.out;
    import java.util.Scanner;
     
    class team{
    	private String sport;
    	private String city;
    	private String name;
    	private String stadium;
    	private String year;
    	private String player;
     
    	public void setsport (String sportIn) {
    		out.print("What sport does the team play: ");
    		sportIn = sport;
    	}
     
    	public void setcity (String cityIn) {
    		out.print("What city does the team play in: ");
    		cityIn = city;
    	}
     
    	public void setname (String nameIn) {
    		out.print("What's your teams name: ");
    		nameIn = name;
    	}
     
    	public void setstadium (String stadiumIn) {
    		out.print("What's" + name + "Stadium");
    		stadiumIn = stadium;
    	}
     
    	public void setyear (String yearIn) {
    		out.print("What year was" + name + "established: ");
    		yearIn = year;
    	}
     
    	public void setplayer (String playerIn) {
    		out.print("Who's" + name + "best player: ");
    		playerIn = player;
    	}
    	private String info = (name + "play" + sport + "in" + city + "." + name + "were founded in" + year + "." + name + "best playert is" + player + ".");
    	public String getinfo () {
    		return info;
     
    	}
    }

    import java.util.Scanner;
     
    class assembly {
    	public static void main (String args[]) {
     
    	team a = new team();
    	Scanner scannera = new Scanner (System.in);
     
    	a.setsport (scannera.next());
    	a.setcity (scannera.next());
    	a.setname (scannera.next());
    	a.setstadium(scannera.next());
    	a.setyear(scannera.next());
    	a.setplayer(scannera.next());
    	a.getinfo();
    	}
     
     
    }


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: BASIC program help

    sportIn = sport;
    Check assignment. value from the right side of assigning operator is assigned to the left side variable.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: BASIC program help

    Also you need to understand when a statement is executed.
    private String info = (name + "play" + sport ...
    When will this assignment statement be executed? What are the values of the variables to the right of the = WHEN it is executed?

  4. The Following User Says Thank You to Norm For This Useful Post:

    qwerty53 (December 16th, 2011)

Similar Threads

  1. Need basic String help
    By Sadalmelik in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2011, 06:05 AM
  2. Very basic program but its making me crazy
    By craig carl in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 2nd, 2011, 03:16 PM
  3. Not sure what to do next (Basic java program)
    By desi22601 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 21st, 2010, 09:05 AM
  4. Basic program which gets cost, adds tax, gets payment then calculates change.
    By bibboorton in forum What's Wrong With My Code?
    Replies: 6
    Last Post: August 25th, 2010, 10:31 AM
  5. Basic Java Program Help
    By roaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2009, 10:28 PM