Question

I was not sure how to update this question I posted earlier, but I need to...

I was not sure how to update this question I posted earlier, but I need to make a code with these parameters in it. I want to try and have the code take the sun and the planets of the solar system and allow the user to pick one of the planets and print out the orbital period around the sun for that planet. I just want the code to try and meet these parameters and be able to print out the orbital period of the planets. Is this possible? If not, then can someone help me fine-tune it and create it? The code/language is Java programming

a. at least 5 variables and they cannot all be of the same type

b. enumerated data type

c. a decision structure

d. loop structure

e. data validation

f. 2 methods (1 void and 1 value returning).

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

According to your question the following program will take the Planet name as input and give the Orbital Speed of that planet as output.

The Code is as follows:

import java.util.Scanner;

enum Planet                                   //Enumerated datatype
{
   Mercury("87.97"),Venus("224.70"),Earth("365.26"),Mars("686.98"),Jupiter("4332.82"),Saturn("10755.70"),Uranus("30687.15"),Neptune("60190.03");  
   private String Orbit;

                                                 // Function Returning One value
    public String getOrbit()
    {
        return this.Orbit;
    }

                                                // Non Returning Function
    private Planet(String Orbit)
    {
        this.Orbit = Orbit;
    }
}

class Main {

   public static void main(String[] args) {
   
     String s;
     Planet[] planets = Planet.values();
   
     Scanner in = new Scanner(System.in);

     System.out.println("Enter the Planet Name:");
     s = in.nextLine();
   

     for (Planet planet : planets)   //Loop structure
       {
         String p = planet.name();
       
         if(s.equals(p))                 //Decision Structure
         {
         System.out.println("Orbital Period for " + planet.name() +
                        " is = " + planet.getOrbit() );
         }
       
       }
    }
}

In the above solution i have created an enum named as Planet, this consist of the planets name along with their orbital speed. Then, in the main program i have take the input from user, after that i have checked with the enum values for that particular planet and return the orbital speed for that planet.

Add a comment
Know the answer?
Add Answer to:
I was not sure how to update this question I posted earlier, but I need to...
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
  • I posted this earlier but the answer did not provide three methods. Can you please post...

    I posted this earlier but the answer did not provide three methods. Can you please post the answer with three methods. Also if possible can it be in C#. Java is also fine but please have three methods in the code. Also the main method. Exercise #3 Guess the Number Write a "Guess the Number" game that randomly assigns a secret number [1,20] for the user to guess. I recommend hard coding your secret number at first to make testing...

  • *This question was posted earlier but I want to make sure my code differs from the...

    *This question was posted earlier but I want to make sure my code differs from the other answer* CS50 Assignment 3 and Assignment 4 (Both Due By Sunday March 29 11:59 PM) Assignment 3: Bank Application In a recent lecture, we discussed getting input from the user by using the scanf() function. For your reference, I have included a simple example of using scanf() below: scanf() example: #include int main(void) { int number; printf("Enter a number: "); //prompt the user...

  • I want to have a code that can pick whichever two planets in the solar system and find the distance of them no matter where in their orbit they are, but I keep getting errors. Can someone please help...

    I want to have a code that can pick whichever two planets in the solar system and find the distance of them no matter where in their orbit they are, but I keep getting errors. Can someone please help me fix it? f rom scipy import exp, pi, absolute, linspace import matplotlib. Ryplot as plt planet-I input ('Which planet do you want to pick for planet 1?") planet_2 input ('which planet do you want to pick for planet 27') distance...

  • Can someone help me with this question, I do not know how to do the long-distance...

    Can someone help me with this question, I do not know how to do the long-distance in excel. If you could show me the Excel data as well that would be great. retention 10.18 The following are the average distances of the planets in the solar system from the 25 Distance (millions of miles) 47.163 67.235 92.960 141.61 313.00 483.60 886.70 1783.0 2794.0 3666.0 Planet No. Planet Mercury Venus Earth Mars Asteroids Jupiter Saturn Uranus Neptune Pluto 4 10 (a)...

  • Hi, this is in reference to a question that I had posted earlier which was, (Imagine...

    Hi, this is in reference to a question that I had posted earlier which was, (Imagine that your Learning Team has received funding to study changes in sexual attitudes over time. Your task is to design a developmental research study to investigate this issue. Your team will outline one of the following: a cross-sectional study, longitudinal study or sequential study. Identify which type of design your team decided to use and explain why you decided on this method. I believe...

  • C++ code do while loop issue. The code I posted works but when it prompts the...

    C++ code do while loop issue. The code I posted works but when it prompts the user if they want to try against with another sentence, it only takes the Y and goes straight into another loop, without letting me enter a new sentence. I need it to be able to take the Y response from a user and then let me enter another sentence. do { cout<<"Enter a sentence:"; //user input sentence cin.getline(str,80); int wordsCount = 0; for (int...

  • I really need help with these two questions. I posted earlier but I didn't get any assistance. please help T...

    I really need help with these two questions. I posted earlier but I didn't get any assistance. please help The shift register below has shift, load and clock inputs as shown. The serial data input is tied 3) High (1). The state of the data input lines is indicated. Determine the data out waveform in reference to the clock pulses.ope) D, D. 0 0 SHIFT/LOAD SRG 4 Serial Data In Data Ost CLK CLK SH/LD Serial data Out Show a...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • I posted this question earlier but realized that the code was not easy to test since...

    I posted this question earlier but realized that the code was not easy to test since it was just screenshots and not text so I am reposting it: I'm very new at working with file streams, and I'm having trouble with a HW assignment I have to work on. For the assignment I have to read an input file named "MagicSquaresIn.txt" (included at the bottom) and I have to check whether they are normal, associative, and panmagic. To check that...

  • RE-POSTED - Computer Science staff, I need this question answered. It will determine a pass or...

    RE-POSTED - Computer Science staff, I need this question answered. It will determine a pass or a fail. Its very imortant that this and the other questions posted are answered 100% Thank you. 13 - Template C++ Advance Please Only answer assignment if your code is 100%. When pasteing your code use text so I may copy and paste into visual studio. The code and questions must be answered 100% correct and works. Thank you. Programming Assignment Convert the int...

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