Results 1 to 20 of 20
- 09-22-2009, 07:09 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
so very lost on school project....
I am very very lost here....Java has always thrown me for a loop (no pun intended), but i am trying very hard to get through this class.
Anyways, we need to make a program that prompts the user for their major, their gpa, tuition, etc....you will see.
Then we are to print the average GPA, average Tuition, highest GPA for the math major, highest gpa for the CIS major, then list WHO had the highest gpa....etc etc etc....it's got my mind racing and I am extremely lost....
Anyways, here's what I have so far..I'm sure to the experts it will look like a total mess....
public static void main(String[] args) {
// TODO Auto-generated method stub
String studentsLast, sGPA = null;
String finalout="";
String text;
String scredits,sstudentsMajor = null;
String credits;
int studentsMajor = 0, i, large=0, gpa = 0;
double cisGPA, mathGpa=0, cisGpa=0, avgGpa, Gpa=0, totalTuition=0, counter=0;
double avgTuition=0, tuitionPaidfinal=0;
//Choose major
String output = "Please enter your major. Your choices are: " + "\n" +
"1. Math " + "\n" +
"2. CIS: " + "\n" +
"0 - End Input" + "\n";
String studentsMajorString = JOptionPane.showInputDialog(null,
output, "Input Data",
JOptionPane.QUESTION_MESSAGE);
//convert to integer
studentsMajor = Integer.parseInt(studentsMajorString);
for(i=1;i>1;++i)
while(studentsMajor != 0);
{
studentsLast = JOptionPane.showInputDialog(null,
"Enter student's last name", "Input Data",
JOptionPane.QUESTION_MESSAGE);
String numberOfCreditsString = JOptionPane.showInputDialog
("Enter number of credits, " +
"for example, 10: ");
//Convert string to double
double numberOfCredits = Double.parseDouble(numberOfCreditsString);
output = "Enter GPA, for example, 3.2: ";
String gpaString = JOptionPane.showInputDialog(null,
output, "Input Data",
JOptionPane.QUESTION_MESSAGE);
//Convert to integer
int gpa1 = Integer.parseInt(gpaString);
output = "Enter tuition paid, for example, 23400: ";
String tuitionPaidString = JOptionPane.showInputDialog(null,
output, "Input Data:",
JOptionPane.QUESTION_MESSAGE);
//Convert to double
double tuitionPaid = Double.parseDouble(tuitionPaidString);
output = "Please enter your major. Your choices are: " + "\n" +
"1. Math " + "\n" +
"2. CIS: " + "\n" +
"0 - End Input" + "\n";
sstudentsMajor = JOptionPane.showInputDialog(null,
output, "Input Data",
JOptionPane.QUESTION_MESSAGE);
//Convert to integer
studentsMajor = Integer.parseInt(sstudentsMajor);
} // while loop
//Average GPA
avgGpa = Gpa/i;
//Average Tuition Paid
avgTuition = tuitionPaidfinal / i;
output = "The average GPA is: "+avgGpa + "\n";
JOptionPane.showMessageDialog(null, output, " ",
JOptionPane.INFORMATION_MESSAGE);
output = "The average tuition paid is: "+avgTuition + "\n";
JOptionPane.showMessageDialog(null, output, " ",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//main
//class
}
- 09-22-2009, 07:10 PM #2
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
BTW, can't use an array...must use while loop.
- 09-22-2009, 07:16 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Please use code tags if you have to post code.
Don't just dump your code and throw your hands in the air. Describe what is happening vs what must happen.
- 09-22-2009, 07:37 PM #4
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
I apologize. Still new here.
What is happening is pretty much nothing. My dialog boxes are not throwing out the average tuition nor the average GPA. That's all the further I have coded because I wanted to make certain I was doing it right. I guess I am not.
Also, for some reason, after one cycle, i am exiting my loop. I need to stay in the loop until the user wishes to exit.
I am just very confused right now.
- 09-22-2009, 07:57 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
The while loop condition controls whether the looping continues or not.
Put println statements for the studentsMajor values to see what they are during execution.
Also, why do you have a for loop around your while loop?
Finally you never add any values at all in your loops so no totalling is ever being done.
- 09-22-2009, 08:00 PM #6
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
So for the credits, my coding needs to be credits = 0.
Correct?
The for loop is an error...I was jumping around trying to figure out how to implement a counter to count the number of times the loop was used.
- 09-22-2009, 08:18 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
To find out how many times your loop ran, you just initialize an int, say count, before the while loop and do count++; inside the while loop. No need for any for another looping construct. Then inside your loop, you need to be getting input values and adding them to some variables declared before the loop.
- 09-22-2009, 08:36 PM #8
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
It's still not staying in the loop. Added the counter...fixing the other things in the loop. Much thanks for all the info so far.
- 09-22-2009, 08:41 PM #9
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Like I said, use println statements to see what the values are at each stage in the program.
Make an effort to understand the out output you get from the printlns. If you get a compiler error, don't rush to post it here. Try to understand it and see if you can't finish it all yourself first.
- 09-22-2009, 08:41 PM #10
Have you tried doign it with a do while?
maybe thats easier? you can play endlessly with while loops :p
little example
Just trying to make you think in other ways to do it.Java Code:int count = 1; do { System.out.println("Count is: " + count); count++; } while (count <= 11); } }Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 09-22-2009, 08:44 PM #11
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
- 09-22-2009, 08:46 PM #12
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
Thank you for another perspective...I am thinking about just scrubbing the whole program and starting over.
Last edited by Moltisanti; 09-22-2009 at 08:48 PM. Reason: spelling error
- 09-22-2009, 08:49 PM #13
have you tried writing it out on a paper? when i lose grip on a project i try to run myself tru the code and write out how it should be. most of the time i solve my problem like that.
Works for me, but hey thats just how i try to do it when i'm in this situation.
try it and maybe you will see it
all the best,
DieterProgramming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 09-22-2009, 08:51 PM #14
by writing it on a paper i don't mean writing java code. i mean analysing like DFD's or NSD's or simple program steps.
Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 09-23-2009, 02:03 AM #15
Member
- Join Date
- Aug 2009
- Posts
- 19
- Rep Power
- 0
I have made tons of progress, but stuck at one last thing...I have to filter out the best GPA from the math student and the best GPA from the CIS student. I have no idea how to do that without using an array.
I'm guessing it should be an if/while statement again....any suggestions?
- 09-23-2009, 05:16 AM #16
-
Your best bet here is to post your best effort at this, and let's see if we can help you progress from there. Much luck!I have made tons of progress, but stuck at one last thing...I have to filter out the best GPA from the math student and the best GPA from the CIS student. I have no idea how to do that without using an array.
I'm guessing it should be an if/while statement again....any suggestions?
- 09-23-2009, 06:01 AM #18
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
hey i think we are in the same class. i had the same exact assignment due tonight and get so far, then get stuck when it comes to getting the calculations from the loop inputs. good luck with yours!
- 09-23-2009, 06:05 AM #19
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
oh, and needless to say, i didn't get it turned in by midnight when it was due. i'm nearly in tears over this project because there seems to be nothing in the book that is even close to what this assignment is asking for! Completely difficult for a java newbie like myself. This is my first java class.. I seemed fine with the assignments up until this one! Now I'm in a panic!
- 09-23-2009, 08:39 AM #20
Similar Threads
-
Need help with school work
By ccfdet in forum New To JavaReplies: 3Last Post: 08-29-2009, 07:14 PM -
Question about school assignment
By wata in forum New To JavaReplies: 7Last Post: 08-18-2009, 02:00 PM -
school project help
By justin8790 in forum New To JavaReplies: 5Last Post: 03-22-2009, 09:54 AM -
Beginner Needs Help w/ Program for School
By badness in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:51 PM -
Please help... assignment for school
By confused2000 in forum New To JavaReplies: 3Last Post: 11-12-2007, 08:12 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks