5 Replies - 1632 Views - Last Post: 14 October 2005 - 08:25 PM Rate Topic: -----

#1 cap10kid3  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 36
  • Joined: 16-August 05

wwhy wont this code work?

Posted 14 October 2005 - 12:32 PM

what is wrong with this program?
import java.io.*;//imports the keyboard function


public class GcF
{
	char a,x,y,z;
	public static void main(String[] args)
	{
  FileOutputStream out;
  PrintStream p;
  try
 	 {
    out = new FileOutputStream("horay.txt");
    p = new PrintStream(out);
 	 }
  catch (NullPointerException e)
 	 { 
 	 System.out.println("Stop trying to kill my programs!\n");
 	 }
 	 
  try
 	 {
    System.out.println("Program #2 \nThe GCF Game \nBy: Thomas Boeckman\n\n");//header
    Playgame();
 	 }
 	 catch (NullPointerException e)// stops most errors from showing
 	 {
    System.out.println("Hanosh! stop trying to sabatoge my programs!");
    Playgame();
 	 }
	}
	public static void Playgame() throws IOException
	{
  try
  {
 	 String YesorNo;
 	 BufferedReader keyboard;
 	 boolean loopNeeded;// creates a loop
 	 
 	 keyboard = new BufferedReader(new InputStreamReader(System.in));//takes input from the keyboard
 	 
 	 System.out.println ("Would you like to play the GCF game?\n Please type Yes or No and press Enter");
 	 YesorNo = keyboard.readLine();// assigns the entered string tothe variable YesorNo
 	 
 	 
 	 if (YesorNo.equalsIgnoreCase("yes"))
 	 gcfNumbers();//sends the program to gcfNumbers
 	 else if (YesorNo.equalsIgnoreCase("no"))
 	 {
    System.out.println("Thanks for playing the GCF game!");
    System.exit(1);// ends the program
 	 }
 	 else 
 	 {
    System.out.println("Oh wizened old fart, please type Yes or No and press Enter");
    Playgame();// repeats
 	 }
  }
  catch   (NullPointerException e)
  {
 	 System.out.println("Oh Inferior One, why must you try to spoil my programs?");
 	 Playgame();
  }
	}
	public static void gcfNumbers()
	{
  try	
 	 {
    Scanner sc = new Scanner(System.in);
       	 int i = sc.nextInt();

    
    if (a == 2)
    {
      twoNumGCF();
   	 }
    else if (a == 3)
   	 {
      threeNumGCF();
   	 }
   	 else 
   	 {
      System.out.println("What are you doing?\n What is so hard about typing a 2 or a 3, I mean, come on!"); 
      gcfNumbers();
   	 }
 	 }
   
   catch (NullPointerException e)
   {
    System.out.println("Why must you bother me so, Hanosh?\n");
    }
  
	};
}


-code box edited in by supersloth

This post has been edited by supersloth: 14 October 2005 - 01:06 PM


Is This A Good Question/Topic? 0
  • +

Replies To: wwhy wont this code work?

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4478
  • View blog
  • Posts: 28,394
  • Joined: 21-March 01

Re: wwhy wont this code work?

Posted 14 October 2005 - 01:07 PM

what is it doing? what should it be doing?
Was This Post Helpful? 0
  • +
  • -

#3 cap10kid3  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 36
  • Joined: 16-August 05

Re: wwhy wont this code work?

Posted 14 October 2005 - 01:13 PM

it is supposed to determint the Greatest commonm factor from thge selection of 2 or 3 numbers, the program is not finished yet, but it wont compile at all. any help would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4478
  • View blog
  • Posts: 28,394
  • Joined: 21-March 01

Re: wwhy wont this code work?

Posted 14 October 2005 - 01:15 PM

compilers tend to give you errors when they don't compile something. what error are you getting?
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: wwhy wont this code work?

Posted 14 October 2005 - 04:12 PM

First thing that comes to mind is the Scanner class...you are not including the correct class library...you need to
import java.util.*;


I can check the rest later...
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: wwhy wont this code work?

Posted 14 October 2005 - 08:25 PM

Some of the other reasons for errors:

1. Class GcF is public...ensure be declared in a file called GcF.java

2. You're probably getting two more errors becasue you are calling twoNumGCF() and threeNumGCF(), but they have not been defined anywhere.

3. I would further expect that you are getting an error in you if statements when comparing variable a...
if(a==2)


In that section of the code, you are using the Scanner class to assign a value to a variable named i...that should likely be a.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1