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 3 of 3

Thread: Converting double values (0.0-110.0) to a 4.0 Scale (as used in GPA calculation)

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Converting double values (0.0-110.0) to a 4.0 Scale (as used in GPA calculation)

    Hello,

    I am new to programming, but am working on a program that takes 6 inputted grade averages on a scale of 0.0 - 100.0 (exceptions in the case someone has exceeded the traditional 100.0 limit) and then divides it by 6 and returns the value in a dialog box. However, I want to take the values inputted and convert them to a 4.0 scale (90.0-100.0 = 4.0, 80.0-89.99 = 3.0, etc.) and then get the average of that so that I can return an average on a 4.0 scale. I have been trying to accomplish this but haven't been able to figure it out and would appreciate some help. Also, as of right now my program only prompts the user for 6 inputs, but I'd like the user to be able to input as many as he/she would like to, any suggestions? I am pasting the code I currently have below.


    import javax.swing.JOptionPane;
     
    public class GPA_Calculation1_0 {
     
    	public static void main(String[] args) {
     
    String courseOne = JOptionPane.showInputDialog("Enter numeric GPA of Course One: ");//Course one
    double numOne = Double.parseDouble(courseOne);
    String courseTwo = JOptionPane.showInputDialog("Enter numeric GPA of Course Two: ");//Course two
    double numTwo = Double.parseDouble(courseTwo);
    String courseThree = JOptionPane.showInputDialog("Enter numeric GPA of Course Three: ");//Course three
    double numThree = Double.parseDouble(courseThree);
    String courseFour = JOptionPane.showInputDialog("Enter numeric GPA of Course Four: ");//Course four
    double numFour = Double.parseDouble(courseFour);
    String courseFive = JOptionPane.showInputDialog("Enter numeric GPA of Course Five: ");//Course five
    double numFive = Double.parseDouble(courseFive);
    String courseSix = JOptionPane.showInputDialog("Enter numeric GPA of Course Six: ");//Course six
    double numSix = Double.parseDouble(courseSix);
     
     
     
    double averageNum = ((numOne + numTwo + numThree + numFour + numFive + numSix)/6.0);
     
     
    JOptionPane.showMessageDialog(null, "Your numeric GPA is: " + averageNum);//Displays output of calculation in dialog box
     
     
     
    System.exit(0);
     
    	}
     
    }
    Last edited by JRR; September 3rd, 2014 at 09:27 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: Converting double values (0.0-110.0) to a 4.0 Scale (as used in GPA calculation)

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Do you need to save the values?
    Do you know about arrays? This is a good place to use them. (Later you'll learn about the ArrayList class which improves on arrays)
    Using an array will require using a loop.

    If you don't need to save the values, reuse the variable that the user enters his data into inside of a loop.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    JRR (September 3rd, 2014)

  4. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Converting double values (0.0-110.0) to a 4.0 Scale (as used in GPA calculation)

    Okay, I edited it, I think it's fixed now. I'm sorry, it's my first thread. And no I am not familiar, but that sounds like a great place to start, I'll go read about them! Thank you!

Similar Threads

  1. Replies: 1
    Last Post: July 26th, 2014, 04:38 AM
  2. Need help converting from int to double
    By newmanj8 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 26th, 2013, 04:24 PM
  3. GPA Calculation Program using an input file
    By ddk1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2011, 05:28 AM
  4. Double to string giving extra values
    By sinsand in forum Collections and Generics
    Replies: 1
    Last Post: August 23rd, 2011, 05:57 AM
  5. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM

Tags for this Thread