Question

In: Computer Science

Hi all! Looking for good explanations as to how this problem is solved without the constructor....

Hi all! Looking for good explanations as to how this problem is solved without the constructor.

1. In this problem, we will write and use a static class (remember static classes do not operate on an object.) Your weight is actually the amount of gravitational attraction exerted on you by the

Earth. Since the Moon’s gravity is only one-sixth of the Earth’s gravity, on the Moon you would weigh only one-sixth of the Earth’s gravity. Write an application that inputs the user’s Earth weight as an integer and outputs her/his weight on the Moon, Mercury, Venus, Jupiter or Saturn. Use the values from this table.

Planet/Moon

Multiply the Earth Weight by

Moon

0.1666

Mercury

0.4

Venus

0.9

Jupiter

2.5

Saturn

1.1

  • You will have a tester class and a planet weight calculation class.

  • Create a static class for planet weight calculation. (A class is considered static if all of its

    methods are static.)

o Youdonotwriteaconstructor(thinkaboutwhy).
o Write a different method for each of the planets. Each method will accept as input the

“earth” weight. It will return the calculated planet weight. Each method should multiply the “earth” weight supplied as an argument by corresponding planet conversion factor to get the equivalent “planet” weight.

o Use constants for your weight conversion factors (the table, above). • Create a tester class

o Get user input with a scanner object
o Ask the user to enter the “earth” weight.
o Call each of the methods in the static class and print the results.

Solutions

Expert Solution

SOLUTION-
I have solve the problem in Java code with comments and screenshot for easy understanding :)

CODE-

PlanetWeight.java

//static class definition
public class PlanetWeight {
    //static function to calculate corresponding value on the planet
    public static double wieghtOnMoon(double weight){
        //returning calculated value on the planet
        return weight*0.1666;
    }
    //static function to calculate corresponding value on the planet
    public static double wieghtOnMercury(double weight){
        //returning calculated value on the planet
        return weight*0.4;
    }
    //static function to calculate corresponding value on the planet
    public static double wieghtOnVenus(double weight){
        //returning calculated value on the planet
        return weight*0.9;
    }
    //static function to calculate corresponding value on the planet
    public static double wieghtOnJupiter(double weight){
        //returning calculated value on the planet
        return weight*2.5;
    }
    //static function to calculate corresponding value on the planet
    public static double wieghtOnSaturn(double weight){
        //returning calculated value on the planet
        return weight*1.1;
    }
}

-----------------------------------------------------

PlanetWeightTester.java

//importing required class
import java.util.Scanner;
//tester class definition
public class PlanetWeightTester {
    //defining main method
    public static void main(String[] args) {
        //creating scanner object to get user input
        Scanner input=new Scanner(System.in);
        //variable to store the intermediate values
        double weightOnEarth,weightOnPlanet;
        //asking user tot enter the weight
        System.out.print("Enter the weight on Earth: ");
        //storing the user input into the variable      
        weightOnEarth=input.nextFloat();
        //calling function to get corresponding weight on the planet
        weightOnPlanet=PlanetWeight.wieghtOnMoon(weightOnEarth);
        //printing the message for the user with calculated value
        System.out.println("Weight "+weightOnEarth+" on Earth is equal to "+weightOnPlanet+" on Moon");
        //calling function to get corresponding weight on the planet
        weightOnPlanet=PlanetWeight.wieghtOnMercury(weightOnEarth);
        //printing the message for the user with calculated value
        System.out.println("Weight "+weightOnEarth+" on Earth is equal to "+weightOnPlanet+" on Mercury");
        //calling function to get corresponding weight on the planet
        weightOnPlanet=PlanetWeight.wieghtOnVenus(weightOnEarth);
        //printing the message for the user with calculated value
        System.out.println("Weight "+weightOnEarth+" on Earth is equal to "+weightOnPlanet+" on Venus");
        //calling function to get corresponding weight on the planet
        weightOnPlanet=PlanetWeight.wieghtOnJupiter(weightOnEarth);
        //printing the message for the user with calculated value
        System.out.println("Weight "+weightOnEarth+" on Earth is equal to "+weightOnPlanet+" on Jupiter");
        //calling function to get corresponding weight on the planet
        weightOnPlanet=PlanetWeight.wieghtOnSaturn(weightOnEarth);
        //printing the message for the user with calculated value
        System.out.println("Weight "+weightOnEarth+" on Earth is equal to "+weightOnPlanet+" on Saturn");
    }
}

SCREENSHOT -

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

HI There, there is no solution for a problem that I am looking for. Advanced Accouting...
HI There, there is no solution for a problem that I am looking for. Advanced Accouting - Chapter 4, problem 30. Can you please assist? Thanks. Posada Company acquired 7,000 of the 10,000 outstanding shares of Sabathia Company on January 1, 2013, for $840,000. The subsidiary’s total fair value was assessed at $1,200,000 although its book value on that date was $1,130,000. The $70,000 fair value in excess of Sabathia’s book value was assigned to a patent with a 5-year...
Shirt inherits clothing. In the Shirt constructor, how is the Clothing default constructor called? (Select all...
Shirt inherits clothing. In the Shirt constructor, how is the Clothing default constructor called? (Select all that apply) Group of answer choices super(); Clothing(); Clothing.Clothing() Make no explicit call Shirt inherits Clothing. In the Shirt constructor, how is a Clothing constructor with one int parameter called? For the answer, assume that an int variable called "myInt" is in scope. Group of answer choices Clothing.Clothing(myInt); Clothing(myInt); super(myInt); Make no explicit call Shirt inherits Clothing. Both classes have their own version of...
Show all your calculations. Answers without explanations or calculations will receive a mark of zero. (This...
Show all your calculations. Answers without explanations or calculations will receive a mark of zero. (This question is worth 20 marks in total.) Telstra is a monopolist. Suppose it operates at the market with demand P = 5 – Q and has the following cost structure: MC=AC = 1. Draw the market demand curve and the marginal cost curve on the graph with Q on X-axis. (Include a large and accurate graph). d. Suppose that now Telstra can identify each...
Please answer ALL parts of the question fully with detailed explanations. #Q5 a)Looking at the rat’s...
Please answer ALL parts of the question fully with detailed explanations. #Q5 a)Looking at the rat’s heart, how does the mammalian heart differs from those of reptiles? And from those of fishes? How similar is it to a bird’s heart? b)What advantage has the mammalian heart over the reptilian heart? Use diagrams if necessary. c) Compare & contrast both the skeletal systems and digestive systems individually in pigs, cats, and sheep. d) pig vs cat : What is the length...
PROBLEM IV On a separate sheet, prepare general journal entries, without explanations, for the merchandising transactions...
PROBLEM IV On a separate sheet, prepare general journal entries, without explanations, for the merchandising transactions listed for Lowell Company. Assume use of the perpetual inventory system and use the NET method. May 1 Sold merchandise to Cento Company for $1,200, terms 2/10,           n/30, goods cost $800.      2   Purchased merchandise from Source Corporation for $3,000,           terms 2/10, n/30.      3   Gave credit to Cento Company for merchandise returned, $200. Cost of           goods returned were $120....
Provide a solution to this problem. Any ideas on how it can be solved.   Comprehensive problem...
Provide a solution to this problem. Any ideas on how it can be solved.   Comprehensive problem (discussion board): •        Current Accounts –       2009: CA = $4,400; CL = $1,500 –       2008: CA = $3,500; CL = $1,200 •        Fixed Assets and Depreciation –       2009: NFA = $3,400; 2008: NFA = $3,100 –       Depreciation Expense = $400 •        Long-term Debt and Equity –       2009: LTD = $4,000; Common stock = $500 –       2008: LTD = $3,950; Common stock = $400 •        Income Statement –       EBIT = $2,000; Taxes = $300 –       Interest Expense...
Give examples of how some countries have solved the problem of migration?
Give examples of how some countries have solved the problem of migration?
Please answer this with a thorough explanation and a solution on how you solved the problem...
Please answer this with a thorough explanation and a solution on how you solved the problem so I can understand this lesson. Thank you very much for helping. Situation: At 6:00 a.m., A one liter Plain NSS solution was started. It is to run for 18 hours. however, after 6 hours, the IV had to be stopped and transferred to another site. After an hour the IV infusion was resumed. 3.1. How much of the solution was consumed 6 hours...
Hogg's Probability and Statistical Inference (9th Edition) - Problem 1.4-20E - How is this problem solved?...
Hogg's Probability and Statistical Inference (9th Edition) - Problem 1.4-20E - How is this problem solved? Hunters A & B shoot at a target with probabilities of p1 and p2, respectively. Assuming independence, can p1 and p2 be selected so that P(zero hits)=P(one hit)=P(two hits)?
Hi all, I'm looking for somebody 40+ years old to answer the following questions for my...
Hi all, I'm looking for somebody 40+ years old to answer the following questions for my psych class: 1. Please describe racial relations when you were growing up. What do you particularly remember about different races in your childhood or early adulthood? 2. How have race relations changed in your lifetime? How would you describe issues of race today compared to when you were younger? 3. What do you think race relations will be like in the future? Please note...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT