import javax.swing.JOptionPane; import java.util.*; import java.text.DecimalFormat; import java.util.StringTokenizer; public class ShelbyHarms_3_03 { public static void main (String [] args) { double a, b, c; //Input sides of triangle double x; //Perimeter of triangle double area; //Area of triangle
[Code] .....
Here are the errors:
ShelbyHarms_3_03.java:39: error: variable x might not have been initialized JOptionPane.showMessageDialog(null, formatter.format(x)); ^ ShelbyHarms_3_03.java:42: error: variable area might not have been initialized JOptionPane.showMessageDialog(null, formatter.format(area)); ^ 2 errors
I've been having trouble with this code for about a week and I've finally got it down to one error. Here is the code:
import java.util.Scanner; public class Triangle { public static void main (String[] args) { Scanner Console = new Scanner(System.in); System.out.print("Please enter the three lengths of your Triangle: "); double a = console.nextDouble();
[Code] ....
And here is the error:
Triangle.java:30: error: class, interface, or enum expected } // End class ^ 1 error
I'm doing a problem where the area of a triangle is returned (if valid). However, I want to return a message (i.e. 'triangle is not valid) if the triangle is invalid.
I'm not sure how to go about to doing this as my method (called area) will only let me return doubles. Possible to return a string in an else within my area method?
public class MyTriangle { public static void main(String[] args) { //triangle is valid if the sum of any two sides is bigger than the third System.out.println(isValid(3, 4, 5)); System.out.println(area(543, 4, 5));
I've been given a school assignment that reads, "Rewrite the main class Geometry so it takes in the dimensions for the triangle and ellipse as user inputs and create a Triangle and an Ellipse class. Use the appropriate variable types, constants, variable names and computational formulas.
Triangle class will have a computePerimeter and a computeArea methods Ellipse class will have a computeArea method Create Report class
• Create a method createReport that takes the values returned from Triangle and Ellipse and combines them in the following message and displays it. Format the values so that they have 2 decimals.
“The triangle has a perimeter of [perimeter] with an area of [area] while the ellipse has an area of [area]”
• Create a method switchReport that takes the original string from createReport and changes the message to display using the available methods in the String class
“The ellipse has an area of [area] while the triangle has an area of [area] with a perimeter of [perimeter]”"
I've run into a problem when creating the createReport method. Everytime i run it i get incorrect values for the perimeter and area (namely i get zero every time).
my code is as follows:
public class Triangle { public double base; public double height; public double hypotenuse; private double tArea; private double perimeter; public Triangle() { base = 0; height = 0; hypotenuse = 0;
[code]....
For the triangle class and
public class Report { Triangle tri2 = new Triangle(); Ellipse eli2 = new Ellipse(); public Report() { } public void createReport() { System.out.println("The triangle has a perimeter of "+tri2.computePerimeter() +" with an area of " +tri2.computeTArea() +" while the ellipse has an area of " +eli2.computeEArea() ); }
for the report class.the Geometry class allows you to input values and if i skip the report and simply print the perimeter and area they are correct. However with the report class it simply gives me zeros.
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input rectangle. All methods should be tested in the runner class.
This is my code:
import java.util.Scanner; public class Rectangle { double length; double width; public Rectangle() {
[Code] ...
What have I done??? I have created this program using the few different resources with which I am supplied, but I don't understand the resources.
package areatest; import javax.swing.JOptionPane; public class AreaTest {
public static double areaTriangle (double length, double width){ //How to calculate the area of a triangle return .5f * length * width;
[Code] .....
When I try to get the area of a rectangle it gives me 9 no matter what input I give it. When I try to get the area of a triangle it gives me .5 no matter what input I give it. Same with the circle but it always gives me 12.56370...
I started with finding the area of a triangle, but now I'm trying to ask a user what kind of shape they want the area for, then ask questions to get the area. I can't figure out how to take the shape a person types to go to a certain case. It also says shape hasn't been initialized. I don't know how to do that.
import java.util.Scanner; public class TriangleArea { static Scanner sc = new Scanner(System.in); public static void main(String[] args){ char shape; String text = "Do you want to find the area of a triangle, square, rectangle, or trapezoid?"; System.out.print("Text"); switch(shape){
Basically its a program where a user is prompted to enter the length of all three sides of a triangle and the program calculates the area by herons formula and can tell if the triangle is equilateral or Pythagorean. I am having trouble entering a formula to where all three enter sides cant possibly be a triangle. Here is my Program. Where the '?' is stated.
import java.util.Scanner; public class Triangle { public static void main(String[] args){ double a; double b; double c; double s; double x; double area;
I am having trouble getting my main triangle program to run. My teacher gave us a sample program, so I tried running his, and it doesn't run either.
Here is the class:
import java.util.Scanner; public class ShelbyHarms_3_06_Triangle { private double sideA, sideB, sideC; // Instance variables, numbers for area and perimeter static Scanner console = new Scanner(System.in); // Establish keyboard
[Code] .....
My errors for the main program(the class has no errors) are:
helbyHarms_3_06.java:37: error: cannot find symbol theSides.getSides(); ^ symbol: variable theSides location: class ShelbyHarms_3_06
I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?
public class circleAre{ double radious; void putData(double radi){ radi = radious;
Here is the program I wrote for calculating the circumference of a circle.
//circumference.java //program that calculates the area and circumference of a circle import java.util.Scanner; //program uses class scanner public class circumference{ //main method begins execution of Java application public static void main(String args[]){
[Code] .....
Even though my code compiles and runs without any errors, the program doesn't calculate the circumference.
This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....
I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.
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) {
I'm creating a program that will compile and run another java program:Lets say I have a program in directory
D:HelloWorldsrc and compiled program will be in D:HelloWorldin inside src and bin is a folder hello (that's a package)
package hello; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); System.out.println("Hello World"); } }
This program will be run by another program (that's the program that I am creating).Here is the code of my program:
package runnercompiler; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; public final class RunnerCompiler {
For this week's assignment, I am supposed to create a java program that encrypt's a user's sentence, outputs the encrypted message, then decrypts the message, outputting the user's original message.
This is what I have so far. It doesn't compile the last few lines since that is not correct Java syntax.
Java Code:
import java.util.Scanner; import java.io.*; public class Decrypter { public static void main(String[] args) { String sentence; final char REAL_ALPHA[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
[Code] .....
So you can see I have "realAlpha" which are regular letters of the alphabet, and "codeAlpha" which are the letters I want to encrypt with. I want 'a' equal to 'z,' 'b' equal to 'y', 'c' equal to 'x' and so forth in that sort of reverse order, you know? So the word "apple" would encrypt into "zkkov."
I am stuck as to how to replace the letters in this way. You can see I tried fumbling with sentence.replace to switch the letters out between the two arrays. Also, I only barely understand arrays.
I have my CheckerboardViewer done, my component is what I need finishing. My final product needs to be a checkerboard with alternating red and grey squares but the background is already grey. My code for the Viewer is:
import javax.swing.JFrame; public class CheckerBoardViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("CheckerBoardViewer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); CheckerBoardComponent component = new CheckerBoardComponent(); frame.add(component); frame.setVisible(true); } }
The requirements are as follows:Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:
A. Set the day.
B. Print the day.
C. Return the day.
D. Return the next day.
E. Return the previous day.
F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
G. Add the appropriate constructors.
H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.
I. Write a program to test various operations on the class Day.Should I break down my day.java into several separate classes, one for each of the sections (previous, next, etc)?
import java.util.*; public class MyDay { static Scanner readinput = new Scanner(System.in); String day; public MyDay(String day) { day = "Sunday";
[code]....
Ideally I would like to create a Gui that would have someone type in the day, and then press a button to return the next day, prior day, or have a text input to test for adding X number of days.
I was given the assignment of creating a number to word program for my first college java programming homework.
Here is what I have created so far :
import java.util.*; public class PrintNumberInWord { // saved as "PrintNumberInWord.java" public static void main(String[] args) { int number = 5; Scanner sc = new Scanner (System.in); { System.out.println ("Enter a number"); System.out.println(" "); if (number == 1) {
[Code] .....
The first lines were made for us so we could follow a guideline, however, no matter what I type the command prompt displays 5 to me, I know thats because 5 is defined in the beginning but backspacing 5 causes the program not to work at all, how can I get this program to work properly?