Results 1 to 4 of 4
Thread: Need help with my codes
- 06-28-2011, 04:32 PM #1
Need help with my codes
hi im a first year college student and im new to Java. And this is our first assignment, Create a program that will compute the average grade, equivalent and remarks of student using whileloop and dowhile loop. And here's what i've done so far:
package Whileloop;
public class yourGrades {
public float prelimGrades = 0.0F;
public float midtermGrades = 0.0F;
public float finalGrades = 0.0F;
public float averageGrades = 0.0F;
public double[] equivalent = new double[10];
public String[] remark = new String[10];
public void showAll() {
averageGrades = (prelimGrades + midtermGrades + finalGrades) / 3;
System.out.println("\nAverage grade: " + averageGrades);
equivalent[0] = 1;
equivalent[1] = 1.25;
equivalent[2] = 1.50;
equivalent[3] = 1.75;
equivalent[4] = 2;
equivalent[5] = 2.25;
equivalent[6] = 2.50;
equivalent[7] = 2.75;
equivalent[8] = 3;
equivalent[9] = 5;
remark[0] = "EXCELLENT";
remark[1] = "VERY GOOD";
remark[2] = "VERY GOOD";
remark[3] = "GOOD";
remark[4] = "GOOD";
remark[5] = "FAIR";
remark[6] = "FAIR";
remark[7] = "PASSING";
remark[8] = "PASSING";
remark[9] = "FAILED";
if (averageGrades >= 98 && averageGrades <= 100) {
System.out.println("Equivalent: " + equivalent[0]);
System.out.println("Remark: " + remark[0]);
} else if (averageGrades >= 96) {
System.out.println("Equivalent: " + equivalent[1]);
System.out.println("Remark: " + remark[1]);
} else if (averageGrades >= 93) {
System.out.println("Equivalent: " + equivalent[2]);
System.out.println("Remark: " + remark[2]);
} else if (averageGrades >= 90) {
System.out.println("Equivalent: " + equivalent[3]);
System.out.println("Remark: " + remark[3]);
} else if (averageGrades >= 87) {
System.out.println("Equivalent: " + equivalent[4]);
System.out.println("Remark: " + remark[4]);
} else if (averageGrades >= 84) {
System.out.println("Equivalent: " + equivalent[5]);
System.out.println("Remark: " + remark[5]);
} else if (averageGrades >= 81) {
System.out.println("Equivalent: " + equivalent[6]);
System.out.println("Remark: " + remark[6]);
} else if (averageGrades >= 78) {
System.out.println("Equivalent: " + equivalent[7]);
System.out.println("Remark: " + remark[7]);
} else if (averageGrades >= 75) {
System.out.println("Equivalent: " + equivalent[8]);
System.out.println("Remark: " + remark[8]);
} else if (averageGrades <= 74) {
System.out.println("Equivalent: " + equivalent[9]);
System.out.println("Remark: " + remark[9]);
}
}
}
__________________________________________________ ________________________________
package Whileloop;
import java.io.*;
public class yourGradesTest {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
yourGrades yg = new yourGrades();
int x = 1;
while (x < 5) {
x++;
System.out.print("\nEnter your Prelim Grades: ");
yg.prelimGrades = Float.parseFloat(reader.readLine());
System.out.print("Enter your Midterm Grades: ");
yg.midtermGrades = Float.parseFloat(reader.readLine());
System.out.print("Enter your Final Grades: ");
yg.finalGrades = Float.parseFloat(reader.readLine());
yg.showAll();
}
}
}
__________________________________________________ _________________________________
package DoWhileloop;
public class yourGrades1 {
public float prelimGrades = 0.0F;
public float midtermGrades = 0.0F;
public float finalGrades = 0.0F;
public float averageGrades = 0.0F;
public double[] equivalent = new double[10];
public String[] remark = new String[10];
public void showAll() {
averageGrades = (prelimGrades + midtermGrades + finalGrades) / 3;
System.out.println("\nAverage grade: " + averageGrades);
equivalent[0] = 1;
equivalent[1] = 1.25;
equivalent[2] = 1.50;
equivalent[3] = 1.75;
equivalent[4] = 2;
equivalent[5] = 2.25;
equivalent[6] = 2.50;
equivalent[7] = 2.75;
equivalent[8] = 3;
equivalent[9] = 5;
remark[0] = "EXCELLENT";
remark[1] = "VERY GOOD";
remark[2] = "VERY GOOD";
remark[3] = "GOOD";
remark[4] = "GOOD";
remark[5] = "FAIR";
remark[6] = "FAIR";
remark[7] = "PASSING";
remark[8] = "PASSING";
remark[9] = "FAILED";
if (averageGrades >= 98 && averageGrades <= 100) {
System.out.println("Equivalent: " + equivalent[0]);
System.out.println("Remark: " + remark[0]);
} else if (averageGrades >= 96) {
System.out.println("Equivalent: " + equivalent[1]);
System.out.println("Remark: " + remark[1]);
} else if (averageGrades >= 93) {
System.out.println("Equivalent: " + equivalent[2]);
System.out.println("Remark: " + remark[2]);
} else if (averageGrades >= 90) {
System.out.println("Equivalent: " + equivalent[3]);
System.out.println("Remark: " + remark[3]);
} else if (averageGrades >= 87) {
System.out.println("Equivalent: " + equivalent[4]);
System.out.println("Remark: " + remark[4]);
} else if (averageGrades >= 84) {
System.out.println("Equivalent: " + equivalent[5]);
System.out.println("Remark: " + remark[5]);
} else if (averageGrades >= 81) {
System.out.println("Equivalent: " + equivalent[6]);
System.out.println("Remark: " + remark[6]);
} else if (averageGrades >= 78) {
System.out.println("Equivalent: " + equivalent[7]);
System.out.println("Remark: " + remark[7]);
} else if (averageGrades >= 75) {
System.out.println("Equivalent: " + equivalent[8]);
System.out.println("Remark: " + remark[8]);
} else if (averageGrades <= 74) {
System.out.println("Equivalent: " + equivalent[9]);
System.out.println("Remark: " + remark[9]);
}
}
}
__________________________________________________ _________________________________
package DoWhileloop;
import java.io.*;
public class yourGrades1Test {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
yourGrades1 yg1 = new yourGrades1();
int x = 1;
do {
x++;
System.out.print("\nEnter your Prelim Grades: ");
yg1.prelimGrades = Float.parseFloat(reader.readLine());
System.out.print("Enter your Midterm Grades: ");
yg1.midtermGrades = Float.parseFloat(reader.readLine());
System.out.print("Enter your Final Grades: ");
yg1.finalGrades = Float.parseFloat(reader.readLine());
yg1.showAll();
} while (x < 5);
}
}
now my question is how can i make my codes more interesting like having a pop up box when asking to enter the name and the prelim, midterm, final grades? thank you very much !!!
- 06-28-2011, 05:14 PM #2
Please wrap your code in code tags when posting it. See: BB Code List - Java Forums
Or use the # icon above the input box.
For popup/dialog boxes to get user input, see the JOptionPane class. There are many code samples on this forum if you do a Search.
- 06-28-2011, 06:21 PM #3
That's the spirit. Like Norm said, JOptionPane is going to be your friend here: How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
You might also want to check out the API: Java Platform SE 6How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-29-2011, 12:23 PM #4
Similar Threads
-
I need some codes
By johnmergene in forum New To JavaReplies: 11Last Post: 01-25-2011, 03:42 AM -
What do the following codes do?
By javaguy2 in forum New To JavaReplies: 2Last Post: 01-23-2011, 10:23 PM -
How do I integrate these two codes?
By Isong in forum AWT / SwingReplies: 3Last Post: 11-03-2010, 02:44 AM -
java codes
By Balajee in forum AWT / SwingReplies: 1Last Post: 09-30-2008, 05:04 PM -
Assistant on my codes. SOS!!
By sya1912 in forum Java AppletsReplies: 16Last Post: 09-01-2008, 02:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks