The Artima Developer Community
Sponsored Link

Java Answers Forum
Using Java to Calculate Semester Hours

7 replies on 1 page. Most recent reply: May 13, 2003 3:04 AM by Rahul

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
Emmanuel Michel

Posts: 4
Nickname: bandog
Registered: May, 2003

Using Java to Calculate Semester Hours Posted: May 12, 2003 5:04 AM
Reply to this message Reply
Advertisement
I am trying to use Java to calculate my semester hours, however I am stuck..Below is the following program, how would I have it calculate the following semester hours.

Mis650 Grade D= 0 credit
Mis670 Grade A= 4 Credit
Mis692 Grade C= 3 credits
Mis700 Grade B+ =3 credits
Mis800 Grade F = 0 credits
Mis540 Grade B= 4 Credit

The number credit earned should be 14, but somehow, I am getting an error


Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: Using Java to Calculate Semester Hours Posted: May 12, 2003 6:11 AM
Reply to this message Reply
You haven't posted your code which makes it difficult to assess the error.

Here's a crude implementation that works from the console:

import java.io.*;
import java.util.*;
 
class GradeCalculator 
{
	public static void main(String[] args) throws IOException
	{
		
		String course[] = new String[]{"MIS650","MIS670","MIS692","MIS700","MIS800","MIS540"};
		Hashtable ht = new Hashtable();
 
		ht.put("A",new Integer(4));
		ht.put("B",new Integer(4));
		ht.put("B+",new Integer(3));
		ht.put("C",new Integer(3));
		ht.put("D",new Integer(0));
		ht.put("F",new Integer(0));
 
		System.out.println("Please enter your grades for respective courses - ");
 
		String temp;
		int credits = 0;
 
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
 
		for (int i=0;i<course.length ;i++ )
		{
			System.out.print(course[i]+" :");
			temp = buf.readLine();
			
			try{
				credits+= ((Integer)ht.get(temp)).intValue();
			}catch(NullPointerException ne){
				
				System.out.println("Please fill in correct grades");
				i--;
			}
		}
		System.out.println("Total credits = "+credits);
	}
}

Emmanuel Michel

Posts: 4
Nickname: bandog
Registered: May, 2003

Re: Using Java to Calculate Semester Hours Posted: May 12, 2003 7:07 AM
Reply to this message Reply
Here is the code..The code output the following info..GPA 2.25, First, and Last name..It is suppose to output credit hour of 14..The problems comes when I add the following:


double credit earned=6;
Credit Earned = ((mmis_650 + mmis_670 + mmis_692+ mmis_700 + mmis_800 + mmis_540 ) / number_credit);

(I supposed the following code should allow me to add the semester hour)


CODES USING



public class assign2_example {
public static void main(String[] args) {
int mmis_650 = 1;
int mmis_655 = 4;
short mmis_667 = 2;
double mmis_680 = 3.5
int mmis_690 = 0;
int mmis_693 = 3;
double number_courses = 6;
String last_name = new String ("Michel");
String first_name = new String ("Emmanuel");
double gpa = ((mmis_650 + mmis_670 + mmis_692+ mmis_700 + mmis_800 + mmis_540 ) / number_courses);

double credit earned=6;
Credit Earned = ((mmis_650 + mmis_670 + mmis_692+ mmis_700 + mmis_800 + mmis_540 ) / number_credit);

System.out.println("MMIS 650 " + mmis_650);
System.out.println("MMIS 670 " + mmis_670);
System.out.println("MMIS 692 " + mmis_692);
System.out.println("MMIS 700 " + mmis_700);
System.out.println("MMIS 800 " + mmis_800);
System.out.println("MMIS 540 " + mmis_540);
System.out.println("");
System.out.println("GPA " + gpa);
System.out.println("");
System.out.println ("Last Name : " + last_name);
System.out.println ("First Name: " + first_name);


}
}




Thank you

Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: Using Java to Calculate Semester Hours Posted: May 12, 2003 9:21 PM
Reply to this message Reply
There is a gross mismatch between the variables that you have declared and those that you are trying to use!

Emmanuel Michel

Posts: 4
Nickname: bandog
Registered: May, 2003

Re: Using Java to Calculate Semester Hours Posted: May 12, 2003 10:40 PM
Reply to this message Reply
INSTRUCTION

Use the following data for your calculations:
COURSE - GRADE - CREDITS EARNED

MMIS 650 - Grade = "D" - 0 credits
MMIS 670 - Grade = "A" - 4 credits
MMIS 692 - Grade = "C" - 3 credits
MMIS 700 - Grade = "B+" - 3 credits
MMIS 800 - Grade = "F" - 0 credits
MMIS 540 - Grade = "B" - 4 credits

A = 4, B+ = 3.5, B=3, C=2, D=1, F=0
Write a java program that will output the following information :
********************************************************
First Name: Your First Name
Last Name: Your Last Name
GPA: Calculate using the data above
Num Credits Earned At NSU: Calculate using the data above

***TO Compile the program, I am using Ready to Program, software designed by Holt Software Associate.



Code use to generate the following output: First Name, Last Name, GPA, Credit at NSU(can't get that to work, i thougth if I added the grades and divide them,I should be able to get answer, but I get an error)

//Emmanuel Michel

public class assign2_example {
public static void main(String[] args) {

int mmis_650 = 1;
int mmis_670 = 4;
short mmis_692 = 2;
double mmis_700 = 3.5;// use double because 3.5 is floating-point number
int mmis_800 = 0;
int mmis_540 = 3;
double number_courses = 6;
String last_name = new String ("Michel");
String first_name = new String ("Emmanuel");
double gpa = ((mmis_650 + mmis_670 + mmis_692+ mmis_700 + mmis_800 + mmis_540 ) / number_courses);




System.out.println("MMIS 650 " + mmis_650);
System.out.println("MMIS 670 " + mmis_670);
System.out.println("MMIS 692 " + mmis_692);
System.out.println("MMIS 700 " + mmis_700);
System.out.println("MMIS 800 " + mmis_800);
System.out.println("MMIS 540 " + mmis_540);
System.out.println("");
System.out.println("GPA " + gpa);
System.out.println("");
System.out.println ("Last Name : " + last_name);
System.out.println ("First Name: " + first_name);


}
}

When I run the program, it generate the following output, I copied and paste it.

MMIS 650 1
MMIS 670 4
MMIS 692 2
MMIS 700 3.5
MMIS 800 0
MMIS 540 3

GPA 2.25

Last Name : Michel
First Name: Emmanuel


The problem is, I need to also to include the code to have it output the number credit of 14

Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: Using Java to Calculate Semester Hours Posted: May 12, 2003 11:04 PM
Reply to this message Reply
How about adding all variables like mmis_650, mmis_670 etc and printing it out ?

Emmanuel Michel

Posts: 4
Nickname: bandog
Registered: May, 2003

Re: Using Java to Calculate Semester Hours Posted: May 13, 2003 2:34 AM
Reply to this message Reply
Thank you so much for your assisance.. I have the Semester hour calculated, instead of coming with 14 as the semester hour, it is coming with 13.5. I am sure by the end of the day, I will figure where the error is at..Again, thank you very much. This is what I am using to calculate it.

double credit = (mmis_650 + mmis_655 + mmis_667+ mmis_680 + mmis_690 + mmis_693 );

Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: Using Java to Calculate Semester Hours Posted: May 13, 2003 3:04 AM
Reply to this message Reply
Of course, if you give credits like 3.5 then you should expect 13.5. Still if u want 14, try Math.ceil().

Best of luck,

Flat View: This topic has 7 replies on 1 page
Topic: crash Tomcat Previous Topic   Next Topic Topic: ceeating DLL

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use