1.11M Members

type could not be resolved

 
0
 

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());
    }
}
 
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.

 
0
 

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;
	}

}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: