Loop Through Objects Of Subclasses To Show Area Of Each?

Oct 13, 2014

This assignment requires me to show areas of each shape by using loop. I can do it with abstract and interface , but in this case. I don't know how to use method getArea() to loop for each object

import java.util.ArrayList;
public class TestShape {
ArrayList<Shape> list = new ArrayList<Shape>();
Circle c;
Rectangle r;
Square s;
public TestShape() {

[Code] .....

View Replies


ADVERTISEMENT

Sorting ArrayList Of Geometric Objects By Area From Smallest To Largest

Mar 18, 2014

I have to create a method with the following header :

public static <E extends Comparable<E> > void sort ( ArrayList<E> list , int left, int right)

i also had to create a swap cells method and position of max integer method. and also had to read the preserved data file in with a scanner. I implemented the comparable interface I am having difficulty sorting my list by the area. It has to be in descending order.

Geometric Object class: since it has comparator also am interested if i need to change this?

CODE:

Driver:
public static void main(String[] args) throws IOException, ClassNotFoundException {
Circle c1 = new Circle (4, "red", false);
Circle c2 = new Circle (2, "blue", true);
Circle c3 = new Circle (10, "blue", true);
Rectangle r1 = new Rectangle (10, 6, "yellow", true);
Rectangle r2 = new Rectangle ( 5, 11, "green", true);
ArrayList <GeometricObject> list = new ArrayList();

[Code] ....

View Replies View Related

JDBC By Using Properties Objects Show Password In Heap

May 4, 2015

Properties info = new Properties( );
info.put( "user", "username" );
info.put( "password", "password" );

Connection conn = DriverManager.getConnection(URL, info);

I am using simple jdbc connection to connect to Sybase as shown above , problem is security team is able to see password as clear text in heap, How to avoid it.

View Replies View Related

Subclasses With Unique Static Variables

Oct 22, 2014

Say I have a class called ClassA which I want to hold my data. Now inside ClassA want to hold instances of a class lets call ClassB. So far we are here.

import blah.B
public class A {
private B myB;
(Getters setters etc)
public String getBString() {
B.getString();
}
}

However I want to have multiple extensions of ClassB which have UNIQUE static variables.

public class B-1 extends B {
private static String mString;
private static int mInt;
}

The problem I have run into is I can't have subclasses with their own static variables. I need the A class to hold any type of B class. How can I manage this?meant

public String getBString{
return B.getString();
}

View Replies View Related

Super Call / Subclasses And Inheritance

Feb 12, 2014

what does super(); do in the following method, I understand its uses to access variables belonging to the superclass but i am unsure of what that one line does. Here is a sample constructor..

public CreditCard()
{
// fill in the default constructor and use the super call
super();
id = "000000";
year = 0;
}

View Replies View Related

How To Create Objects In A Loop

Feb 12, 2014

Is it possible to use a loop to create objects? I'm trying to put together a program (just as a way of learning) to run a horse race.

What I'd like to is have the user enter the number of horses they want in the race, and then create the objects as the user enters the various attributes of the horse (at least the horse's name), and then once all the instance variables have been set, create the first horse object and then move on to the second one, etc, until all the horse objects have been created.

I know I can't use something like a for loop to do it, so how would the code be writte

View Replies View Related

Loop Through Objects And Call Method For Each One

Nov 22, 2014

I want to loop through each of my objects and call the method for each one. ( polymorphic array )

Error: Constructor Dog in class Dog cannot applied for gives Types

Required String,String

Found: no arguments

Reason actual and formal argument lists differ in length

Java Code:

public class animal {
private String m_type="";
private String m_name="";
public static void main (String[] args) {

[Code] ....

View Replies View Related

How To Give Values To Array Objects Without Using Loop

Apr 3, 2014

The main method should creates a Student object with name as "Bill" and marks as {88,92,76,81,83} and print it.

Java Code:

class TestStudent {
public static void main(String args[]) {
Student1 st = new Student1();
st.name = "bill";
Student st1[] = new Student[6];
//This gives error
st1[].marks = {1, 5, 8, 9, 7, 6}; mh_sh_highlight_all('java');

View Replies View Related

Naming Objects Depending Of Times A Loop Have Gone

Oct 4, 2014

I know the normal way of naming objects is

Pipe pipe1 = new Pipe

but I want the objects to be made inside a loop and named after how many times the loop have been gone through so I tried

Pipe pipe(numberOfTimes) = new Pipe

where numberOfTimes was a variable counting the loops. This is not working.I need the naming to be pipe1, pipe2, pipe3 etc depending on how many times the loop have been pased

Scanner keyboard = new Scanner (System.in);
String morePipes = ("yes");
int dimRor;
int numberOfPipes = -1;

[code]....

View Replies View Related

For Loop - Store Any Number Of Objects As Long As It Is Less Than 4

Jul 8, 2014

I have a problem with my application. It supposed to store 4 different Room objects but when I entered one only it stores tat object variables into all my Array elements. I just need it to store any number of objects as long as it is less than 4.

Java Code:

import java.util.Arrays;
import java.util.Scanner;
import javax.swing.JOptionPane;
class TestRoom {
public static void main(String [] args)
{
String[] roomsInHouse = new String[4];

[Code] .....

View Replies View Related

New Lines Don't Show Up In File But They Do Show Up On Console

Apr 30, 2015

I have the following code.

class A {
List<StringBuilder> list;
public void output(List<StringBuilder> objectToOutput){
try(BufferedWriter bw = new BufferedWriter(new FileWriter("temp.txt"))){
for(StringBuilder row:objectToOutput) bw.write(row.toString());
}catch(IOException e){}

[code]....

Why don't the a's show up on the console? I put them in as part of the debugging process and now I don't understand why they don't show up in both places.

View Replies View Related

Make Date Column Show Only Date And TimeIn And TimeOut Column Only Show Time

Mar 11, 2014

How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.

View Replies View Related

Copying Data Objects To Serializable Objects

Jul 27, 2014

I am currently working on a project where I need to return data from a database over RMI to a client who requests it. Some of the fields in the Data Object can not be seen by the client so I need to create another object to send over the network instead. The method I use is this...

public static SerializableObject createSerializableObjectFromDataObject(DataObject dataObject){
SerializableObject serializableObject = new SerializableObject();
serializableObject.setField(dataObject.getField());
serializableObject.setAnotherField(dataObject.getAnotherField());
return serializableObject;
}

Is there a better way of doing this? I am creating many subclasses DataObject which all require this static method to be implemented and I can't push it into the superclass because each one needs custom behaviour.

View Replies View Related

Area Of A Pentagon

Sep 7, 2014

I have to produce a program that gives the area of a pentagon. I'm very new to java so I get confused easily. I followed the formula in the textbook but I'm doing something wrong and I don't know what. This is the code I've written.

[import java.util.Scanner;
public class Pentagon {
public static void main(String[]args) {
Scanner input = new Scanner (System.in);
// Prompt for length

[Code] ....

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Calculating Area With JOptionPane?

Sep 9, 2014

I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Area {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
StringTokenizer st;

[code]....

View Replies View Related

Calculating Area And Circumference Of A Circle

Apr 21, 2014

Here is the code that I wrote out:

//program that calculates the circumference and area of a circle

import java.util.Scanner;
public class circle{
public static void main(String[] args){
Scanner input= new Scanner( System.in);
double r; //declares radius

[Code] .....

And here is what is displayed in the command prompt when I compile my code:

circle.java:17: error: cannot find symbol
r.input.nextdouble();//entered the radius
symbol: method nextdouble()
location: variable input of type Scanner
1 error

What am I doing wrong?

View Replies View Related

How To Get Coordinates Of Transparent Area In Image

Mar 25, 2015

How to find coordinates of transparent area in the image. I working on .png image which has transparent background and transparent area in the middle of the image. The transparent area in the middle look a like ellipse, so i want to find coordinate of top, bottom, left, and right of that area. I am using opencv.

I have tried to find pixels and from result that i got, i understand that pixel with rgb that equal to 255.0 255.0 255.0 is transparent. what i have in my mind is, if rgb with value that equal to 255 255 255 detected, i will put 1 into arraylist named transparent, and if it not equal to 255 255 255 i will put 0 into the list. So when i look into the list, if there is 1 0 or 0 1 it means that border between transparent area and colored area or vice versa. But, how to know if that border is between transparent area in the middle of image and the image, and not between background and the image. Am i doing this correctly?

Here snippet of code.

Mat imgMask = Highgui.imread(imgfile);
double[] pixels = new double[3];
System.out.println("channel " + imgMask);
for(int x = 0; x < imgMask.cols(); x++) {
for(int y = 0; y < imgMask.rows(); y++) {
pixels = imgMask.get(y, x);

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Can Text Area Also Be Used For Input

Apr 7, 2014

I have a popup that displays textual info and sometimes gets text input from the user. I'm using the following code:

JTextArea textArea = new JTextArea( getGameHistory( true, -2 ) );
JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
textArea.setFont(new Font("courier", Font.PLAIN, 12));
scrollPane.setPreferredSize( new Dimension( 30, 100 ) );
String input = JOptionPane.showInputDialog(null, scrollPane, "Fun Chess ",
JOptionPane.YES_NO_OPTION);

This shows a nice text area and an input field underneath it.The getGameHistory() method just returns a long string detailing the current game.Is there a way of just showing the text area without the input field underneath?Can the text area also be used for input instead?

View Replies View Related

Area Of Triangle Java Program?

Sep 2, 2014

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

View Replies View Related

How To Transfer Output Into Text Area

Sep 26, 2014

how to put the output the the text area this is the code .

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package interns;
/**
*
* @author JosephP
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

[Code]...

View Replies View Related

Program To Calculate Area Of Circle

Mar 11, 2015

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;

[Code] .....

View Replies View Related

Area Of Regular Pentagon - End Result

Jul 17, 2014

I am doing exercises which has to do with the area of regular pentagon.

(Geometry: area of a regular polygon) A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is :

I have checked errata on their page and they did not list the type-o under the final result.

Errata link [URL] ....

their result is
Enter the number of sides: 5
Enter the side: 6.5
The area of the polygon is 74.69017017488385

and mine is Area of regular pentagon is 72.69017017488385

is it a code error?

import java.util.Scanner;

public class AreaOfAregularPolygon4_5 {
public static void main (String[] args){
//Initiate scanner and use the input
Scanner input = new Scanner (System.in);
System.out.println(" Enter the number of sides in polygon");

[Code] ....

View Replies View Related

Transferring Contents Of Text Area Of One Jframe To Another?

Mar 14, 2015

trying to tranfer content of a text area on one jframe to a text area in another

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved