473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Geometry calculator

This was an assignment for our JAVA class

I am still a beginner and my code keeps getting errors, and I am so confused. I've tried every different way I can think of, can someone please take a look and point out some of the errors. Even just point me to the right direction. I've been working on this for 3 days. HELP!!!!!

Write a Geometry Calculator that computes the perimeter and area of the following
objects:
(a) Trapezoid (general case)
(b) Triangle (general case)
(c) Circle
Input values and formulas for area and perimeter are given in the following table:
Object Input values Area (A) Perimeter (P)
Trapezoid a = longer parallel
side
c = shorter parallel
side
b = side
d = side
( )
,
4( )
( )( )
( )( )
a c Q
A a c
a c
Q a b c d a b c d
a b c d a b c d
+
= ≠

= + − + − − + ×
+ − − − + + +
P=a+b+c+d
Triangle a = side
b = side
c = side
( )( )( ),
( )/2
A ss a s b s c
s a b c
= − − −
= + +
P =a+b+c
Circle r = radius
A = r2π P = 2rπ

The program has to be based on GUI helps the user to select options, enter input data, and present results. Feel free to organize and beautify your program according to your taste.If the user clicks the help button, the program should generate a help screen. If the user clicks the start button, the program should generate the geometric calculator options screen shown in Fig. 2. The list of options is: trapezoid, triangle, circle. Figure 3 shows an example of calculation of the area and perimeter of triangle. The user enters inputs (a,b,c) and then clicks the Calculate button. After that the results appear in the area and
perimeter fields. If the input values are incorrect (not positive numbers, or a=c for trapezoid, or the sum of two sides of triangle is less then or equal to the third side of triangle) your program should open an error message window and display an appropriate error message. For all geometric objects the output should be the same (area and perimeter).

__________________________________________________ _______

This is what I have so far


import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.border.*;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.*;
public class TriangleCalculator extends JFrame implements
ActionListener {
public static final int WIDTH = 250;
public static final int HEIGHT = 250;
public static void main(String[] args)
{
TriangleCalculator gui = new TriangleCalculator();
gui.setVisible(true);
}

///// Create the selectPanel on buttonPanel/////

// selectPanel contains the selectMenuBar
JPanel selectPanel = new JPanel();
buttonPanel.add(selectPanel, BorderLayout.NORTH);
selectPanel.setLayout(new GridLayout(3, 1));
selectPanel.setBackground(Color.LIGHT_GRAY);
// Create the selectMenuBar in the first grid of selectPanel
JMenuBar selectMenuBar = new JMenuBar();
selectPanel.add(selectMenuBar);

// Create the selectMenu in selectMenuBar
JMenu selectMenu = new JMenu("Select Figure");
selectMenuBar.add(selectMenu);

// Create the circleMenuItem in selectMenu
JMenuItem circleMenuItem = new JMenuItem("Circle");
circleMenuItem.addActionListener(new CircleListener());
selectMenu.add(circleMenuItem);

// Create the trapezoidMenuItem in selectMenu
JMenuItem trapezoidMenuItem = new JMenuItem("Trapezoid");
trapezoidMenuItem.addActionListener(new TrapezoidListener());
selectMenu.add(trapezoidMenuItem);

// Create the triangleMenuItem in selectMenu
JMenuItem triangleMenuItem = new JMenuItem("Triangle");
triangleMenuItem.addActionListener(new TriangleListener());
selectMenu.add(triangleMenuItem);


//Create the input textfields
jtfInput_a = new JTextField(10);
jtfInput_b = new JTextField(10);
jtfInput_c = new JTextField(10);
inputPanel.setLayout(new GridLayout(2,3));

//first row
inputPanel.add(new JLabel("a", JLabel.CENTER));
inputPanel.add(new JLabel(" "));
inputPanel.add(new JLabel("b", JLabel.CENTER));


//Create solve panel with the button
SolvePanel = new JPanel();
JButton solveButton = new JButton("Calculate.");
SolveButton.addActionListener(this);
SolvePanel.add(SolveButton);
biggerPannel.add(solvePanel, BorderLayout.CENTER);

//Create result panel with title and grid (2,2)
resultPanel = new JPanel();
resultPanel.add(jtfResultArea);
resultPanel.add(new JLabel("Perimeter= ", label.RIGHT));

//Clear all input
jtfInput_a.setText(" "); //input field

//Display
jtfResults.Area.setText(string.valueof()); //output field
}


I keep getting this error.....
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete MethodBody

at calc.main(calc.java:7)

Hope you can help I think I am about to climb the wall =)
Dec 16 '07 #1
2 6450
BigDaddyLH
1,216 Expert 1GB
Your code needs a lot of help. I honestly think it's beyond the sort of help you can get through a forum. You need someone to sit down with you and explain basic syntax, or you need to stop and reread your textbook/notes/tutorial.
Dec 17 '07 #2
Thank you for the advice.

I did however manage to create the starting menu. I was looking for guidance. I am afterall a newbie hence I really don't know anything. I am in college and this is not my major, it was an extra credit that I took. The professor really doesn't help at all. I am trying to learn it through books, but its not easy. I was hoping someone would point me in the right direction, ( as in maybe tutorials) instead I was told what was obvious and just like our professor gave me no help whatsoever.

Thank you for the reply nonetheless

As you can see I am not as hopeless

________________________________________________

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Final extends Frame {
JButton HELP;
JButton START;
JLabel Main;
JTextField textfield_1;

public Final() {
FinalLayout customLayout = new FinalLayout();

setFont(new Font("Helvetica", Font.PLAIN, 12));
setLayout(customLayout);

HELP = new JButton("HELP");
HELP.addActionListener(new HELPListener( ));
add(HELP);

START = new JButton("START");
add(START);

Main = new JLabel("Welcome to the Geometry calculator");
add(Main);

textfield_1 = new JTextField("For instructions click HELP, or click START");
add(textfield_1);

setSize(getPreferredSize());

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}

public static void main(String args[]) {
Final window = new Final();

window.setTitle("Final Project");
window.pack();
window.show();
}
}

class FinalLayout implements LayoutManager {

public FinalLayout() {
}

public void addLayoutComponent(String name, Component comp) {
}

public void removeLayoutComponent(Component comp) {
}

public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);

Insets insets = parent.getInsets();
dim.width = 320 + insets.left + insets.right;
dim.height = 240 + insets.top + insets.bottom;

return dim;
}

public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}

public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();

Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+96,128,40); }
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+168,insets.top+96,128,40) ;}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+16,insets.top+8,288,48);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+168,272,56) ;}
}
}
Dec 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jon | last post by:
Hello all, I'm certain this question has been asked before; I was unsure what terms to search for within the newsgroup archive to find the proper answer I wanted. Hopefully someone can point me...
7
by: Maxim Shemanarev | last post by:
I'd like to announce my project called Anti-Grain Geometry. http://www.antigrain.com Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard...
6
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
7
by: Chris | last post by:
Hi, If a user resizes a Toplevel window, or I set a Toplevel's geometry using the geometry() method*, is there any way to have the geometry reset to that required for all the widgets? I think...
12
by: gsal | last post by:
What would be the easiest way to go about offering 3D graphics for the purpose of rendering geometry? Suppose engineers (my co-workes) have to design some enclosure, nozzle, bracket, or whatever...
3
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, do you know an URL for me where to find a sample for an abstract Geometry class, where classes like Point, Line, Area are inherited. This sample should explain OOP (what is inheritance,...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.