invalid method declaration; return type requred

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1079 Views - Last Post: 18 April 2010 - 06:13 PM Rate Topic: -----

#1 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

invalid method declaration; return type requred

Posted 16 April 2010 - 01:39 PM

i get that erro in lines 25 and 69
what i am trying to do is get the int quest from the Doer class to the Save and Check class

import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
	protected int quest;      
    public void Stuff () {
       	quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
   	}
   	public int getQuest(){
   		return quest;
   	}                               
}
class Save extends Doer {
	DecimalFormat df = new DecimalFormat ("0.00");	
	private String pen;
	private double b;
	private double quest1;
	private double withdraw, withdraw1, date1;
	private ArrayList withdrawArray, date;
	private ArrayList penalties;
	public SaveC(){
		super();
	}	
	public void Save (){
		if (quest == 1) {
			do {
				quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
				if (quest1 == 1){	
					date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
		            withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
					withdraw ++;
		            date.add (date1);
		            if (withdraw > 3) {
		            	JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
		            	pen = "$1.00";
		            	penalties.add (pen);
		       		}
		       		else if (withdraw <= 3) {
		       			pen = " ";
		       			penalties.add (pen);
		       		}	
		 	    	withdrawArray.add (withdraw1);
				}
				else if (quest1 == 2){
					System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
					for (int a = 0; a < (withdraw + check); a ++){
	    			b ++;
	    			System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
	    			}
	    			b = 0;				
				}	
			} while ((quest1 == 1) || (quest1 == 2));
			System.out.println("GAME OVER");
		}
	}
}
class Check extends Doer {	
	DecimalFormat df = new DecimalFormat ("0.00");
	private String pen;
	private double b;
	private double quest1;
	private double check, check1, date1;
	private ArrayList checkArray, date;
	private ArrayList penalties;		
	public CheckC(){
		super();
	}
	public void Check (){
		if (quest == 2) {
			quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
			do{
				if (quest1 == 1){
					date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
		       		check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
		       		check ++;
		       		date.add(date1);
		       		if (check < 20) {
		       			JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
		       			pen = "$.50";
		       			penalties.add (pen);
		       		}
		       		else if (check >= 20) {
		       			pen = " ";
		       			penalties.add (pen);
		       		}
		       		checkArray.add(check1);
				}
				System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
	    		for (int a = 0; a < (withdraw + check); a ++){
	    			b ++;
	    			System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
	    		}
	    		b = 0;
			}
			while ((quest1 == 1) || (quest1 == 2));
    		System.out.println("GAME OVER");	
		}
	}
}
class ch13num8 {         
    public static void main ( String [] args ) {              
        Doer quest;                      
    	quest = new Doer(); 
    	quest.Stuff();             
    	System.exit(0);           
    } 
}



Is This A Good Question/Topic? 0
  • +

Replies To: invalid method declaration; return type requred

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: invalid method declaration; return type requred

Posted 16 April 2010 - 02:51 PM

Firstly, you were told in an earlier post that having the method name the same as a class name is really bad (as in conventions). Change this for your own sake. Secondly, your constructor differes from your class name. Your constructor must have the exact same name as your class. So, for instance, you have a class Save, but your constructor is SaveC
public SaveC(){
                super();
        }  

Was This Post Helpful? 1
  • +
  • -

#3 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 04:38 PM

okay i changed the class name and made the constructor the same as the method but i still get the same errors

but now in lines 23 and 67
import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
        protected int quest;      
    public void Stuff () {
        quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
        }
        public int getQuest(){
                return quest;
        }                               
}
class SaveC extends Doer {
        DecimalFormat df = new DecimalFormat ("0.00");  
        private String pen;
        private double b;
        private double quest1;
        private double withdraw, withdraw1, date1;
        private ArrayList withdrawArray, date;
        private ArrayList penalties;
        public Save(){
                super();
        }       
        public void Save (){
                if (quest == 1) {
                        do {
                                quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
                                if (quest1 == 1){       
                                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                            withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
                                        withdraw ++;
                            date.add (date1);
                            if (withdraw > 3) {
                                JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
                                pen = "$1.00";
                                penalties.add (pen);
                                }
                                else if (withdraw <= 3) {
                                        pen = " ";
                                        penalties.add (pen);
                                }       
                                withdrawArray.add (withdraw1);
                                }
                                else if (quest1 == 2){
                                        System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
                                        for (int a = 0; a < (withdraw + check); a ++){
                                b ++;
                                System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
                                }
                                b = 0;                          
                                }       
                        } while ((quest1 == 1) || (quest1 == 2));
                        System.out.println("GAME OVER");
                }
        }
}
class CheckC extends Doer {      
        DecimalFormat df = new DecimalFormat ("0.00");
        private String pen;
        private double b;
        private double quest1;
        private double check, check1, date1;
        private ArrayList checkArray, date;
        private ArrayList penalties;            
        public Check(){
                super();
        }
        public void Check (){
                if (quest == 2) {
                        quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
                        do{
                                if (quest1 == 1){
                                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                                check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
                                check ++;
                                date.add(date1);
                                if (check < 20) {
                                        JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
                                        pen = "$.50";
                                        penalties.add (pen);
                                }
                                else if (check >= 20) {
                                        pen = " ";
                                        penalties.add (pen);
                                }
                                checkArray.add(check1);
                                }
                                System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
                        for (int a = 0; a < (withdraw + check); a ++){
                                b ++;
                                System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
                        }
                        b = 0;
                        }
                        while ((quest1 == 1) || (quest1 == 2));
                System.out.println("GAME OVER");        
                }
        }
}
class ch13num8 {         
    public static void main ( String [] args ) {              
        Doer quest;                      
        quest = new Doer(); 
        quest.Stuff();             
        System.exit(0);           
    } 
}


This post has been edited by Nameo0: 18 April 2010 - 04:38 PM

Was This Post Helpful? 0
  • +
  • -

#4 nano-gilmour  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 39
  • Joined: 07-February 10

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 04:46 PM

You have to name the constructor by the class name.
so at line 23 change Save to SaveC, and at line 67 change Check to CheckC.
hope this helps.
Was This Post Helpful? 0
  • +
  • -

#5 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 04:59 PM

okay it builds and runs partially
when i build/run it i get

Quote

Note: C:\Users\Nameo0\Documents\JCreator LE\MyProjects\ch13num8\ch13num8.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

and when i run it it only goes through the doer class and then ends the program

import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
        protected int quest;      
    public void Stuff () {
        quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
        }
        public int getQuest(){
                return quest;
        }                               
}
class SaveC extends Doer {
        DecimalFormat df = new DecimalFormat ("0.00");  
        private String pen;
        private double b;
        private double quest1;
        private double withdraw, withdraw1, date1;
        private ArrayList withdrawArray, date;
        private ArrayList penalties;
        public SaveC(){
            super();
        }       
        public void Save (){
        	if (quest == 1) {
            	do {
                	quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
                    	if (quest1 == 1){       
                            date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                            withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
                            withdraw ++;
                            date.add (date1);
                            if (withdraw > 3) {
                                JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
                                pen = "$1.00";
                                penalties.add (pen);
                                }
                                else if (withdraw <= 3) {
                                        pen = " ";
                                        penalties.add (pen);
                                }       
                                withdrawArray.add (withdraw1);
                                }
                                else if (quest1 == 2){
                                	System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
                                    for (int a = 0; a < withdraw; a ++){
                                		b ++;
                                		System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
                                	}
                                b = 0;                          
                                }       
                        } 
                        while ((quest1 == 1) || (quest1 == 2));
                        System.out.println("GAME OVER");
                }
        }
}
class CheckC extends Doer {      
        DecimalFormat df = new DecimalFormat ("0.00");
        private String pen;
        private double b;
        private double quest1;
        private double check, check1, date1;
        private ArrayList checkArray, date;
        private ArrayList penalties;            
        public CheckC(){
                super();
        }
        public void Check (){
                if (quest == 2) {
                        quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
                        do{
                                if (quest1 == 1){
                                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                                check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
                                check ++;
                                date.add(date1);
                                if (check < 20) {
                                        JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
                                        pen = "$.50";
                                        penalties.add (pen);
                                }
                                else if (check >= 20) {
                                        pen = " ";
                                        penalties.add (pen);
                                }
                                checkArray.add(check1);
                                }
                                System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
                        for (int a = 0; a < check; a ++){
                                b ++;
                                System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
                        }
                        b = 0;
                        }
                        while ((quest1 == 1) || (quest1 == 2));
                System.out.println("GAME OVER");        
                }
        }
}
class ch13num8 {         
    public static void main ( String [] args ) {              
        Doer quest;                      
        quest = new Doer(); 
        quest.Stuff();             
        System.exit(0);           
    } 
}


Was This Post Helpful? 0
  • +
  • -

#6 nano-gilmour  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 39
  • Joined: 07-February 10

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:04 PM

well, you should make a constructor for the Doer class and if you implemented public void Stuff () to be the constructor you should change it to : public Doer.
hope this helps.
Was This Post Helpful? 0
  • +
  • -

#7 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:10 PM

i changed it to this:
not usre if its right
class Doer {        
    protected int quest; 
    	public Doer(){
    	}     
    public void Stuff () {
        quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
        }
        public int getQuest(){
                return quest;
        }                               
}


but i still get the same two notes
and it did not change any problems
Was This Post Helpful? 0
  • +
  • -

#8 nano-gilmour  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 39
  • Joined: 07-February 10

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:20 PM

well, in your maim method in class ch13num8 you instantiated Doer only.
I ran over your code quickly and i guess you need to instantiate a SaveC and a CheckC then if the user input was 1 save method from SaveC class should run and if the user input was 2 check method from CheckC class should run.
hope that was helpful.
Was This Post Helpful? 0
  • +
  • -

#9 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:29 PM

so i would iniciate checkc and savec in the main class also?
Was This Post Helpful? 0
  • +
  • -

#10 nano-gilmour  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 39
  • Joined: 07-February 10

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:34 PM

View PostNameo0, on 18 April 2010 - 04:29 PM, said:

so i would iniciate checkc and savec in the main class also?

Sure as they will not create themselves :D
Was This Post Helpful? 0
  • +
  • -

#11 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:46 PM

You wouldnt instantiate them ASWELL You would instantiate them only. These classes inherit all members and attributes of class Doer. This means instantiate the subclass to have access to the super class. Browsing through your code, i dont even see why you need inheritance here anyway. Its good to use inheritence, but you need to understand why you use it.

That other issue you get is a warning. Not really good to get it, normally means your doing something dodgy. However, if you do get it, you can just ignore it. It shouldnt effect anything.
Was This Post Helpful? 0
  • +
  • -

#12 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:49 PM

still getting the same problems
new code:
import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
    protected int quest; 
    public Doer(){
    }     
    public void Stuff () {
    	quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
    }    
    public int getQuest(){
    	return quest;
    }                               
}
class SaveC extends Doer {
    DecimalFormat df = new DecimalFormat ("0.00");  
    private String pen;
    private double b;
    private double quest1;
    private double withdraw, withdraw1, date1;
    private ArrayList withdrawArray, date;
    private ArrayList penalties;
    public SaveC(){
        super();
    }       
    public void Save (){
    	if (quest == 1) {
        	do {
            	quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
                	if (quest1 == 1){       
                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                        withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
                        withdraw ++;
                        date.add (date1);
                        if (withdraw > 3) {
                            JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
                            pen = "$1.00";
                            penalties.add (pen);
                            }
                        else if (withdraw <= 3) {
                                pen = " ";
                                penalties.add (pen);
                        }       
                        withdrawArray.add (withdraw1);
            		}
            		else if (quest1 == 2){
            			System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
                		for (int a = 0; a < withdraw; a ++){
            				b ++;
            				System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
            			}
                		b = 0;                          
                }       
            } 
            while ((quest1 == 1) || (quest1 == 2));
            System.out.println("GAME OVER");
        }
    }
}
class CheckC extends Doer {      
        DecimalFormat df = new DecimalFormat ("0.00");
        private String pen;
        private double b;
        private double quest01;
        private double check, check1, date1;
        private ArrayList checkArray, date;
        private ArrayList penalties;            
        public CheckC(){
                super();
        }
        public void Check (){
        	if (quest == 2) {
                quest01 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
                do{
                	if (quest01 == 1){
                    	date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                        check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
                        check ++;
                        date.add(date1);
                        if (check < 20) {
                        	JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
                            pen = "$.50";
                            penalties.add (pen);
                        }
                        else if (check >= 20) {
                            pen = " ";
                            penalties.add (pen);
                    	}
                        checkArray.add(check1);
					}
                    System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
                    for (int a = 0; a < check; a ++){
                        b ++;
                        System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
                }
            b = 0;
            }
            while ((quest01 == 1) || (quest01 == 2));
    		System.out.println("GAME OVER");        
    	}
    }
}
class ch13num8 {         
    public static void main ( String [] args ) {              
        Doer quest;                      
        quest = new Doer(); 
        quest.Stuff();
        SaveC quest1;
        quest1 = new SaveC();
        quest1.Save();
        CheckC quest01;
        quest01 = new CheckC();
        quest01.Check();             
        System.exit(0);           
    } 
}


Was This Post Helpful? 0
  • +
  • -

#13 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:54 PM

If you are referring to a deprecation warning, then it is because you do not parameterize the ArrayList, or declare the generic type of the elements for the List to store. So if you want to store ints, declare an ArrayList<Integer>; for Strings, declare an ArrayList<String>, etc.
private ArrayList withdrawArray, date; 
private ArrayList penalties; 



@nick2price: A deprecation warning means that you are using something that has been decomissioned. There is a reason for this- usually it is b/c of poor practice/better tools (in this case with Generics) or faulty code.

This post has been edited by macosxnerd101: 18 April 2010 - 05:57 PM

Was This Post Helpful? 1
  • +
  • -

#14 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:57 PM

okay, assigning types to the arraylists helped with the note problem, but when my program is run it only does the Doer class and then finishes the program
import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
    protected int quest; 
    public Doer(){
    }     
    public void Stuff () {
    	quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
    }    
    public int getQuest(){
    	return quest;
    }                               
}
class SaveC extends Doer {
    DecimalFormat df = new DecimalFormat ("0.00");  
    private String pen;
    private double b;
    private double quest1;
    private double withdraw, withdraw1, date1;
    private ArrayList <Double>withdrawArray, date;
    private ArrayList <String>penalties;
    public SaveC(){
        super();
    }       
    public void Save (){
    	if (quest == 1) {
        	do {
            	quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
                	if (quest1 == 1){       
                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                        withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
                        withdraw ++;
                        date.add (date1);
                        if (withdraw > 3) {
                            JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
                            pen = "$1.00";
                            penalties.add (pen);
                            }
                        else if (withdraw <= 3) {
                                pen = " ";
                                penalties.add (pen);
                        }       
                        withdrawArray.add (withdraw1);
            		}
            		else if (quest1 == 2){
            			System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
                		for (int a = 0; a < withdraw; a ++){
            				b ++;
            				System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
            			}
                		b = 0;                          
                }       
            } 
            while ((quest1 == 1) || (quest1 == 2));
            System.out.println("GAME OVER");
        }
    }
}
class CheckC extends Doer {      
        DecimalFormat df = new DecimalFormat ("0.00");
        private String pen;
        private double b;
        private double quest01;
        private double check, check1, date1;
        private ArrayList <Double>checkArray, date;
        private ArrayList <String>penalties;            
        public CheckC(){
                super();
        }
        public void Check (){
        	if (quest == 2) {
                quest01 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
                do{
                	if (quest01 == 1){
                    	date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                        check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
                        check ++;
                        date.add(date1);
                        if (check < 20) {
                        	JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
                            pen = "$.50";
                            penalties.add (pen);
                        }
                        else if (check >= 20) {
                            pen = " ";
                            penalties.add (pen);
                    	}
                        checkArray.add(check1);
					}
                    System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
                    for (int a = 0; a < check; a ++){
                        b ++;
                        System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
                }
            b = 0;
            }
            while ((quest01 == 1) || (quest01 == 2));
    		System.out.println("GAME OVER");        
    	}
    }
}
class ch13num8 {         
    public static void main ( String [] args ) {              
        Doer quest;                      
        quest = new Doer(); 
        quest.Stuff();
        SaveC quest1;
        quest1 = new SaveC();
        quest1.Save();
        CheckC quest01;
        quest01 = new CheckC();
        quest01.Check();             
        System.exit(0);           
    } 
}


Was This Post Helpful? 0
  • +
  • -

#15 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: invalid method declaration; return type requred

Posted 18 April 2010 - 05:59 PM

As I say, i think you need to try and learn about inheritence a bit better. Checking your quest variable within each class was not really a viable solution, otherwise you would have no real control over what gets called in main. So I made a few changes, and now it works. Do as macosxnerd says to get rid of the warning. Check this code out and see how it differs from yours.
import java.text.*; 
import javax.swing.*; 
import java.lang.*; 
import java.util.*;

class Doer {        
        protected int quest;      
    public void Stuff () {
        quest = Integer.parseInt(JOptionPane.showInputDialog (null, "What would you like to do?\n1) Access Checking\n2) Access Savings"));
        }
        public int getQuest(){
                return quest;
        }                               
}
class SaveC extends Doer {
        DecimalFormat df = new DecimalFormat ("0.00");  
        private String pen;
        private double b;
        private double quest1;
        private double withdraw, withdraw1, date1;
        private ArrayList withdrawArray, date;
        private ArrayList penalties;
        public SaveC(){
            super();
        }       
        public void Save (){
                do {
                        quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Withdraw\n2) View Transation History\n3) Do Nothing"));
                        if (quest1 == 1){       
                            date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                            withdraw1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much do you want to withdraw?"));
                            withdraw ++;
                            date.add (date1);
                            if (withdraw > 3) {
                                JOptionPane.showMessageDialog (null, "You have gone over your three monthly withdrawal limit and therefore you have incured a $1 fee.");
                                pen = "$1.00";
                                penalties.add (pen);
                                }
                                else if (withdraw <= 3) {
                                        pen = " ";
                                        penalties.add (pen);
                                }       
                                withdrawArray.add (withdraw1);
                                }
                                else if (quest1 == 2){
                                        System.out.println ("Number\t\tDate\t\tWithdraws\t\tPenalties");
                                    for (int a = 0; a < withdraw; a ++){
                                                b ++;
                                                System.out.println (b + ")\t\t\t"  +  date.get(a) +  "\t\t\t$" + df.format(withdrawArray.get(a)) + "\t\t\t" +penalties.get(a));
                                        }
                                b = 0;                          
                                }       
                        } 
                        while ((quest1 == 1) || (quest1 == 2));
                        System.out.println("GAME OVER");
                
        }
}
class CheckC extends Doer {      
        DecimalFormat df = new DecimalFormat ("0.00");
        private String pen;
        private double b;
        private double quest1;
        private double check, check1, date1;
        private ArrayList checkArray, date;
        private ArrayList penalties;            
        public CheckC(){
                super();
        }
        public void Check (){
                        quest1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What would you like to do?\n1) Write A Check\n2) View Transation History\n3) Do Nothing"));
                        do{
                                if (quest1 == 1){
                                        date1 = Double.parseDouble (JOptionPane.showInputDialog (null, "What is today's date?\nPlease follow the example to enter the date.\nEX. Date: January 13, 1997\n  Enter: 01131997"));
                                check1 = Double.parseDouble (JOptionPane.showInputDialog (null, "How much did you write on the check?"));
                                check ++;
                                date.add(date1);
                                if (check < 20) {
                                        JOptionPane.showMessageDialog (null, "You have been charged $.50 and you will be charged this amount for the next " + (20 - check ) + " times.");
                                        pen = "$.50";
                                        penalties.add (pen);
                                }
                                else if (check >= 20) {
                                        pen = " ";
                                        penalties.add (pen);
                                }
                                checkArray.add(check1);
                                }
                                System.out.println ("Number\t\tDate\t\tChecks\t\tPenalties");
                        for (int a = 0; a < check; a ++){
                                b ++;
                                System.out.println (b + ")\t\t\t" + date.get(a) + "\t\t\t$" + df.format(checkArray.get(a)) + "\t\t\t" +penalties.get(a));
                        }
                        b = 0;
                        }
                        while ((quest1 == 1) || (quest1 == 2));
                System.out.println("GAME OVER");        
                
        }
}
class ch13num8 {         
    public static void main ( String [] args ) {              
       
        SaveC s = new SaveC();
        CheckC c = new CheckC();
        s.Stuff();    
        if(s.getQuest()==1){
        c.Check(); 
        }else{
        s.Save();   
        }
        System.exit(0);           
    } 
}


This post has been edited by nick2price: 18 April 2010 - 06:02 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2