Reputation: 1
I have to create a program where I am asked to continuously ask for the date to be searched using a class called DayPrices. I have completed and figured out most of the the program and I think it will work however, when I call the function
get.Data(String[], double,double,double,double,double,double) I
I get this error in netbeans stating that ".class" expected
import java.util.Scanner;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;
import java.util.Date;
/**
*
* @author Emad Khalique
*/
public class DayPrices {
private static Scanner input = new Scanner(System.in);
private static Scanner x;
private static Formatter y;
public void openFile()
{
try
{
x = new Scanner(new File("C:/Users/Emad Khalique/Desktop/google.txt"));
}
catch (Exception e)
{
System.out.println("could not find file");
}
}
public void readFile()
{
int counter = 1;
String[] date1 = new String[24];
String[] open1 = new String[24];
String[] high1 = new String[24];
String[] low1 = new String[24];
String[] close1 = new String[24];
String[] adjclose1 = new String[24];
String[] volume1 = new String[24];
//store data into the array in a while loop that increments the counter and the array
while(x.hasNext())
{
date1[counter] = x.next();
open1[counter] = x.next();
high1[counter] = x.next();
low1[counter] = x.next();
close1[counter] = x.next();
adjclose1[counter] = x.next();
volume1[counter] = x.next();
// create a function that only prints form the specefied array. to search create a system where it checks for the specefic date
counter++;
}
//convert the array of strings to their corresponding demand of type
double Open = Double.parseDouble(open1[counter]);
double High = Double.parseDouble(high1[counter]);
double Low = Double.parseDouble(low1[counter]);
double Close = Double.parseDouble(close1[counter]);
double AdjClose = Double.parseDouble(adjclose1[counter]);
double Volume = Double.parseDouble(volume1[counter]);
}
//while loop of function for a function that continuously asks for the next date and displays the corresponding counter#
//a system to configure the methods of search
public void getData(String date1[], double Open, double High, double Low, double Close, double AdjClose, double Volume)
{
int counter = 0;
Scanner input = new Scanner(System.in);
String datefinder;
System.out.println("Please enter a date to search");
datefinder = input.nextLine();
while (datefinder != date1[counter])
{
while(datefinder != date1[counter])
{
counter++;
}
System.out.println(date1[counter]);
counter++;
}
}
public void closeFile()
{
x.close();
}
}
import com.sun.org.apache.xpath.internal.operations.String;
import java.util.Scanner;
import java.lang.*;
import java.util.*;
import java.io.*;
/** * * @author Emad Khalique */ public class CST1201 {
public static void main(String[] args){
DayPrices pricesCall = new DayPrices ();
int runAgain = 1;
while(runAgain == 1) //create a method to increment runAgain variable
{
Scanner input = new Scanner(System.in);
DayPrices prices = new DayPrices();
prices.openFile();
prices.readFile();
while(runAgain == 1){
//saidfunction that will get the data
prices.getData(String[], double, double, double, double, double, double);
}
prices.closeFile();
System.out.println("Would you like to continue? ");
runAgain = input.nextInt();
}
}
}
Upvotes: 0
Views: 323
Reputation: 50899
You can't invoke a method with type parameters, you need to send an actual value.
prices.getData(new String[3], 3.4, 17, 5.5, ...);
If you want the values from readFile()
, one option is to move the variables to the class scope and create getters for them to access in main
public class DayPrices {
private double open;
private double high;
private double low;
// more variables
public getOpen() {
return open;
}
// more getters
public void readFile() {
open = Double.parseDouble(open1[counter]);
high = Double.parseDouble(high1[counter]);
low = Double.parseDouble(low1[counter]);
//...
}
}
And in main
prices.getData(prices.getData1(), prices.getOpen(), ...);
As a side note, variables in Java should start with lowercase.
Upvotes: 1
Reputation: 739
I think you should not send 'String[]' because compiler thinks that you are passing class-type so you can pass a 'string[]' variable in prices.getData() function simply.
Upvotes: 0