Hey guys :idea:
This is my code

studNo = JOptionPane.showInputDialog(null, "Enter Student Number: ");
	studName = JOptionPane.showInputDialog(null, "Enter Student Name  : ");

	prelim = Float.parseFloat(JOptionPane.showInputDialog("Enter Prelim grade  : "));
	midterm = Float.parseFloat(JOptionPane.showInputDialog("Enter Midterm grade  : "));
	finals = Float.parseFloat(JOptionPane.showInputDialog("Enter Final grade  : "));

	
	overallGrade = (prelim * .2) + (midterm * .3) + (finals * .5);

	
	JOptionPane.showMessageDialog(null, "         Grade Computation" + "\n"
+ "Student No.     : " + studNo + "\n"
+ "Student Name: " + studName + "\n" + "\n"
+ "Grades: " + "\n" 
+ "     Prelims  : " + prelim + "\n" 
+ "     Midterm : " + midterm + "\n" 
+ "     Finals      : " + finals + "\n" + "\n" 
+ "Results:" + "\n" 
+ "      Overall Grades: " + overallGrade + "\n" + "\n"

 + "Created by: Sample" + "\n"
 + "Date completed: November 29, 2011");

 
            
	if (overallGrade >= 75) 
	JOptionPane.showMessageDialog(null, "      Remarks: Passed"); 
	if (overallGrade <= 75 && overallGrade >= 50) 
	JOptionPane.showMessageDialog(null, "      Remarks: Failed");
	else if (overallGrade <= 49) 
	JOptionPane.showMessageDialog(null, "      Remarks: Dropped");

so basically what I want is to put the remarks at that specified area and not print it separately


I run out of idea on how to do is, I'm hoping someone can help me with this.. Please, I'm begging anyone :)

Recommended Answers

All 3 Replies

if you want that, you have to put all of it in one String and show it using one JOptionPane MessageBox

one option:

String before = " Grade Computation" + "\n"
+ "Student No. : " + studNo + "\n"
+ "Student Name: " + studName + "\n" + "\n"
+ "Grades: " + "\n"
+ " Prelims : " + prelim + "\n"
+ " Midterm : " + midterm + "\n"
+ " Finals : " + finals + "\n" + "\n"
+ "Results:" + "\n"
+ " Overall Grades: " + overallGrade + "\n" + "\n";

String after = "\nCreated by: Sample" + "\n"
+ "Date completed: November 29, 2011";

String grade = "";

if (overallGrade >= 75)
grade =  " Remarks: Passed";
if (overallGrade <= 75 && overallGrade >= 50)
grade = " Remarks: Failed";
else if (overallGrade <= 49)
grade = " Remarks: Dropped";
String result = new String(before);
result.concat(grade);
result.concat(after);
JOptionPane.showMessageDialog(null, result);

I tried using the code you gave me but when I run it, this time, it doesn't show the remarks anymore

String result = new String(before);

plus this part has yellow highlights and it says Remove string constructor invocation

anyway, I tried removing it but still nothing happens, the remarks still won't show up. I don't know if I'm doing something wrong. gaah!! my head is all messed up..

well ... I just wrote something in the lines of what you should do.
yes, String has no constructor which takes a String as parameter, but I figured you would figure that one out.
you can replace that line with

String result = before;

in your if statements, you can change the code in:

if (overallGrade >= 75)
 result +== " Remarks: Passed";
if (overallGrade <= 75 && overallGrade >= 50)
  result += " Remarks: Failed";
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.