Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Java Program


  • Please log in to reply

#1
BobboJC

BobboJC

    New Member

  • Member
  • Pip
  • 2 posts
I'm working on a Program for my computer class. I understand what is going on, but have a hard time writing my own code. The requirements for this program are found at http://149.149.136.7...10programs.html and Program Number 1. I understand what I am supposed to do, but am having an extremely hard time implementing it. I do not want a hand-out as that will not help me in the end, but some guidance would be appreciated. I've been working on it for an hour and here is what I have at this point:

//*************************************************************************
// Secant.java Author: Robert Young
//
//
//*************************************************************************

public class Secant
{

public static void main (String[] args)
{
string temp;
string filename;

temp=getInput("Would you like to specify your polynomial with a file (y or n)? ");

if (temp=y)
{
filename=getInput("Enter the file name: ");
}
}

public static double secant(Poly poly, double x0, double x1, int iter) //returns the result of the secant method
{

}

public static Poly getPoly(int degree) //user inputs the coefficients of the powers of x from 0 to degree
{
return Keyboard.readInt(prompt);
}

public static String displayPoly(Poly poly) //displays the polynomial (nonzero coeffs only)
{

}
}

It is definately not much and much may not be correct. My AIM name is bjy562 and MSN is [email protected]. Again, I do not want a hand-out, but some help. It would be greatly appreciated.
  • 0

Advertisements


#2
destin

destin

    Member

  • Member
  • PipPip
  • 53 posts

if (temp=y)
{
filename=getInput("Enter the file name: ");
}

This will not work. First of all, the = operator is an assignment operator. It will pass a reference of y to temp. Then, y isn't a variable, so you'll get an error. Also, you'll get an error even if y was declared, because conditionals resolve to boolean values; temp=y does not resolve to a boolean value. You need to change that to:
if (temp.equals("y")) {
	filename = getInput("Enter the file name: ");
}
Assuming that getInput(String) is declared in your class.

Another thing... you cannot create a string with string because string is not a class. String is.

import java.util.Scanner;

public class Secant {
	/** for user input */
	static private Scanner scanner = new Scanner(System.in);
	
	/** main entry point of the program */
	static public void main(String[] args) {
		/** prompt user to see whether they would like to read from a file or not */
		System.out.print("Would you like to specify your polynomial with a file (y or n)? ");
		
		/** take the first character of the user's response, if it equals 'y', then wantsFile will be true */
		boolean wantsFile = (scanner.next().charAt(0) == 'y');
		
		if (wantsFile) {
			/** prompt user for file name */
			System.out.print("Enter the file name: ");
			
			/** create a file out of the user's input (which will be the path of the file) */
			File file = new File(scanner.next());
		}
	}
	
	/**
	 * @param poly  the polynomial to use
	 * @param x0	starting function value for root finding
	 * @param x1	starting function value for root finding
	 * @param iter  the number of times to iterate
	 */
	static public double secant(Poly poly, double x0, double x1, int iter) {
	}
	
	// etc...
}

I'm not exactly sure on what your stuck with. Please be more specific.

Hope this helps.

Edited by destin, 12 February 2006 - 10:42 PM.

  • 0

#3
BobboJC

BobboJC

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Hi Destin,

Thank you for the reply, it is helpful. Our prof makes us use a class called Keyboard instead of the Scanner class. Hence the return Keyboard.readDouble(prompt). The program is due tomorrow, and I've just hit a wall. I will continue to work on it in the morning, but again, thank you for your help.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP