Question

This same solution except that you need to use the Dialog boxes option instead of Scanner...

This same solution except that you need to use the Dialog boxes option instead of Scanner class option

Planting Grapevines

A vineyard owner is planting several new rows of grapevines, and needs to know how many grapevines to plant in each row. She has determined that after measuring the length of a future row, she can use the following formula to calculate the number of vines that will fit in the row, along with the trellis end-post assemblies that will need to be constructed at each end of the row:

            

The terms in the formula are:

V is the number of grapevines that will fit in the row.

R is the length of the row, in feet.

E is the amount of space used by an end-post assembly, in feet.

S is the space between vines, in feet.

Write a program that makes the calculation for the vineyard owner. The program should ask the user to input the following:

The length of the row, in feet

The amount of space used by an end-post assembly, in feet

The amount of space between the vines, in feet

My current code is

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double R, E, S;
int V;
System.out.printf(" Enter the length of the Row(in Feet) ");
R=sc.nextDouble();
System.out.printf(" Enter the amount of space used by end post assembly(in Feet) ");
E=sc.nextDouble();
System.out.printf(" Enter the amount of space between the vines(in Feet) ");
S=sc.nextDouble();
V = (int)((R - (2.0*E)) / S);
if (V < 0) //Validate of the entered values are correct
System.out.printf("Error!!.. Seems you have not entered one of avalues correct.");
else
System.out.printf(" Number of grape wines that will fit in the row would be %d", (int)V); //Converting from decimal to Int since the number of vines will be in whole number.
  
}
}

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

Here is the completed code for this problem. Just changed all input/output to use JOptionPane dialog boxes only, changed nothing else. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Main.java

import javax.swing.JOptionPane;

public class Main {

      public static void main(String[] args) {

            double R, E, S;

            int V;

            // reading input using JOptionPane window and converting to double

            R = Double.parseDouble(JOptionPane

                        .showInputDialog("Enter the length of the Row(in Feet)"));

            E = Double

                        .parseDouble(JOptionPane

                                    .showInputDialog("Enter the amount of space used by end post assembly(in Feet)"));

            S = Double

                        .parseDouble(JOptionPane

                                    .showInputDialog("Enter the amount of space between the vines(in Feet)"));

            V = (int) ((R - (2.0 * E)) / S);

            if (V < 0) // Validate of the entered values are correct

            {

                  // displaying output using JOptionPane window

                  JOptionPane

                              .showMessageDialog(null,

                                           "Error!!.. Seems you have not entered one of avalues correct.");

            }

            else {

                  // displaying output using JOptionPane window

                  JOptionPane.showMessageDialog(null,

                              "Number of grape wines that will fit in the row would be "

                                           + (int) V);

            }

      }

}

/*OUTPUT*/


Input Enter the length of the Row(in Feet) ? 100 Cancel OK X

Input Enter the amount of space used by end post assembly(in Feet) ? 201 OK Cancel

Input X Enter the amount of space between the vines(in Feet) ? Cancel OK LO

Message Ci Number of grape wines that will fit in the row would be 12 ок X

Add a comment
Know the answer?
Add Answer to:
This same solution except that you need to use the Dialog boxes option instead of Scanner...
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
  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka...

    in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka the one that says :               public class SmartString implements SmartStringADT at the beginning //for SmartStringTest.java: import static org.junit.Assert.*; import org.junit.Test; public class SmartStringTest {    //Test insert method    @Test    public void testinsert1() {        SmartString evaluator = new SmartString();        evaluator.insert(0, "Hello");        evaluator.insert(4, ", how are you?");        assertEquals("Hello, how are you?", evaluator.toString());    }   ...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • You are to prepare a tax return using the following information. You will need to use...

    You are to prepare a tax return using the following information. You will need to use Form 1040, Schedule B if applicable, you determine (Read requirements in text). John Brown, age 53, (social security number 554-78-4556) is single and is supporting his 18 year old son, David (social security number 444-55-7777). David is a student at MirMonte High School. They live in a rented home at 1245 West 5Th Street, Coalinga, CA. John is employed as a engineer and received...

  • Please create a class in Java that completes the following conditions MorseTree.java /* This program will...

    Please create a class in Java that completes the following conditions MorseTree.java /* This program will read in letters followed by their morse code * and insert them properly in a tree based on the amount of symbols * it has and whether they are left or right descendent. Finally * it prints a few certain nodes. */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class MorseTree {    public static void main(String[] args) throws FileNotFoundException {        //...

  • I have Majority of the code written but I just need to implement the <,>,and =...

    I have Majority of the code written but I just need to implement the <,>,and = sign in the code. I have posted the instructions for the whole code. I will add what I have at the end. Objectives: Implement basic class concepts in Java Implement inheritance with super and sub-classes Implement basic polymorphism concepts Problem: The TARDIS has been infected by a virus which means it is up to Doctor Who to manually enter calculations into the TARDIS interface....

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

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