CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2014
    Posts
    1

    Output is not coming

    I am having trouble with this output was wondering if someone could offer a third eye to see what I am doing wrong.

    Code:
    public class ContestantTester
    {
    
    	public static void main(String[] args)
    	{
    		Contestant contestant = new Contestant("Jon Smith");
    
    		System.out.print("Expected Name: Jon Smith------------------------------>");
    		System.out.println("Actual Name: " + contestant.getWinnings());
    
    		contestant.addWinnings(100.0);
    		contestant.addWinnings(200.0);
    
    		System.out.print("Expected Winnings: 300.0------------------------------>");
    		System.out.println("Actual Winnings: " + contestant.getWinnings());
    
    		System.out.print("Expected toString: [name=Jon Smith, winnings=$300.0]-->");
    		
    		// WHEN YOU PASS AN OBJECT REFERENCE TO PRINTLN, THE toString() METHOD
    		// FOR THE CLASS (IN THIS CASE CONTESTANT) IS AUTOMATICALLY CALLED
    		System.out.println("Actual toString: " + contestant);
    
    		contestant.bankrupt();
    		System.out.print("Expected Winnings: 0.0-------------------------------->");
    		System.out.println("Actual Winnings: " + contestant.getWinnings());
    
    		contestant.addWinnings(150.0);
    
    		System.out.print("Expected Winnings: 150.0------------------------------>");
    		System.out.println("Actual Winnings: " + contestant.getWinnings());
    
    	}
    
    }
    Here is my Class:

    Code:
    public class Contestant
    {
    	private double winnings1 = 100.00;
    	private double winnings2 = 200.00;
    	private String Contestant;
    	
    	public Contestant(String Contestant)
    	{
    		String contestant = Contestant;
    	}
    
    	public void setWinnings1(double winnings1)
    	{
    		winnings1 = 100.00; //establishing the value as 100
    	}
    	
    	public void setWinnings2(double winnings2)
    	{
    		winnings2 = 200.00; //establishing the value as 200
    	}
    	
    	public String getContestant()
    	{
    			String contestant = Contestant;
    			return contestant;
    	}
    			
    	public Object bankrupt() {
    		return null;
    	}
    
    	public String getWinnings() {
    		int getWinnings = 100;
    		getWinnings++;
    		return null;
    	}
    
    	void addWinnings(double d) {
    		
    	}
    	
    }
    The values that are coming up are NULL. What am I going wrong. I am new to this Java Programming and have done well so far but it doesn't seem like it is clicking for me at this point.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: Output is not coming

    The values that are coming up are NULL.
    Did you write the code? null is the value being returned by the methods:
    Code:
    return null;
    Change the null to the value that you want to see returned by the method.
    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured