We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

type could not be resolved

I have a java code that i don't know what is the problem. could you help me? On"Stock testStock = new Stock();" I get an error message that says " Stockcannot be resolved to a type."

import java.util.Scanner;

/**
An application class to test Stock class
*/
public class StockTesting
{
public static void main (String[] args)
    {
    //Create an object belonging to the class Stock
    Stock testStock = new Stock();
    //Declare local variables
    int inputNumberOfShares, outputNumberOfShares;
    String inputTickerSymbol, outputTickerSymbol;
    double inputDividend, outputDividend;
    double outputYearlyDividend;
    //Get input values
    Scanner scannedInfo = new Scanner(System.in);
    System.out.print("Enter numbers own, stock symbol"
    + " and dividend : ");
    System.out.flush();
    inputNumberOfShares = scannedInfo.nextInt();
    inputTickerSymbol = scannedInfo.next();
    inputDividend = scannedInfo.nextDouble();
    System.out.println();
    //Test mutator and accessor methods
    testStock.setNumberOfShares(inputNumberOfShares);
    testStock.setTickerSymbol(inputTickerSymbol);
    testStock.setDividend(inputDividend);
    outputNumberOfShares
    = testStock.getNumberOfShares ();
    outputTickerSymbol = testStock.getTickerSymbol();
    outputDividend = testStock.getDividend();
    System.out.println("Number of shares : " +
    outputNumberOfShares);
    System.out.println("Stock symbol is : " +
    outputTickerSymbol);
    System.out.println("Dividend per share is : " +
    outputDividend);
    //Test yearlyDividend method
    outputYearlyDividend = testStock.yearlyDividend();
    System.out.println("Yearly Dividend is : " +
    outputYearlyDividend);
    System.out.println();
    //Test mutator and accessor methods
    testStock.setNumberOfShares(inputNumberOfShares);
    testStock.setTickerSymbol(inputTickerSymbol);
    testStock.setDividend(inputDividend);
    outputNumberOfShares
    = testStock.getNumberOfShares ();
    outputTickerSymbol = testStock.getTickerSymbol();
    outputDividend = testStock.getDividend();
    System.out.println("Number of shares : " +
    outputNumberOfShares);
    System.out.println("Stock symbol is : " +
    outputTickerSymbol);
    System.out.println("Dividend per share is : " +
    outputDividend);
    //Test yearlyDividend method
    outputYearlyDividend = testStock.yearlyDividend();
    System.out.println("Yearly Dividend is : " +
    outputYearlyDividend);
    System.out.println(testStock.toString());
    }
}
3
Contributors
2
Replies
5 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
Ibanez1942
Newbie Poster
1 post since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The code you posted is for a class called StockTesting. Is there a class called Stock? Where is the code for that class?
ps Please post code in CODE tags, it's completely unreadable without them.

JamesCherrill
... trying to help
Moderator
8,516 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30

The reason you are getting type resolve issues is because most likely you did not create the Stock class. Here's a pregenerated one you can use from Eclipse: (You'll have to set the parameters yourself.)

public class Stock
{
	private int NumberOfShares;
	private String TickerSymbol;
	private double Dividend;
	
	public Stock()
	{
		NumberOfShares = 0;
		TickerSymbol = "none";
		Dividend = 0.0;
	}

	public void setNumberOfShares(int inputNumberOfShares)
	{
		// TODO Auto-generated method stub
		NumberOfShares = inputNumberOfShares;
	}

	public void setTickerSymbol(String inputTickerSymbol)
	{
		// TODO Auto-generated method stub
		TickerSymbol = inputTickerSymbol;
	}

	public void setDividend(double inputDividend)
	{
		// TODO Auto-generated method stub
		Dividend = inputDividend;
	}

	public int getNumberOfShares()
	{
		// TODO Auto-generated method stub
		return NumberOfShares;
	}

	public String getTickerSymbol()
	{
		// TODO Auto-generated method stub
		return TickerSymbol;
	}

	public double getDividend()
	{
		// TODO Auto-generated method stub
		return Dividend;
	}

	public double getYearlyDividend()
	{
		// TODO Auto-generated method stub
		return 0;
	}

}
Anyday
Newbie Poster
15 posts since Oct 2011
Reputation Points: 11
Solved Threads: 3
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1785 seconds using 2.72MB