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: help with a last bit of my code!!

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with a last bit of my code!!

    Ok so this is my code


    import java.util.Scanner;

    public class AllisonBrittanyCalculateGrades {

    public static void main(String [] args) {

    Scanner sc = new Scanner(System.in);

    double sum = 0;
    double lowest = 100;
    double score;
    double ast;
    double grad;

    for(grad = 1; grad <= 5; grad++) {

    System.out.println("Enter asignment grades");
    score = sc.nextDouble();

    sum = sum + score;

    if (score < lowest)
    {
    lowest = score;
    }
    }
    sum = sum - lowest;
    sum = sum/4;

    System.out.println("Your assignment average is " + sum);

    System.out.println("Enter first exam grade");
    double grade1 = sc.nextDouble();

    System.out.println("Enter second exam grade");
    double grade2 = sc.nextDouble();

    System.out.println("Enter lab grade");
    double lab = sc.nextDouble();

    System.out.println("Enter final exam grade");
    double fe = sc.nextDouble();

    double average = sum*.20 + grade1*.15 + grade2*.20 + lab*.20 + fe*.25;
    System.out.println("The weighted average is " + average);

    if (average <= 100 && average >= 90) {
    System.out.println("You will receive an A");
    }
    if (average < 90 && average >= 80) {
    System.out.println("You will receive an B");
    }
    if (average < 80 && average >= 70) {
    System.out.println("You will receive an C");
    }
    if (average < 70 && average >= 60) {
    System.out.println("You will receive an D");
    }
    if (average < 60) {
    System.out.println("You will receive an F");
    }

    Scanner scanner = new Scanner(System.in);

    System.out.println("Do you want to calculate for another student? Please type true or false");
    String truefalse = scanner.nextLine();
    }
    }



    the issue I'm having is I need to be able to have it say bye bye if the user types in false and have it start from the beggining if the user types in true. I have tried everything I can think of and I have to turn this program in by the end of the say. Please help!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with a last bit of my code!!

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

    have it say bye bye if the user types in false and have it start from the beggining if the user types in true
    That's usually done by wrapping the code to be repeated in a while loop. The while's condition should test what the user entered and either continue or exit as per the program's requirements.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default Re: help with a last bit of my code!!

    Continuing from where you left off, I can only suggest that you:
    1. Declare a boolean type of truefalse first
    2. Place all your code in a while loop
    3. Don't need to create another object of your Scanner class.
    4. Replace -
     String truefalse = scanner.nextLine();
    with
     truefalse = sc.nextBoolean();
    . Something like this:
    boolean truefalse = true;
    while (truefalse){
    //TheRestOfYourCodeGoesHere
    //Finally
    System.out.println("Do you want to calculate for another student? Please type true or false");
    truefalse  = sc.nextBoolean();
    }

    I hope this helps.
    Who holds the KEY to all knowledge?

Similar Threads

  1. how to make my code play some audio?Just a bit!
    By Samaras in forum Java Theory & Questions
    Replies: 11
    Last Post: August 29th, 2012, 08:23 AM
  2. Noob needs a bit of help
    By carmst74 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 14th, 2011, 06:01 PM
  3. New to Java I am a bit puzzled with my code
    By Elle_Le_Belle in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 15th, 2011, 11:52 AM
  4. Eclipse goes beyond me a bit
    By MagicMojo in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 9th, 2011, 10:05 AM
  5. bit of help please...
    By Andrew123 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 15th, 2010, 06:07 AM

Tags for this Thread