Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help with my assignment please!!! (Novice User)

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with my assignment please!!! (Novice User)

    Hey guys, as I've stated in other questions; I am taking a java class for college and its taught online and I dont get very much "instruction" at all. Its more of a figure it out on your own kind of class. My problem is I'm rather confused about how to execute my assignment. I think there is a way to insert values to String data in order to do calculations with them. I will post the actual assignment itself as well as what I have so far. I think I'm on my way down the wrong path. What I'm struggling with is when I have to input String data and then find averages of the Inputs from the dialog box. If anyone could please help me get on the right path in order to be able to output the information needed I would be greatly appreciative! I'm not looking for an assignment to copy and paste and turn in! I just need some guidance! It is supposed to be an assignment on how to use loops. Code and Assignment as follows.

    This assignment is for 5 different medical patients.

    Type of data
    • Age of the patient Integer
    • Gender of the patient String (M or F)
    • Location of surgery String(S for surgery center or H for hospital)
    • Insurance payment Double
    • Name of the patient’s Doctor String (last name only)

    You are then to do the following:

    • Print the number of males and the average age of the males
    • Print the number of females and the average age of the females
    • Print the average insurance payment for all surgeries at the surgery center
    • Print the average insurance payment for all surgeries at the hospital
    • Print the average insurance payment for all surgeries
    • Print the name of the Doctor who received the highest insurance payment and what that payment
    amount was




    Here is what I have so far, (I realize I have unneeded variables):

    package Assignment3;
    import javax.swing.JOptionPane;
    public class Assignment3 {
     
    	public static void main(String[] args) {
     
    		//Variables
    		String gen1, gen2, gen3, gen4, gen5;
    		int age1, age2, age3, age4, age5;
    		String loc1, loc2, loc3, loc4, loc5;
    		double ins1, ins2, ins3, ins4, ins5;
    		String avalue, gvalue, Ivalue;
    		String pat1, pat2, pat3, pat4, pat5;
    		String doc1, doc2, doc3, doc4, doc5;
     
    		//Patient Name Dialog Boxes
    		pat1 = JOptionPane.showInputDialog(null,"Enter 1st Patients Name: ", "Name", JOptionPane.QUESTION_MESSAGE);
    		pat2 = JOptionPane.showInputDialog(null,"Enter 2nd Patients Name: ","Name", JOptionPane.QUESTION_MESSAGE);
    		pat3 = JOptionPane.showInputDialog(null,"Enter 3rd Patients Name: ","Name", JOptionPane.QUESTION_MESSAGE);
    		pat4 = JOptionPane.showInputDialog(null,"Enter 4th Patients Name: ","Name", JOptionPane.QUESTION_MESSAGE);
    		pat5 = JOptionPane.showInputDialog(null,"Enter 5th Patients Name: ","Name", JOptionPane.QUESTION_MESSAGE);
     
    		//Age Dialog Boxes
    		avalue = JOptionPane.showInputDialog(null,"Enter Age For: "+pat1,"Age", JOptionPane.QUESTION_MESSAGE);
    		age1 = Integer.parseInt(avalue);
    		avalue = JOptionPane.showInputDialog(null,"Enter Age For: "+pat2,"Age", JOptionPane.QUESTION_MESSAGE);
    		age2 = Integer.parseInt(avalue);
    		avalue = JOptionPane.showInputDialog(null,"Enter Age For: "+pat3,"Age", JOptionPane.QUESTION_MESSAGE);
    		age3 = Integer.parseInt(avalue);
    		avalue = JOptionPane.showInputDialog(null,"Enter Age For: "+pat4,"Age", JOptionPane.QUESTION_MESSAGE);
    		age4 = Integer.parseInt(avalue);
    		avalue = JOptionPane.showInputDialog(null,"Enter Age For: "+pat5,"Age", JOptionPane.QUESTION_MESSAGE);
    		age5 = Integer.parseInt(avalue);
     
    		//Gender Dialog Boxes
    		gen1 = JOptionPane.showInputDialog(null,"Enter Gender For: "+pat1,"Gender", JOptionPane.QUESTION_MESSAGE);
    		gen2 = JOptionPane.showInputDialog(null,"Enter Gender For: "+pat2,"Gender", JOptionPane.QUESTION_MESSAGE);
    		gen3 = JOptionPane.showInputDialog(null,"Enter Gender For: "+pat3,"Gender", JOptionPane.QUESTION_MESSAGE);
    		gen4 = JOptionPane.showInputDialog(null,"Enter Gender For: "+pat4,"Gender", JOptionPane.QUESTION_MESSAGE);
    		gen5 = JOptionPane.showInputDialog(null,"Enter Gender For: "+pat5,"Gender", JOptionPane.QUESTION_MESSAGE);
     
    		//Location Dialog Boxes
    		loc1 = JOptionPane.showInputDialog(null,"Enter Location For: "+pat1,"Location", JOptionPane.QUESTION_MESSAGE);
    		loc2 = JOptionPane.showInputDialog(null,"Enter Location For: "+pat2,"Location", JOptionPane.QUESTION_MESSAGE);
    		loc3 = JOptionPane.showInputDialog(null,"Enter Location For: "+pat3,"Location", JOptionPane.QUESTION_MESSAGE);
    		loc4 = JOptionPane.showInputDialog(null,"Enter Location For: "+pat4,"Location", JOptionPane.QUESTION_MESSAGE);
    		loc5 = JOptionPane.showInputDialog(null,"Enter Location For: "+pat5,"Location", JOptionPane.QUESTION_MESSAGE);
     
    		//Insurance Dialog Boxes
    		Ivalue = JOptionPane.showInputDialog(null,"Enter Insurance Amount For: "+pat1, JOptionPane.QUESTION_MESSAGE);
    		ins1 = Double.parseDouble(Ivalue);
    		Ivalue = JOptionPane.showInputDialog(null,"Enter Insurance Amount For: "+pat2, JOptionPane.QUESTION_MESSAGE);
    		ins2 = Double.parseDouble(Ivalue);
    		Ivalue = JOptionPane.showInputDialog(null,"Enter Insurance Amount For: "+pat3, JOptionPane.QUESTION_MESSAGE);
    		ins3 = Double.parseDouble(Ivalue);
    		Ivalue = JOptionPane.showInputDialog(null,"Enter Insurance Amount For: "+pat4, JOptionPane.QUESTION_MESSAGE);
    		ins4 = Double.parseDouble(Ivalue);
    		Ivalue = JOptionPane.showInputDialog(null,"Enter Insurance Amount For: "+pat5, JOptionPane.QUESTION_MESSAGE);
    		ins5 = Double.parseDouble(Ivalue);
     
    		//Doctor Dialog Boxes
    		doc1 = JOptionPane.showInputDialog(null,"Enter Doctor's Name For: "+pat1,"Doctor's Name", JOptionPane.QUESTION_MESSAGE);
    		doc2 = JOptionPane.showInputDialog(null,"Enter Doctor's Name For: "+pat2,"Doctor's Name", JOptionPane.QUESTION_MESSAGE);
    		doc3 = JOptionPane.showInputDialog(null,"Enter Doctor's Name For: "+pat3,"Doctor's Name", JOptionPane.QUESTION_MESSAGE);
    		doc4 = JOptionPane.showInputDialog(null,"Enter Doctor's Name For: "+pat4,"Doctor's Name", JOptionPane.QUESTION_MESSAGE);
    		doc5 = JOptionPane.showInputDialog(null,"Enter Doctor's Name For: "+pat5,"Doctor's Name", JOptionPane.QUESTION_MESSAGE);

    //Calculations
    ??????????
    ???????????
    ??????????
    ????????????


    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with my assignment please!!! (Novice User)

    I have to input String data and then find averages of the Inputs
    See the Integer/Double class for a method to convert (parse) a String to an int/double value.
    Once the values are in int/double variables, you will be able to do the needed math.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my assignment please!!! (Novice User)

    Thanks once again Norm, am I way off base with my foundation? I have some sample code thats "similar" to what I'm doing and it looks nothing like what I have. I'm pretty sure I'm over complicating it and forcing myself to write way too much.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with my assignment please!!! (Novice User)

    Do you know about loops and arrays? Using them would make the code shorter and easier to work with.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my assignment please!!! (Novice User)

    I did know a little bit and I did some research and completely started from scratch. These are the problems that I'm having;

    When I use the Dialog box in order to print my results it shows results from each step of the input. (Shows first Entry, 2nd entry, 3rd, entry, ect...) I only want it to show the very end result after its done collecting the information but I'm not sure how to do it.

    Also theres a part of the assignment that says "Output the name of the Doctor that received the highest payment, and what that payment was." I'm sure how to even start doing this. Do I have to use a scanner? I'm not very good with scanners at all, I've only used them in a couple of sample programs.

    Your help is always appreciated!

    package Javassignment3;
    import javax.swing.JOptionPane;
    public class Javassignment3 {
     
    	public static void main(String[] args) {
     
    		String gvalue, dName;
    		int acount=0, gcount=0, lcount=0;
    		double icount=0;
    		int pat, mcount=0, fcount=0;
    		int mTotal, fTotal;
    		int mAge=0, fAge=0, fAgeAve=0, mAgeAve=0;
    		double insAve=0;
    		int sCount=0, hCount=0;
    		double sIns=0, hIns=0, hInsAve=0, sInsAve=0;
    		double totalIns=0, totalInsAve=0;
    		String info="";
    		int wirthCount=0, tamesCount=0, kleinCount=0;
     
     
    		for(pat = 1; pat<=5; ++pat){
    			//Input data
    			gvalue = JOptionPane.showInputDialog(null,"Enter Patient Gender (1=M 2=F): ","Gender", JOptionPane.QUESTION_MESSAGE);
    			gcount = Integer.parseInt(gvalue);
    			gvalue =JOptionPane.showInputDialog(null,"Enter Patients Age","Age", JOptionPane.QUESTION_MESSAGE);
    			acount = Integer.parseInt(gvalue);
    			gvalue = JOptionPane.showInputDialog(null,"Enter Location (1=Surgery Center 2=Hospital): ","Location", JOptionPane.QUESTION_MESSAGE);
    			lcount = Integer.parseInt(gvalue);
    			gvalue = JOptionPane.showInputDialog(null,"Enter Insurance Payment","Insurance", JOptionPane.QUESTION_MESSAGE);
    			icount = Double.parseDouble(gvalue);
    			dName = JOptionPane.showInputDialog(null, "Enter Doctor's Last Name (Wirth, Lames, or Klein): ","Doctor", JOptionPane.QUESTION_MESSAGE);
     
    			//if Gender conditions
    			if(gcount==1){
    				mcount=mcount+1;
    				mAge=mAge+acount;
     
    			}
    			else{
    				fcount=fcount+1;
    				fAge=fAge+acount;	
    			}
     
    			//if Location conditions
    			if(lcount==1){
    				sCount=sCount+1;
    				sIns=sIns+icount;
     
     
    			}
    			else
    				hCount=hCount+1;
    				hIns=hIns+icount;
     
    			//Surgeon Count
    			if(dName.equals("Wirth")){
    				wirthCount=wirthCount+1;
    			}
     
    			//average
    			mAgeAve=mAge/5;
    			fAgeAve=fAge/5;
    			hInsAve=hIns/hCount;
    			sInsAve=sIns/sCount;
    			totalIns=hIns+sIns;
    			totalInsAve=totalIns/5;
     
     
    			info=info+"Number of Males: "+mcount+"\n";
    			info=info+"Average Age of Males: "+mAgeAve+"\n";
    			info=info+"Number of Females: "+fAge+"\n";
    			info=info+"Average Age of Females: "+fAgeAve+"\n";
    			info=info+"Average Insurance Payment at Surgery Center: "+sInsAve+"\n";
    			info=info+"Anverage Insurance Payment at Hospital: "+hInsAve+"\n";
    			info=info+"Average Insurance Payment for all Surgeries: "+totalInsAve+"\n";
     
     
    		{
    		JOptionPane.showMessageDialog(null,info,"Information", JOptionPane.INFORMATION_MESSAGE);
    		System.exit(0);
    		}
    		}
    		}

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help with my assignment please!!! (Novice User)

    I only want it to show the very end result after its done collecting
    If that statement is outside the loop it should only show once.

    Output the name of the Doctor that received the highest payment
    That requires you to save the amount of payment and name of the doctor that got it. As the payments are received compare the new payment against the one saved. If bigger, save the new amt and name.
    A technique is to prime the amt with a small or negative value so the first compare will save the data for the first one.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java User-Input bug (not continuing); NOVICE
    By Shzylo in forum Java Theory & Questions
    Replies: 11
    Last Post: December 14th, 2012, 07:54 AM
  2. Hello every user.. Please help in me my java assignment !!!
    By commandor in forum Algorithms & Recursion
    Replies: 1
    Last Post: March 11th, 2012, 10:24 AM
  3. Novice needs advice
    By grahamgen in forum Java Theory & Questions
    Replies: 8
    Last Post: September 12th, 2011, 04:04 PM
  4. Novice with java methods, please help!
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2009, 04:23 AM