Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a class SodaCan with methods getsurfaceAr ea () and getvolume (). The

ID: 3840071 • Letter: I

Question

Implement a class SodaCan with methods getsurfaceAr ea () and getvolume (). The height and radius of a soda can object should be specified upon instantiation. TA Initials ________ Implement the class Car with the following properties A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency should be specified upon instantiation, and the initial fuel level should be zero Supply a method called drive that simulates driving the car for a certain distance, which reduces the fuel level in the gas tank. If the car is unable to drive the specified distance, this method should return False. Otherwise drive should return True. Additionally, supply a method called get -gas-level to return the current fuel level and a method called add gas to add fuel back to the tank. An example of these methods in use is as follows: hybrid_car = car (50) #50 miles per gallon hybrid_car. add-gas (20) #Add 20 gallons of fuel if hybrid_car-drive 100): #Drive 100 miles print hybrid_car_get_gas_level() #Display remaining fuel else: print "Not enough gas!" TA Initials ______ Write a class Bug that models a bug that moves along a 1D line. The bug moves either to the right or left. Initially, the bug moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide the constructor method: def__init__(self, initialPosition) and the methods turn (), move (), position () and direction (). Example usage: ant = Bug (10) # starts at position 10 facing right ant .move () #Position is 11 ant turn () #now facing left ant move () #Position is 10 ant move () #Position is 9 print ant position () prints 'g' to the screen print ant direction () #prints ''left" to the screen Write a small test function that uses your class to make the bug move and turn a few times. This test program should print out the actual and expected positions. TA Initials ___________

Explanation / Answer

/** * Created by nagulmeeras on 10/03/17. */ public class SodaCan { private float height; private float radius; public static final double PI = 3.14; /* @height Float height of the SodaCan @radius Float Radius of the SodaCan */ public SodaCan(float height, float radius) { this.height = height; this.radius = radius; } /* @return Double Value of the Surface Area of the SodaCan */ public double getSurfaceArea() { //Below is the formula based calculation for Surface area double surfaceArea = 2 * PI * radius * (height + radius); return surfaceArea; } /* @return Double value of Volume of SodaCan */ public double getVolume() { //Below is the formaula based volume calculation double volume = (PI) * Math.pow(radius, 2) * height; return volume; } } class Car { private double efficiency; private double fuelLevel; /* @efficiency Double Inititial efficiency of the Car measured in miles/gallon @fuelLevel Double Initial fuel level is Zero */ public Car(double efficiency) { this.efficiency = efficiency; this.fuelLevel = 0; } /* @distance Double Distance to be travelled by the Car */ public boolean drive(double distance) { if (distance
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote