Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times

    Exclamation OMG nee JAVA (not javascript) help!

    OK - I need help with this - it's commented so if anyone can help me out I'd really be grateful.
    This is for a school assignment, and I can't see what the prof is writing on the screen...
    Code:
    public class GradeCalc {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner input = new Scanner(System.in);
    		//1.Ask user for max points
    		System.out.println("What is the max points you can attain?");
    		int maxPoints = input.nextInt();
    		
    		System.out.println("The max points is: " + maxPoints);
    	
    		//2. Ask user how many points attained
    	    System.out.println("What is the max points you got?");
    	    int myPoints = input.nextInt();
    	
    	    System.out.println("The max points I got is: " + myPoints);
    
    
    		
    		//3. Display % of points attained
    		//how to do this?
    	    double (myPercent
    			System.out.println("The max points I got is: " + myPercent);
    		//4. Display the letter grade
    	 int testscore = 76;
    	 //arbitrary number here - not sure how to get it into the equation below
         char grade;
    
    
         if (testscore >= 90) {
             grade = 'A';
         } else if (testscore >= 80) {
             grade = 'B';
         } else if (testscore >= 70) {
             grade = 'C';
         } else if (testscore >= 60) {
             grade = 'D';
         } else {
             grade = 'F';
         }
         System.out.println("Grade = " + grade);
          // this only works if the original max points is 100 - if it were different it would not work...
    	}
    }
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,139
    Member #
    27197
    Liked
    959 times
    Are you just trying to figure out how to calculate the grade?
    If so, syntax is on you because I don't know Java, but:
    Code:
    (myPoints/maxPoints)*100
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    OK - that's like PHP, so I get that - now I have to figure out how to write whatever will fetch myPoints and get it into the equation...

    I am not sure I'm ready for this...
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,139
    Member #
    27197
    Liked
    959 times
    Perhaps this? How To Use Divide By In Java - Java | Dream.In.Code
    Which seems like:
    Code:
    double myPercent = (myPoints / maxPoints) * 100;
    // Or possibly
    int myPercent = (myPoints / maxPoints) * 100;
    Man, we might just end up learning Java together...
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  6. #5
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    I've been looking things up for hours - my head is spinning - I may drop this and just go with Advanced PHP...

    This was described as a beginners course - there are 25 in the class and everyone but me has a background in something that works like JAVA; C#, C++, some are there to "brush up" on their JAVA. The guy beside me has been programming in C for twenty years, and C++ for seven... But what he writes is not the same as what the Prof writes on the big screen, so it does me no good. His stuff works - he and the prof discuss why their approaches are different - but I don't need to learn more than one way to do things at this point!

    This is a government-sponsored course (Quebec pays the tuition), and the guy teaching it actually works in the business, so it is up-to-date, but it seems many of the people in the class already know a lot of this and are there just for the certification, not for the knowledge. And so we are going forward really fast, and I am very much afraid I'm going to get left behind. I have three classes to decide if I'm going to drop it - if I drop after the cutoff date I have to pay the tuition, and it's about $1200. Also, if I fail at midterms, they kick me out and I have to pay. So it's a big decision.

    I'll let you know when I get it working
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  7. #6
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,139
    Member #
    27197
    Liked
    959 times
    I didn't try getting the conditional for the grade letter to work, but after some digging thru the Java API, I wrote this, which I was able to compile and successfully run:
    Code:
    //Not sure what this is, but apparently you're supposed to import Scanner before you use it.
    import java.util.Scanner;
    public class GradeCalc{
    public static void main(String[] args){ 
        Scanner input = new Scanner(System.in);  
    //Declare some variables. Discovered that using double is key here.
        double maxPoints; 
        double myPoints;
        double myPercent; 
    //Ask the question.
        System.out.print("Max possible: "); 
    //Store it. Lather, rinse, repeat.
        maxPoints = input.nextInt();
        System.out.print("Input your score: ");
        myPoints = input.nextInt();
    //Calculate your percent.
        myPercent = (myPoints/maxPoints)*100;
    //Round your percent. Guessed on whether this was a thing in Java. Totally nailed it.
        myPercent = Math.round(myPercent);
    //Output the grade.
        System.out.println("Your percentage is: " + myPercent + "%");
        } 
    }
    Last edited by Ronald Roe; Sep 19th, 2013 at 03:33 PM.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  8. #7
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times

    Smile

    Jeez - I forgot about that - we did import Scanner - we're using eclipse with the Android ADT bundle, and it give you lists of hints (kind of like DW) and you can import and install automatically (kind of like the Linux repository).

    We imported it for an earlier exercise and I guess it just stayed resident in the program.

    I have had a discussion with the program co-ordinator and we spoke to the Prof - the upshot is that I'm going to drop this in favor of advanced PHP, to will give me a better basis for the JAVA, then re-enroll next year. It's a bit of a bummer, but I'd rather do it right than stumble through it and not get all I can from the course. Since I already know a bit about PHP, I'm going to concurrently take the course in HTML5 and CSS3, so it's not so bad.

    Anyway, thank for the help - I'm still trying to figure out the math - what the thing is supposed to do is:


    1. when compiled, the program should print out the question "What are the max points available?"
    2. the user inputs a number
    3. then the program prints out the question "How many points did you get?"
    4. the user inputs a second number
    5. using those two numbers, the program calculates the percentage value of the user's points and prints it out
    6. then the program calculates the letter grade based on the percentage and prints it out.


    I'm going to pick up a "JAVA for Dummies" or something and see how that goes - the HTML5/CSS3 is on weekends only and the PHP doesn't start until January, so maybe I'll have some time to play around.
    Last edited by AlphaMare; Sep 19th, 2013 at 04:11 PM.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  9. #8
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,480
    Member #
    425
    Liked
    2784 times
    Man, I gotta get the government of Ontario to start sponsoring me and give me free education.

    How'd you pull that off, Mare?
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  10. #9
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by TheGAME1264 View Post
    Man, I gotta get the government of Ontario to start sponsoring me and give me free education.

    How'd you pull that off, Mare?
    Move to a bigoted, xenophobic, narcissistic province that wants to develop a captive French unilingual workforce so they can separate from Canada, and trains them on the federal equalization transfer dime?
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  11. #10
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,480
    Member #
    425
    Liked
    2784 times
    If it wasn't so damn cold there, CALISS, count me in!

    (You forgot "sexually degenerate", by the way).
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:02 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com