Question

Q.5.8 Write short Java code to display the following screen (no need to do it practically using a compiler, just basic coding

Continue? Х ? Continue using the application? Yes No Q.5.10 Discuss the difference between a PRETEST and POSTTEST loop.

Q.5.13 Given the following coding. private String GenerateStars(int x) { String stars = ; if (SALES[x]>=100){ stars = ****

Q.5.14 Discuss any two ways in which you could improve a loop performance. Q.5.15 Given the screenshot below:

BEACH RESORT DEVELOPMENT REPORT UNITS PRICE UNIT 1 R 800000.00 UNIT 2 R 400000.00 UNIT 3 750000.00 UNIT 4 R 480000.00 UNIT 5

PLEASE SOLVE THESE QUESTIONS. USE JAVA FOR CODING.

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

5.8

import javax.swing.JOptionPane;

public class Question5_8 {

   public static void main(String[] args) {

   // Java code to display an input dialog with a message, given title
       String choice = JOptionPane.showInputDialog("Enter {1} to display the vowel count.\nEnter {2} to display the non vowel count."
               + "\nEnter {0} to exit.");

}

}

Output:

Input X ? Enter {1} to display the vowel count. Enter {2} to display the non vowel count. Enter {0} to exit. OK Cancel

5.9

import javax.swing.JOptionPane;

public class Question5_9 {

   public static void main(String[] args) {

   // Java code to display a confirm dialog with a message given title and containing only yes/no buttons and showing question message icon

JOptionPane.showConfirmDialog(null, "Continue with the application? ","Continue? ",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);

}

}

Output:

Continue? Х ? Continue with the application? Yes No

5.10

  • PRETEST loop is a loop structure in which the condition is tested first and if the condition evaluates to true then the statements within the loop are executed whereas a POSTTEST loop is a loop structure in which the statements within the loop are executed first and then the condition of the loop are evaluated.
  • So in a POSTTEST loop, the loop statements are executed atleast once even if the condition is false in the first iteration whereas in PRETEST loop, if the condition is false in the first iteration then the loop statements are not executed at all.
  • So a POSTTEST loop ensures that the loop statements are executed at least once but a PRETEST loop doesn't ensure that the loop statements are executed at least once.

Eg- PRETEST loop:

let i = 10; // set i to 10
// loop that prints the the number from 5 to 1
// since i = 10 > 5, hence the loop is not executed even once
while(i > 0 and i < 5)
{
   Display i;
   i = i - 1;
}

POSTTEST loop:
let i = 10; // set i to 10
// loop that prints the the number from 5 to 1
// the loop will be executed for i = 10, (the first iteration) since the condition is evaluated after the loop statements
// But when the while condition is executed, it returns false, hence the loop is exited.
do
{  
   Display i;
   i = i - 1;
}while(i > 0 and i < 5);

5.13


private String GenerateStars(int x)
{
   String stars = "";

// assuming SALES is an array defined within the class containing the method
   // if statement is used to return the number of stars based on the SALES amount at index x
   // if SALES amount at index x >= 100, then return a string containing 5 starts i.e *****
   // else return a string containing 2 stars i.e **
   if(SALES[x] >= 100){
       stars = "*****";
   }
   else{
       stars = "**";
   }
  
   return stars;
  
}

Add a comment
Know the answer?
Add Answer to:
PLEASE SOLVE THESE QUESTIONS. USE JAVA FOR CODING. Q.5.8 Write short Java code to display the...
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
  • (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectan...

    (NEED FULL CODE PLEASE)write a java program class to calculate and display the areas of 10 rectangles using arrays. * input validation sizes must be between 0-50 inches output to be displayed on the screen and send to an output file. *the output must appear in the following format. rectangle length width area 1    2.0    3.0    6.0 2 - - - - 10 display the rectangle with largest area. rectangle1 area= display the rectangle with smallest area. rectangle2 area=

  • All code will be in Java, and there will be TWO source code. I. Write the...

    All code will be in Java, and there will be TWO source code. I. Write the class  MailOrder to provide the following functions: At this point of the class, since we have not gone through object-oriented programming and method calling in detail yet, the basic requirement in this homework is process-oriented programming with all the code inside method processOrderof this class. Inside method processOrder, we still follow the principles of structured programming.   Set up one one-dimensional array for each field: product...

  • Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a scr...

    Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a screen shot for code. Write clear code with comments and follow coding convention. Comments should include your name, student number and subject code on top of your code Question 1 Create a list to store all the subject codes that you are currently doing at UOW Then use for loop to display it in a table as in the...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • I need help please... Intro to Programming in C – small program 8 Project objective: To...

    I need help please... Intro to Programming in C – small program 8 Project objective: To compile, build, and execute an interactive program using character arrays and string.h functions **Submit source code (prog8.c) through Canvas • One source code file (unformatted text) will be submitted • The file name must match the assignment • The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas • The code must be submitted on time in...

  • ***Please use java code for the question below*** Write a program that calculates the future value...

    ***Please use java code for the question below*** Write a program that calculates the future value of a given investment at a given interest rate for a specified number of years. The formula for this calculation is: value = investmentAmount * (1 + monthly interest rate)years*12 Use text fields for the user to enter the numbers (Investment Amount, Number of Years, and Annual Interest). To get/load data from the textbox, (in this case doubles) use the following structure: (bold are...

  • Program Description: A Java program is to be created to produce Morse code. The Morse code...

    Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • Please use the JAVA code attached as an input to the program that must be created...

    Please use the JAVA code attached as an input to the program that must be created IN JAVA. Instructions of the program: java code: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * */ import java.util.Random; public class Rand_Z3_Exp { /** * @param args the command line arguments */ public static void main(String[] args) {...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

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
ADVERTISEMENT