Results 1 to 3 of 3
  1. #1
    swirth123 is offline Member
    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Default Help with assignment, calling methods in same class

    Hey guys, I need some help with an assignment I have for my java class. I basically need to rewrite a working program and break it down into multiple methods in order to do the same thing. The assignment I have to rewrite is bellow, if I could just get one example how to do one I can figure the rest out easily. The first part is; find the avgfee_agh (average fee of agh) in a different method and return it to the main. If someone could help I would be very very grateful. THank you

    Java Code:
    package hospital;
    import javax.swing.JOptionPane;
    public class hospital {
    	
    	public static void main(String[] args) {
    		//Declare variables
    				String patient_last, surgery_location, surgery_type, insurance_fee, surgeon_name, output="";
    				int agh_count=0, upmc_count=0;
    				double fee = 0, agh_fee = 0, upmc_fee = 0, avgfee_agh, avgfee_upmc, high_fee = 0;
    				int count_knee=0, count_hip=0;
    				String highest_surgeon="";
    				String high_patient="";
    				String high_surgeon="";
    				String high_location="";
    				String more_data = "yes";
    				int Atkins_count=0,Johnson_count=0,Smith_count=0;
    						
    				while(more_data.equals("yes"))
    				{
    					//Read the data
    					patient_last=JOptionPane.showInputDialog(null,"Enter Patient's Last Name",
    						"Input Data", JOptionPane.QUESTION_MESSAGE);
    					
    					surgery_location=JOptionPane.showInputDialog(null,"Enter the Surgery Location (AGH or UPMC)",
    						"Input Data", JOptionPane.QUESTION_MESSAGE);
    					
    					surgery_type=JOptionPane.showInputDialog(null,"Enter the Type of Surgery (knee or hip)",
    						"Input Data", JOptionPane.QUESTION_MESSAGE);
    					
    					insurance_fee=JOptionPane.showInputDialog(null,"Enter the Amount of Fee Paid By Insurance",
    							"Input Data", JOptionPane.QUESTION_MESSAGE);
    					//parse insurance fee to double
    					 fee=Double.parseDouble(insurance_fee);
    					
    					surgeon_name=JOptionPane.showInputDialog(null,"Enter the Surgeon's Name (Johnson, Atkins, or Smith)",
    							"Input Data", JOptionPane.QUESTION_MESSAGE);	
    							
    					//Count number of each type of surgery
    					if(surgery_type.equals("knee"))
    						count_knee=count_knee+1;
    					else
    						count_hip=count_hip+1;
    						
    					//Count number of surgeries at each location
    					if(surgery_location.equals("UPMC"))
    					{
    						upmc_count=upmc_count+1;
    						upmc_fee=upmc_fee+fee;
    					}
    					if(surgery_location.equals("AGH"))
    					{
    						agh_count=agh_count+1;
    						agh_fee=agh_fee+fee;				
    					}
    					
    					//Count number of surgeries each surgeon did
    					if(surgeon_name.equals("Johnson"))
    						Johnson_count=Johnson_count+1;
    					else
    					if(surgeon_name.equals("Atkins"))
    						Atkins_count=Atkins_count+1;
    					else
    						Smith_count=Smith_count+1;
    					
    					//Find surgeon with highest fee
    					if (fee>high_fee)
    					{
    						high_fee=fee;
    						high_patient=patient_last;
    						high_surgeon=surgeon_name;
    						high_location=surgery_location;
    					}
    				
    					//Ask if more data
    				 	more_data=JOptionPane.showInputDialog(null,"More Info? Enter yes or no",
    						 "Input Dialog",JOptionPane.QUESTION_MESSAGE);	
    				}//End of while loop
    				
    				//Calculate average fee for each location
    				avgfee_agh=agh_fee/agh_count;
    				avgfee_upmc=upmc_fee/upmc_count;
    						
    				//Find surgeon with most surgeries
    				if ((Johnson_count > Atkins_count)&(Johnson_count > Smith_count))
    						highest_surgeon = "Johnson";
    				else
    					if ((Atkins_count > Johnson_count)&(Atkins_count > Smith_count))
    						highest_surgeon = "Atkins";
    					else
    						highest_surgeon = "Smith";
    			
    				//Output data
    			 	output=output+"Number of Knee Surgeries: "+count_knee+"\n"; 
    				output=output+"Number of Hip Surgeries: "+count_hip+"\n"+"\n";
    				output=output+"Average Fee Paid at AGH: "+avgfee_agh+"\n";
    				output=output+"Average Fee Paid at UPMC: "+avgfee_upmc+"\n";
    				output=output+"Number of Surgeries Performed by Johnson: "+Johnson_count+"\n";
    				output=output+"Number of Surgeries Performed by Atkins: "+Atkins_count+"\n";
    				output=output+"Number of Surgeries Performed by Smith: "+Smith_count+"\n"+"\n";
    				output=output+"Doctor Who Performed the Most Surgeries: "+highest_surgeon+"\n"+"\n";
    				output=output+"Patient Whose Insurance Paid Highest Fee: "+high_patient+"\n";
    				output=output+"Doctor For Above Patient: "+high_surgeon+"\n";
    				output=output+"Location of Above Patient's Surgery: "+high_location+"\n";
    				
    				
    				//Display the output dialog box
    				JOptionPane.showMessageDialog(null,output,"Output",JOptionPane.INFORMATION_MESSAGE);
    				System.exit(0);
    				
    			
    			} //end class
    			
    	
    		} //end method
    Last edited by pbrockway2; 03-16-2013 at 04:17 AM. Reason: code tags altered

  2. #2
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: Help with assignment, calling methods in same class

    can you please explain clearly what you want exactly i didn't get you..
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default Re: Help with assignment, calling methods in same class

    Hi swirth123, welcome to the forums.

    I was going to give you the answer but though it wouldn't be right. Instead, I'll give you an alternative example:
    Java Code:
    public static void main(String[] args)
    {
        int num = 1;
        System.out.println(num*10);
    }
    An alternative using methods:
    Java Code:
    public static void main(String[] args)
    {
        int num = 1;
        num = calToMethod(num);
        System.out.println(num);
    }
    
    public static int callToMethod(int num)
    {
        return num*10;
    }
    Have a look at the link below for additional information.
    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    EDIT: I should also add the text on lines 111 and 114 are the wrong way around.

    Regards.
    Last edited by Ronin; 03-16-2013 at 08:37 PM. Reason: Adding code indents

Similar Threads

  1. Calling on other class methods?
    By carrot_spy in forum New To Java
    Replies: 1
    Last Post: 10-06-2012, 10:28 PM
  2. A class calling methods from external class
    By Aaron5466 in forum New To Java
    Replies: 4
    Last Post: 04-16-2012, 11:36 AM
  3. Replies: 16
    Last Post: 11-25-2011, 01:18 PM
  4. Calling base class methods
    By new2java2009 in forum New To Java
    Replies: 1
    Last Post: 11-15-2011, 10:47 PM
  5. Calling methods into another class? Help please!
    By javanator in forum New To Java
    Replies: 1
    Last Post: 03-20-2010, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •