How do you use power of math. I'm trying to write a calculator to calculate the volume of a cylinder by asking the user to enter the height and radius but when I use pow(2) it doesn't work. I imported java.lang.math class so i dont have to keep using math. for now my code runs just fine since I'm using radius * radius but I would really luv to use the power instead times each other when i have to use higher powers.
import java.util.Scanner; import static java.lang.Math.*; public class Lab2 { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
Write a Java program that calculates the area and volume of a cube, sphere, cylinder, and regular tetrahedron. Your program should obtain the necessary input for each of the objects from the console and output the input, area, and volume of the object. Use appropriate messages to guide the user of your program.
Here what i did, i am not sure if this is what the assignment want, but this is the best method i could come up with
//Khang Le import java.util.Scanner; public class InputAreaVolume { public static void main(String[] args) {
How can i assign current null value to current date, I only what to assign this if the current value coming from database is null otherwise i must use value from database
How do i go about developing a simple arithmetic tester program which can be used to support young children improve their arithmetic skill. The program should accepts string data for the player's name and the number of questions they want to try, which will be entered by the user. The program should take in the following inputs from the user:
The name of the player, so that the game can refer to them by name in messages. The name must be between 2 and 20 characters inclusive.
The number of sums that the user wants to attempt. This number must be a whole number, and be between 2 and 50 inclusive.
The program must check that the values entered fall within the valid ranges. The program must also check that no empty strings are entered for names.
Once the player has entered their name and the number of questions they want to attempt, the game begins. The program must generate sums for the player.
The program should generate one question at a time and display the question for the user. The questions must involve two numbers and be either a multiplication, division, subtraction, or addition. For example, the following are all valid questions:
3 * 4 = ? 8 / 2 = ? 7 + 1 = ? 9 - 8 = ?
The first number, second number, and arithmetic operator (multiply, divide, add, subtract) should all be chosen randomly, the program should Generate a new random number for each of the three parts of each sum. this requires you to choose one of the four symbols based on which random number is returned.
A few checks must be carried out before a generated question is displayed to the user. If the question is an addition question, no checks are required. If the question is a multiplication question, no checks are required. However, checks are required for subtraction and division sums.
If the question is a subtraction question, the program must check that the second number is equal to or smaller than the first number. Whilst the second number is larger than the first number, new numbers should be generated.
I want to be able to use the current date to solve a math problem, specifically as follows:If today is March 17, the math problem of the day should be:
(Month times Day of Month) + 99 = Answer of the Day
(3 x 17) + 99 = 150
How can I create a java script to find the current month and the current day of month, multiple those two together, then add 99 and display the answer as a result.
So I'm beginning to learn java with the book HeadFirst Java. The books says that all a tester class does is create objects of a new type and then use the dot operator...
I don't really understand what a tester class is and what it does ? and what is the Dot operator and how does it work ?
Our instructor gave us a list of steps to complete after creating a Balloon, but I can't get past just creating it. Search results have brought up other Balloon thread, however I couldn't find a topic about issues just creating the balloon.
package myprojects; ublic class BalloonTester { public static void main(String[] args) { Balloon redBalloon = new Balloon("Red Balloon", 100);
(Using an Existing Class: Creating Objects and Calling Accessor and Mutator Methods)
I. The Assignment
This assignment is to write a "test" class (aka: a "driver" class or "client code") that uses the class Balloon.java, available on the class web page.
To use the Balloon class, download it and store it in the src folder of your NetBeans project. Make sure you save it as Balloon.java.
The best way to learn how to use the Balloon class or any other Java class, for that matter - is to consult the documentation, Balloon.html (online). You can also read the javadoc comments that appear just above the class declaration and above each method declaration, which explain what each method does, what the method's parameters are, and what value if any - is returned by the method. The html support pages are generated from these comments.
-Review declaring variables, creating objects, calling methods that return a value vs. void methods, and accessor and mutator methods before beginning. To receive credit for this assignment, you must not modify the Balloon class in any way!
II. Your BalloonTester Class
Your BalloonTester class will have only a single method "main" and will perform each of the following operations, in the exact order listed below. Each operation may be done in one or two statements. Make sure you follow directions faithfully, and note that once you have done step 3, you can copy and paste it to do steps 6, 9, and 12.
1.Create a Balloon object with a name of your own choosing and an altitude of 100 meters.
2.Create a second Balloon object with a name of your own choosing, and specify an initial altitude of -100 meters.
3.Call the accessor methods of the Balloon class to get the name and altitude of each Balloon object. Print the data, one object per line.
4.Make the object you created in step 1 ascend to an altitude of 250 meters.
5.Call the adjustAltitude method to increase the altitude of the object you created in step 2 by 150 meters.
6.Call the accessor methods of the Balloon class to get the name and altitude of each object. Print the data, one object per line.
7.Call the adjustAltitude method to decrease the altitude of the object you created in step 1 by 150 meters.
8.Make the object you created in step 2 descend to the same altitude as the other object. You may assume that the other object is at a lower altitude.
To get credit for step 8., the statement(s) you write must always work, regardless of the actual altitude of the second object. It cannot depend on you knowing the altitude of the second object, but must utilize the fact that the object knows its own altitude. In other words, if you use a literal in any way to set the altitude, it is not correct.
9.Call the accessor methods to get the name and altitude of each object. Print the data, one object per line.
10.Move the object you created in step 1 to an altitude that is four times its current altitude. As in step 8, the statement(s) you write must work for any altitude and may not depend on you figuring out the new altitude beforehand.
11.Attempt to move the object you created in step 2 to an altitude that is 150 meters below its current altitude.
12.Call the accessor methods to get the name and altitude of each object. Print the data, one object per line.
and this is the Balloon.java given:
// File: Balloon2.java // Modified Balloon class has overloaded constructors
/** * A class to represent a hot-air balloon. Balloon objects have a name and an altitude. */ public class Balloon2 { // instance variables private String name ; // name of the balloon private int altitude; // altitude (height) of balloon in meters
I have a login window, which when sucessful will activate a new Applet/JFrame. The problem is that the login window remains in the background under the new JFrame. I want this to diappear. I want to either set the visibility to false, or close it.This is how the new window is started:
if(sucess.equals("flase")){
DBAccess dba = new DBAccess(); dba.setFname(fnameusr); //fnameusr dba.setLname(lnameusr); //lnameusr dba.main(null);
//LogIn.exit(0); }else{ JOptionPane.showMessageDialog(null, "Your credentials were not entered correctly or you may not be authorised to access this system."); System.exit(0); }
When the application starts and the index page is initially loaded, dialog is not shown correctly (panel is not shown) and shows that selected==null. But in debugger prepareSelect seems working correctly and selected is initialised (not null). When I reload page, dialog is shown correctly.
Below are facelets for the page composition and backing bean code.
Register.xhtml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"
Write a Java code of the method startsWithCount that takes an array of strings words and a String S. The method should return an integer that is the number of strings that starts with S.
For example if:words = { "All", "Arab", "size", "Almond", "Allowed", "here"} and S= "All", then the method should return 2
PHP Code:
public class StringwithCount { public static void main (String[]args) { String strings[] = { "All", "Arab", "size", "Almond", "Allowed", "here"}; String output= ""; for ( int i = 0; i < words.length; i++) { if (words[i].startsWith("s")) c + +; }
I am trying to create a user defined Exception. I am using a hard-coded value in the constructor of circle class at the time of object creation.But in the constructor this value becomes 0.
import java.lang.Exception; import javax.swing.*; class InvalidRadiusException extends Exception{ private double r; public InvalidRadiusException(double radius){ r = radius;
[Code] ....
Due to this its always generating InvalidRadiusException even if i am supplying a non-zero non-negative value.
Recently we updated out database and we changed our tables' and columns' names, I'm developing an adf application with EJB3.0 the question is that the new column names start with a number (eg. 001U_ID), its a kind of encoding the names of the tables so no one can modify the values.
When I create a query on the table it is throwing an exception:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'U_ID'.
I think the problem is that the EJB3.0 doesn't recognize column names starting with a number!!! What can I do to solve this issue?
public class PondRadius { public static void main (string[] args) { //Calculate the radius of a pond //which can hold 20 fish averaging 10 inches long int fishCount = 20;//number of fish in pond int fishLength = 10;// Average fish length int inchesPerFoot = 12;//number of inches in one foot
[Code] ....
And here is the error or exceptions i received
C:javaLesson1>javac PondRadius.java PondRadius.java:23: error: ')' expected System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch es long you need a pond with an area of " +
I have to print points on a circle in increments of -0.1, but when I use a number larger than 1.3, the list stops at 0.1 larger than negRadius, and I don't know why. (Assume the center is (0,0))
public class PointsOnACircleV1 { public static void main(String[] args) { double radius = 1;
public class Regextest { public static void main(String a[]){ String stream = "ab34ef"; Pattern pattern = Pattern.compile("d*")
[code]....
My question is: The methods start()will give the indexes into the text where the found match starts .d*, this means if a number found.index must be returned. Why doesn't it print 3? 12345
I want to get the max volume from a file that I stored in an arraylist but it don't know if this is the way to do it. also I don't know how to print the method in the main method. here is the method that will get the max volume
public Shape3D maxVolume(ArrayList<Shape3D> shapes ){ Shape3D currentMax; int currentMaxIndex = 0; for ( int i = 1; i < shapes.size(); i++)
[Code] ....
This is my shape3D class
public abstract class Shape3D implements Comparable<Shape3D> { private String type; public double radious; public double height;
My program never compiled. the code is for a dialog box that calculates the volume of a cylinder, and i know there are simpler codes to do it, but this is the format my teacher wants...Heres the code:
import javax.swing.*; public class classTwo { public static void main(String[] args) { String rad, hei, vol; Scanner joe = new Scanner(System.in); System.out.println ("Hi, please enter a radius."); double rad = joe.nextLine(); System.out.println ("Enter a height.");
Write a program that draws 20 circles, with the radius and location of each circle determined at random...... Two circles overlap if the distance between their center points is less than the sum of their radii...
There may be many problems with the code in general but what I'm struggling with is the distance and the totalradius portion. Visually, its inaccurate.
import java.awt.*; import javax.swing.*; public class CircleTest extends JPanel { Circle []circles; Circle []circleCenter; Circle []all; private int distance, totalradius, dx, dy; private int radius,x,y;
I am currently building a java music player and need getting the volume control to work. I want to be able to set the computers volume directly using an integer. I've created a slider and put the value into an integer. The part that I am having trouble with is getting the volume to work.
I am doing an assignment that is asking for the user to put in the radius of a circle and the program figures out the area, diameter and circumference. It is using 2 different java programs to accomplish this. One with the info on how to get area, diameter and circumference and one is the demo that runs the program. I keep getting errors on my demo.
// Circle Class public class Circle { private double rad; private double Pie; private double area; private double diameter;
(Corner point coordinates) Suppose a pentagon is centered at (0, 0) with one point at the 0 o’clock position. Write a program that prompts the user to enter the radius of the bounding circle of a pentagon and displays the coordinates of the five corner points on the pentagon. Here is a sample run:
Enter the radius of the bounding circle: 100 The coordinates of five points on the pentagon are (95.1057, 30.9017) (0.000132679, 100) (-95.1056, 30.9019) (-58.7788, -80.9015) (58.7782, -80.902)
What we know , we know both the radius of the circle(user inputted) and the side of the pentagon from formula (double side = 2 * radius * Math.sin(Math.PI/5)) .We also know that one point is (0 .100) Also i know that the distance between 2 points is Math.sqrt(Math.pow(x1 - x2 ,2) - Math.pow(y1 -y2 ,2)) .
There might be other ways to solve it but this is my best bet trough i dont remember how to solve linear equations of the form x^2 + y^2 = - radius and radius ^2 = x^2 + (y - 100) ^ 2..
The solution i found is using the radius from the center to the point we want to find out and using the radius to the point we already know ( 0 .100) but i have to solve that damn equation first ...