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.Ima geIcon;
import javax.swing.JFr ame;
import javax.swing.JMe nu;
import javax.swing.JMe nuBar;
import javax.swing.JMe nuItem;
import javax.swing.JOp tionPane;
import javax.swing.JPa nel;
import javax.swing.JLa bel;
import javax.swing.JBu tton;
import javax.swing.bor der.*;
import javax.swing.JTe xtField;
import java.awt.Border Layout;
import java.awt.Color;
import java.awt.GridLa yout;
import java.awt.Image;
import java.awt.event. ActionListener;
import java.awt.event. ActionEvent;
import java.text.*;
public class TriangleCalcula tor extends JFrame implements
ActionListener {
public static final int WIDTH = 250;
public static final int HEIGHT = 250;
public static void main(String[] args)
{
TriangleCalcula tor gui = new TriangleCalcula tor();
gui.setVisible( true);
}
///// Create the selectPanel on buttonPanel/////
// selectPanel contains the selectMenuBar
JPanel selectPanel = new JPanel();
buttonPanel.add (selectPanel, BorderLayout.NO RTH);
selectPanel.set Layout(new GridLayout(3, 1));
selectPanel.set Background(Colo r.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.a dd(selectMenu);
// Create the circleMenuItem in selectMenu
JMenuItem circleMenuItem = new JMenuItem("Circ le");
circleMenuItem. addActionListen er(new CircleListener( ));
selectMenu.add( circleMenuItem) ;
// Create the trapezoidMenuIt em in selectMenu
JMenuItem trapezoidMenuIt em = new JMenuItem("Trap ezoid");
trapezoidMenuIt em.addActionLis tener(new TrapezoidListen er());
selectMenu.add( trapezoidMenuIt em);
// Create the triangleMenuIte m in selectMenu
JMenuItem triangleMenuIte m = new JMenuItem("Tria ngle");
triangleMenuIte m.addActionList ener(new TriangleListene r());
selectMenu.add( triangleMenuIte m);
//Create the input textfields
jtfInput_a = new JTextField(10);
jtfInput_b = new JTextField(10);
jtfInput_c = new JTextField(10);
inputPanel.setL ayout(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("Calcul ate.");
SolveButton.add ActionListener( this);
SolvePanel.add( SolveButton);
biggerPannel.ad d(solvePanel, BorderLayout.CE NTER);
//Create result panel with title and grid (2,2)
resultPanel = new JPanel();
resultPanel.add (jtfResultArea) ;
resultPanel.add (new JLabel("Perimet er= ", label.RIGHT));
//Clear all input
jtfInput_a.setT ext(" "); //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 =)
2 6484 BigDaddyLH 1,216
Recognized Expert Top Contributor
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.
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.JBu tton;
import javax.swing.JFr ame;
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(custo mLayout);
HELP = new JButton("HELP") ;
HELP.addActionL istener(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(getPref erredSize());
addWindowListen er(new WindowAdapter() {
public void windowClosing(W indowEvent 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 addLayoutCompon ent(String name, Component comp) {
}
public void removeLayoutCom ponent(Componen t comp) {
}
public Dimension preferredLayout Size(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInset s();
dim.width = 320 + insets.left + insets.right;
dim.height = 240 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSi ze(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer (Container parent) {
Insets insets = parent.getInset s();
Component c;
c = parent.getCompo nent(0);
if (c.isVisible()) {c.setBounds(in sets.left+24,in sets.top+96,128 ,40);}
c = parent.getCompo nent(1);
if (c.isVisible()) {c.setBounds(in sets.left+168,i nsets.top+96,12 8,40);}
c = parent.getCompo nent(2);
if (c.isVisible()) {c.setBounds(in sets.left+16,in sets.top+8,288, 48);}
c = parent.getCompo nent(3);
if (c.isVisible()) {c.setBounds(in sets.left+24,in sets.top+168,27 2,56);}
}
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 to some relevant
postings or websites.
In any case, I want to create a geometry class that has some base
functionalities. The problem I am particularly interested in is such:
|
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 C++. The terms and conditions of
use are very simple and described on the License page.
AGG doesn't depend on any graphic API or technology. Basically, you can
think
of AGG as of a rendering engine that produces pixel images in memory from
|
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....
#include <stdio.h>
#include <stdlib.h>
|
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 have on his site, a Javascript
Calculator for working out the cost of what they want, for example:
1 widget and 2 widglets = £5.00
|
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 java.awt.*;
import java.awt.event.*;
import java.io.*;
| |
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 I found what I'm looking for in tk itself:
"""
13.3. How can I clear the geometry settings for a toplevel?
If you want to have Tk resize your toplevel to what the toplevel
|
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 physical part/component, I would like to
write a program where they can at least see the resulting geometry and
navigate it, i.e., zoon-in/out, rotate, pan. On the side, I could
have data entry fields with the input parameters and when something...
|
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, polymorphism,
encapsulation, ...)
Thank you,
Norbert
|
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 the last operator entered
/* Digit entered as integer value i
* Updates the value of input accordingly to (input * 10) + i
*/
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |