Question

CAN YOU PLEASE DO THIS IN JAVA! WILL LEAVE GOOD RATING THANK YOU Modify your program...

CAN YOU PLEASE DO THIS IN JAVA! WILL LEAVE GOOD RATING THANK YOU

Modify your program that reads grades from the user, so that it has a method that checks if a particular input is valid i.e. as long as the user types invalid input, the user should be given another chance to enter input (it would also be good to let the user know that their input is invalid). Moreover, only a valid grade should be used in computing the sum and average. At the appropriate point in your code, put a comment that states that the grade entered by the user has been determined to be valid.

Write/modify your program that draws 2 pictures (e.g. houses) so that it uses a loop (with 2 iterations). What would you need to change if you wanted the program to draw more than 2 pictures? What kind of loop is appropriate for this?

Tracing programs containing loops (by drawing tables and showing output; you need not write any code):

  • Trace the following program assuming the user enters 3 for value and 21 for limit. Draw a table showing the values of relevant variables (value, limit, mult, count) during each iteration of the loop: Multiples.java. As you trace, keep track of the output too, and then check that your predicted output is correct by running the program.
  • Trace Stars.java by drawing a table that shows the values of relevant variables (row and star) and keeping track of the output. This program contains a nested for loop, so for each iteration of the outer loop, the inner loop executes in its entirety:
    row star
    1 1
    2 1
    2 2
    3 1
    3 2
    3 3
    ... ...

Program below

import java.util.Scanner;

public class GradeSumAverage {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int grade = 0;
        int totalScore = 0;
        double scoreCount = 0;
        do {

            System.out.print("Enter your score (Enter -1 to exit): ");
            grade = scanner.nextInt();
            if (isValidScore(grade)) {
                System.out.println("Info: Grade entered is found to be valid.");
                totalScore += grade;
                scoreCount += 1;
            }

        } while (grade != -1); // loop until user enters -1

// dispplay the sum and average (to 2 decimals)
        System.out.println("Total Score: " + totalScore);
        System.out.printf("Average Score: %.2f\n", totalScore / scoreCount);
    }

// method takes in a grade returns true if the grade is between 0 and 100 else returns false
    public static boolean isValidScore(int score) {
        if (0 <= score && score <= 100) return true;
        else return false;
    }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here only GradeSumAverage class is given , so i am providing the answer for giving invalid message to user only.

1.

Code:

import java.util.Scanner;

public class GradeSumAverage {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
int grade = 0;
int totalScore = 0;
double scoreCount = 0;
do {

System.out.print("Enter your score (Enter -1 to exit): ");
grade = scanner.nextInt();
if (isValidScore(grade))
{
System.out.println("Info: Grade entered is determined to be valid.");
totalScore += grade;
scoreCount += 1;
}
else
{
System.out.println("Info: Your input is not valid, Please enter a valid input(between 0 to 100):");
//displaying invalid msg untill user enters valid number.
}

} while (grade != -1); // loop until user enters -1

// dispplay the sum and average (to 2 decimals)
System.out.println("Total Score: " + totalScore);
System.out.printf("Average Score: %.2f\n", totalScore / scoreCount);
}

// method takes in a grade returns true if the grade is between 0 and 100 else returns false
public static boolean isValidScore(int score) {
if (0 <= score && score <= 100) return true;
else return false;
}
}

Screenshot:

Output:

Here only 7,6,9 are valid so the sum is : 22, average is 7.33.

and i am highlighting the invalid message.

2.

If you wanted to take more than 2 pictures, you need to change the loop condition, and for this we can loose "for " loop

as for(int i=0;i<2;i++) {} //in the place of 2 you can write the the number images you want to take.

Hoping that the above answer will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
CAN YOU PLEASE DO THIS IN JAVA! WILL LEAVE GOOD RATING THANK YOU Modify your program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • Your code should contain appropriate validations and must focus on code optimization. Briefly, explain (150-200 words)...

    Your code should contain appropriate validations and must focus on code optimization. Briefly, explain (150-200 words) the logic of the program and how the code can be   optimized. Modify the code to repeat the program until the user enters “no”. (*I need the logical write out on how the program behaves when there is an input from the user. (I don't need the //comments). import java.util.Scanner; public class Q2 {     public static void main(String[] args)     {         Scanner...

  • Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user...

    Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user for the ten virtual address from the work sheet we did the week before spring break. Once you have it working run it in a script command capturing the output. Make sure the script file has a .txt extension and upload the output. //Java Program import java.util.Scanner; public class virtual{    public static void main(String[] args){    int[] virtualAddressPace={2,1,6,0,4,3,-1,-1,-1,5,-1,7,-1,-1,-1,-1};    Scanner input = new...

  • in Java This program will output a right triangle based on user specified height triangleHeight and...

    in Java This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a character. Modify the given program to output a right triangle that instead uses the user-specified trianglechar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or* Each subsequent line will...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The...

    This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt) (2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Open a new file in your text editor, and start a class that will demonstrate a...

    Open a new file in your text editor, and start a class that will demonstrate a working two-dimensional array: import java.util.Scanner; class TwoDimensionalArrayDemo { public static void main(String[] args) { 2. Declare a three-by-three array of integers. By default, the elements will all be initialized to 0. int[][] count = new int[3][3]; 3. Declare a Scanner object for input, variables to hold a row and column, and a constant that can be used to indicate when the user wants to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT