Help needed in this program!
Hi, i have written a program for solving a power flow question,using Gaussian elimination method to solve for matrices.The program is pretty long,and i have tried breaking the program into smaller modules,but there were errors in the numeric results at the end.
I need some suggests as to how to break the program into smaller modules???
/* Example 10.6 Pg 347 from Bergen.
Demonstration of Newton-Raphson Iteration.
import java.util.*;
import java.io.*;
import java.lang.Math;
import java.lang.ArrayIndexOutOfBoundsException;
public class NewtonRaphsonIt
public static void main( String args[])throws ArrayIndexOutOfBoundsException
int Deg = 360;
int Loop = 3;
double pi = 3.141592653589793238;
double limit = Math.abs(5E-6);
int i,j,k,u;
double V1,V2,V3,P2,P3,Q3,deltaP2,deltaP3,deltaQ3;
double Theta1,Theta2,Theta3;
double P1,Q1,Q2;
double P_Loss,Q_Loss,PF;
double maxi,temp,temp2;
int tempi=0;
//values given
P2=0.6661; P3=-2.8653; Q3=-1.2244;
V1=1; V2=1.05; Theta1=0;
//values supposely to be chosen as a rough guess
Theta2=Theta3=0; V3=1;
double [][] Y_bus = {{-19.98,10,10},{10,-19.98,10},{10,10,-19.98}};
double [][] J = new double [3][3];
double [] fx = new double [3];
double [] oldx = {Theta2,Theta3,V3};
double [] x = {Theta2,Theta3,V3};
double [] V = {V1,V2,Theta1};
double [] Bus = {P2,P3,Q3};
double [] delta = new double [3];
double [] ANS = new double [3];
int f = fx.length;
int y = Y_bus.length;
int z = J.length;
int c = Bus.length;
int h = delta.length;
int e = ANS.length;
int ox= oldx.length;
//System.out.println("Arrary size for Ybus is:" +n);
//output Ybus Matrix
System.out.println(" Ybus is:");
System.out.println("---------");
for ( i=0; i<y; i++)
for ( j=0; j<y; j++)
System.out.print(+Y_bus[i][j]+" "+", ");
System.out.println();
for ( u=1; u<Loop+1; u++){
//while(delta[0] < limit){
//Jacobian matrix
//deltaP2/deltaTheta2
J[0][0] = (Math.abs(V[1]))* (Math.abs(V[0])) * Y_bus[1][0] * (Math.cos(x[0]))
+ (Math.abs(V[1]))* (Math.abs(x[2])) * Y_bus[1][2] * (Math.cos(x[0]-x[1]));
//deltaP2/deltaTheta3
J[0][1] = -(Math.abs(V[1]))* (Math.abs(x[2])) * Y_bus[1][2] * (Math.cos(x[0]-x[1]));
//deltaP2/delta|V3|
J[0][2] = (Math.abs(V[1])) * Y_bus[1][2] * (Math.sin(x[0]-x[1]));
//deltaP3/deltaTheta2
J[1][0] = -(Math.abs(V[1]))*(Math.abs(x[2])) * Y_bus[2][0] * (Math.cos(x[1]-x[0]));
//deltaP3/deltaTheta3
J[1][1] = (Math.abs(V[0])) *(Math.abs(x[2])) * Y_bus[2][0] * (Math.cos(x[1]))
+(Math.abs(V[1])) *(Math.abs(x[2])) * Y_bus[2][1] * (Math.cos(x[1]-x[0]));
//deltaP3/delta|V3|
J[1][2] = (Math.abs(V[0])) * Y_bus[2][0] * (Math.sin(x[1]))
+(Math.abs(V[1]))* Y_bus[2][1] * (Math.sin(x[1]-x[0]));
//deltaQ3/deltaTheta2
J[2][0] = - Y_bus[2][0] * (Math.abs(x[2])) * (Math.abs(V[1])) *(Math.sin(x[1]-x[0]));
//deltaQ3/deltaTheta3
J[2][1] = (Math.abs(x[2]))*(Math.abs(V[0])) * Y_bus[2][0] * (Math.sin(x[1]))
+(Math.abs(x[2]))*(Math.abs(V[1])) * Y_bus[2][1] * (Math.sin(x[1]-x[0]));
//deltaQ3/delta|V3|
J[2][2] = -((Math.abs(V[0])) * Y_bus[2][0] * (Math.cos(x[1]))
+ (Math.abs(V[1])) * Y_bus[2][1] * (Math.cos(x[1]-x[0]))
+ (Math.abs(x[2]))* 2 * Y_bus[2][2]);
//output Jacobian Matrix
System.out.println();
System.out.println(+u+")"+" Jacobian Matrix is:");
System.out.println("-----------------------");
for ( i=0; i<z; i++)
for ( j=0; j<z; j++)
System.out.print(+J[i][j]+" "+", ");
System.out.println();
// variable P2
fx[0] = (Math.abs(V[1]))*(Math.abs(V[0])) * Y_bus[1][0] * (Math.sin(x[0]-V[2]))
+ (Math.abs(V[1]))*(Math.abs(x[2])) * Y_bus[1][2] * (Math.sin(x[0]-x[1]));
//System.out.println("P2 is :"+fx[0]);
// variable P3
fx[1] = (Math.abs(x[2]))*(Math.abs(V[0])) * Y_bus[2][0] * (Math.sin(x[1]-V[2]))
+ (Math.abs(x[2]))*(Math.abs(V[1])) * Y_bus[2][1] * (Math.sin(x[1]-x[0]));
//System.out.println("P3 is :"+fx[1]);
// variable Q3
fx[2] = -((Math.abs(x[2]))*(Math.abs(V[0])) * Y_bus[2][0] * (Math.cos(x[1]-V[2]))
+ (Math.abs(x[2]))*(Math.abs(V[1])) * Y_bus[2][1] * (Math.cos(x[1]-x[0]))
+ (Math.abs(x[2]))*(Math.abs(x[2])) * Y_bus[2][2]);
//System.out.println("Q3 is :"+fx[2]);
//Output f(x)
System.out.println();
System.out.println(+u+")"+" Function f(x) is:");
System.out.println("--------------------");
for ( k=0; k<f; k++)
System.out.println(+fx[k]);
System.out.println();
//ouput P2,P3,Q3 as a matrix
System.out.println();
System.out.println(+u+")"+" Matrix [P2,P3,Q3] is:");
System.out.println("------------------------");
for ( k=0; k<c; k++)
System.out.println(+Bus[k]);
System.out.println();
//finding values of deltaP2,deltaP3,deltaQ3
System.out.println();
System.out.println(+u+")"+" Matrix [d.P2,d.P3,d.Q3] is:");
System.out.println("------------------------------");
for ( k=0; k<h; k++)
System.out.println(delta[k]= Bus[k]- fx[k]);
System.out.println();
//find delta x={deltaTheta2,deltaTheta3,delta|V3|}
//Gaussian Elimination method
//solve Ax=b
//matrix J will be destroyed,solution will be in matrix delta
if(J[0].length != z)
System.out.println("Matrix J must be a Square Matrix!");
return;
for(j=0; j<z; j++)
maxi=-1E-12;
for(i=j; i<z; i++)
if(Math.abs(J[i][j])> maxi)
tempi=i;
maxi=Math.abs(J[i][j]);
//System.out.println(+tempi);
if(maxi<1E-12)
System.out.println
("The Set either has mutltiple solutions or no unique solution!");
return;
//Permuting tempi row with the j-th row
if(tempi != j)
for(k=j; k<z; k++)
temp=J[j][k]; //store 1st row into temp space
J[j][k]=J[tempi][k]; //store last row into 1st row
J[tempi][k]=temp; //store 1st row back into last row
temp=delta[j]; //store 1st row into temp space
delta[j]=delta[tempi]; //store last row into 1st row
delta[tempi]=temp; //store 1st row back into last row
//System.out.println("deltatemp:"+delta[j]);
//Divide j-th row by J[j][j]
temp=J[j][j];
delta[j]=delta[j]/temp;
System.out.println("delta1:"+delta[j]);
for(k=j; k<z; k++)
J[j][k]=J[j][k]/temp;
for(i=0; i<z; i++)
if(i != j)
temp=J[i][j];
temp2=delta;
for(k=0; k<z; k++)
J[i][k] = J[i][k]-temp*J[j][k];
delta[i]= temp2-temp*delta[j];
System.out.println("delta:"+delta[j]);
System.out.println("J:"+J[i][k]);
// values of deltax in radians
System.out.println(+u+")"+" The solution for AX=b is:");
System.out.println("----------------------------");
for(i=0; i<z; i++)
System.out.println(+delta[i]);
x[i] = delta[i];
// values of deltax in degrees
System.out.println();
System.out.println(+u+")"+" The solution for deltaX is:");
System.out.println("------------------------------");
ANS[0] = x[0] * Deg/(2*pi);
ANS[1] = x[1] * Deg/(2*pi);
ANS[2] = x[2];
for(i=0; i<e; i++)
System.out.println(+ANS[i]);
//finding X^1=x^0 + deltax^0
System.out.println();
System.out.println(" The solution for X after iteration:"+"("+u+")");
System.out.println("---------------------------------------");
for(i=0; i<e; i++)
x[i] = oldx[i] + ANS[i];
System.out.println(+x[i]);
System.out.println();
//System.out.println("oldx:" +oldx[i]);
//System.out.println();
//update the oldx with the new values from x
for(i=0; i<ox; i++)
oldx[i] = x[i];
//System.out.println("oldx:" +oldx[i]);
//System.out.println();
//convert to radians for Math.sin/cos()
x[0] = x[0] * (2*pi)/Deg;
x[1] = x[1] * (2*pi)/Deg;
x[2] = x[2];
}//for loop
//if (delta[0] == limit)
// break;
//}//while loop
// calcuate P1,Q1,Q2
P1 = (Math.abs(V[0]))*(Math.abs(V[1])) * Y_bus[0][1]* (Math.sin(V[2]-x[0]))
+ (Math.abs(V[0]))*(Math.abs(x[2])) * Y_bus[0][2] * (Math.sin(V[2]-x[1]));
System.out.println("P1 is :"+P1);
System.out.println();
Q1 = -((Math.abs(V[0]))*(Math.abs(V[1])) * Y_bus[0][1] * (Math.cos(V[2]-x[0]))
+ (Math.abs(V[0]))*(Math.abs(x[2])) * Y_bus[0][2] * (Math.cos(V[2]-x[1]))
+ (Math.abs(V[0]))*(Math.abs(V[0])) * Y_bus[0][0]);
System.out.println("Q1 is :"+Q1);
System.out.println();
Q2 = -((Math.abs(V[1]))*(Math.abs(V[0])) * Y_bus[1][0] * (Math.cos(x[0]-V[2]))
+ (Math.abs(V[1]))*(Math.abs(x[2])) * Y_bus[1][2] * (Math.cos(x[0]-x[1]))
+ (Math.abs(V[1]))*(Math.abs(V[1])) * Y_bus[1][1]);
System.out.println("Q2 is :"+Q2);
System.out.println();
//Power Loss P_Loss = (P1+P2) - P3
P_Loss = (P1+P2) - P3;
System.out.println("Power Loss is :"+P_Loss);
System.out.println();
System.out.println("P2 is :"+P2);
System.out.println();
System.out.println("P3 is :"+P3);
System.out.println();
System.out.println("Q3 is :"+Q3);
System.out.println();
//Reactive Power Loss
Q_Loss = (Q1+Q2) - Q3;
System.out.println("Reactive Power Loss:" +Q_Loss);
System.out.println();
System.out.println("Q1 is :"+Q1);
System.out.println();
System.out.println("Q2 is :"+Q2);
System.out.println();
System.out.println("Q3 is :"+Q3);
System.out.println();
//Power factor PF = P/sqrt[(P^2 + Q^2)]
PF = P3/(Math.sqrt( (P3*P3) + (Q3*Q3)));
System.out.println("Power Factor is :"+PF);
System.out.println();
Start off by creating a Matrix class, rather than doing it all with 2d arrays in the main method? (The Matrix class might do little more than be a wrapper around a 2d array, but at least it would be a bit more modular.)
Similar Messages
-
Hello,
I would like to enquire on whether this VI has any error. I need to configure the digital input as a positive limit switch which is a sensor which when blocked, will produce a change in the voltage pulse.
Attachments:
sensor.vi 34 KBHello,
I could not open. Can you save it for LabView 8.2 or 8.5?
Andy
Best Regards,
Andy
PCI-7356@UMI7764; PCIe-6320@SCB-68; LV2011; Motion Assistant 2.7; NI Motion 8.3; DAQmx 9.4; Win7 -
I need help instantly on this program please
import java.util.*;
public class D3
private static int[] z = new int[100000];
private static int first=z[0];
private static int last=z[n-1];
private static int n=100000;
public static void main(String args[])
Scanner input=new Scanner(System.in);
for(int i=0;i<z.length;i++)
z=2*i;
int seqSearch(z;50000;n); //method call 4 key where key=mid
int binSearch(z;first;last;50000);
int seqSearch(z;35467;n); //method call 4 key where key in the left half
int binSearch(z;first;last;35467);
int seqSearch(z;89703;n); //method call 4 key where key in the right half
int binSearch(z;first;last;89703);
public int seqSearch(int z[];int key;int n)
long start = System.currentTimeMillis();
int count=0;
int ans=-1;
for(int i=0;i<n;i++)
if z[i]=key
count++
{ans=i
break;}
return ans;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
public int binSearch(int z[];int first;int last;int key)
long start = System.currentTimeMillis();
int count=0;
if(last<first){
count++;
index=-1;
else
count++;
int mid=(first+last)/2
if(ket=z[mid]{
index=mid;
else
if(key<z[mid]){
index = binSearch(z[];first;mid-1;key);
else
index=binSearch(z[];mid+1;last;key);
return index;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
// if anyone could tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...plz i need help now,,,"Guide to a first-time poster"
you need to add exclamation marks to signify how urgent it is
e.g.
i need help instantly on this program please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
capital letters is better
I NEED HELP INSTANTLY ON THIS PROGRAM PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
starting the italics on line 1, better again
import java.util.*;
public class D3
private static int[] z = new int[100000];
private static int first=z[0];
private static int last=z[n-1];
private static int n=100000;
public static void main(String args[])
Scanner input=new Scanner(System.in);
for(int i=0;i<z.length;i++)
z=2*i;
int seqSearch(z;50000;n); //method call 4 key where key=mid
int binSearch(z;first;last;50000);
int seqSearch(z;35467;n); //method call 4 key where key in the left half
int binSearch(z;first;last;35467);
int seqSearch(z;89703;n); //method call 4 key where key in the right half
int binSearch(z;first;last;89703);
public int seqSearch(int z[];int key;int n)
long start = System.currentTimeMillis();
int count=0;
int ans=-1;
for(int i=0;i<n;i++)
if z=key
count++
{ans=i
break;}
return ans;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
public int binSearch(int z[];int first;int last;int key)
long start = System.currentTimeMillis();
int count=0;
if(last><first){
count++;
index=-1;
else
count++;
int mid=(first+last)/2
if(ket=z[mid]{
index=mid;
else
if(key><z[mid]){
index = binSearch(z[];first;mid-1;key);
else
index=binSearch(z[];mid+1;last;key);
return index;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
and what about the dukes, offer 10 (never to be awarded, of course)
do this, then sit back and watch the replies roll in. -
Help needed with this form in DW
Hi, i have created this form in dreamweaver but ive got this problem.
In the fields above the text field, the client needs to fill in some info such as name, email telephone number etc.
But the problem is when ill get the messages. Only the text from the large text field is there.
What did i do wrong??
http://www.hureninparamaribo.nl/contact.html
Thank you
Anybody??Thank you for your response. So what do i have to do to fix this?
Date: Sun, 20 Jan 2013 07:57:56 -0700
From: [email protected]
To: [email protected]
Subject: Help needed with this form in DW
Re: Help needed with this form in DW
created by Ken Binney in Dreamweaver General - View the full discussion
You have several duplicate "name" attributes in these rows which also appears in the first row
Telefoon:
Huurperiode:
Aantal personen:
Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5008247#5008247
Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5008247#5008247
To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5008247#5008247. In the Actions box on the right, click the Stop Email Notifications link.
Start a new discussion in Dreamweaver General by email or at Adobe Community
For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746. -
PLEASE CAN SOMEOME HELP ME INSTALL THIS PROGRAM????
PLease can someone help me install this program?? I am not computer literate.
What program specifically are you struggling with? What operating system are you using? What happens when you try?
-
I need Some help to complete this program
i write this program to call file from my hard drive "the file name is
input.tex" "the program the file and the result for the program are below"
please read the program and the file befor you read my question
now, i need to use 3 arrays
1) first array to read this part
include[0]: VAR ZRO 1
include[1]: +0000000000
include[2]: VAR I 1
include[3]: +0000000000
include[4]: VAR SUM 1
include[5]: +0000000000
include[6]: VAR AVG 1
include[7]: +0000000000
include[8]: VAR N 1
include[9]: +0000000000
include[10]: VAR TMP 1
include[11]: +0000000000
include[12]: VAR DTA 990
include[13]: +0000000000
in this way
VAR ZRO 1
VAR I 1
VAR SUM 1
VAR AVG 1
VAR N 1
VAR TMP 1
VAR DTA 990
2) second array is dimensional array to read this part
include[15]: READ N
include[16]: LABL 20
include[17]: READ TMP
include[18]: GE TMP ZRO 40
include[19]: SUB ZRO TMP TMP
include[20]: LABL 40
include[21]: PUTA TMP DTA I
include[22]: LOOP I N 20
include[23]: MOVE ZRO I
include[24]: LABL 50
include[25]: GETA DTA I TMP
include[26]: ADD TMP SUM SUM
include[27]: LOOP I N 50
include[28]: DIV SUM N AVG
include[29]: PRNT AVG
include[30]: STOP
in this way
READ N
LABL 20
READ TMP
GE TMP ZRO 40
SUB ZRO TMP TMP
LABL 40
PUTA TMP DTA I
LOOP I N 20
MOVE ZRO I
LABL 50
GETA DTA I TMP
ADD TMP SUM SUM
LOOP I N 50
DIV SUM N AVG
PRNT AVG
STOP
3) the third to read this part
include[32]: +0000000005
include[33]: +0000000020
include[34]: -0000000430
include[35]: +0000000553
include[36]: +0000001323
include[37]: -0000000896
in this way
+0000000005
+0000000020
-0000000430
+0000000553
+0000001323
-0000000896
i hope i see some help
[http://arbshare.net/files-182969.html]According to the file name ending with extension .tex, I guess that it's TeX, a markup language, not a programming language.
Topicstarter: look for a more suitable forum. Good luck. -
I Need Help With Making This Program Work
The directions for this program:
Enhance the Student class to contain an Advisor. The advisor has a name (type Name), phone number (type String). Place edits in the Name class to validate that the length of the first name is between 1 and 15, middle inital <= 1, and lastName is between 1 and 15. Throw an IllegalArgumentException if the edits are not met. The advisor attribute in the Student class should replace the advisorName. Document the Name, Advisor, and Student classes including the preconditions and postconditions where necessary. Create a test class that will instantiate a Student, fully populate all of its fields and print it out. Do not document the test class. Submit for grade Student.java, Advisor.java, and Name.java.
public class Student
private Advisor advisorName;
private Advisor phoneNumber;
public void setAdvisorName(Advisor anAdvisorName)
advisorName = anAdvisorName;
public Advisor getAdvisorName()
return advisorName;
public void setPhoneNumber(Advisor aPhoneNumber)
phoneNumber = aPhoneNumber;
public Advisor getPhoneNumber()
return phoneNumber;
public class Name
private String firstName;
private String midInit;
private String lastName;
public String getFullName()
return firstName + " " + midInit + " " + lastName;
public String getFirstName()
return firstName;
public String getMidInit()
return midInit;
public String getLastName()
return lastName;
Calculates length of the first name.
(Postcondition: getFirstName() >= 0)
@param s the length of the first name to calculate
(Precondition: length of aFirstName > 0 and <= 15)
public void setFirstName(String aFirstName)
if(aFirstName.length() < 1)
throw new IllegalArgumentException();
if(aFirstName.length() > 15)
throw new IllegalArgumentException();
firstName = aFirstName;
Calculates length of the middle initial.
(Postcondition: getMidInit() >= 0)
@param s the length of the middle initial to calculate
(Precondition: length of s > 0 and <= 1)
public void setMidInit(String aMidInit)
if(aMidInit.length() == 1)
throw new IllegalArgumentException();
midInit = aMidInit;
Calculates length of the last name.
(Postcondition: getLastName() >= 0)
@param s the length of the last name to calculate
(Precondition: length of aLastName > 0 and <= 15)
public void setLastName(String aLastName)
if(aLastName.length() < 1)
throw new IllegalArgumentException();
if(aLastName.length() > 15)
throw new IllegalArgumentException();
lastName = aLastName;
public class Advisor
private Name advisorName;
private String phoneNumber;
public String getFullName()
return advisorName + " " + phoneNumber + " ";
public Name getAdvisorName()
return advisorName;
public String getPhoneNumber()
return phoneNumber;
public void setAdvisorName(Name anAdvisorName)
advisorName = anAdvisorName;
public void setPhoneNumber(String aPhoneNumber)
phoneNumber = aPhoneNumber;
public class Test
public static void main(String[] args)
Name name1 = new Name();
name1.setFirstName("Timothy");
name1.setLastName("O'Neal");
name1.setMidInit("J.");
System.out.println("name1 = " +
name1.getFirstName() + " " +
name1.getMidInit() + " " +
name1.getLastName());
Student st = new Student();
st.setAdvisorName(name1);
Name name2 = st.getAdvisorName();
System.out.println("name2 = " +
name2.getFirstName() + " " +
name2.getMidInit() + " " +
name2.getLastName());
name2.setFirstName("Timothy");
System.out.println("name2 = " +
name2.getFirstName() + " " +
name2.getMidInit() + " " +
name2.getLastName());
System.out.println("name1 = " +
name1.getFirstName() + " " +
name1.getMidInit() + " " +
name1.getLastName());
System.out.println("name1 = " + name1.getFullName());
System.out.println("name2 = " + name2.getFullName());
}I can't get the test class to compile and i'm not sure if this is what i'm suppose to dopublic class Test
public static void main(String[] args)
Student st = new Student();
Advisor advisor = new Advisor();
st.setAdvisor(advisor);
Name name1 = new Name();
name1.setFirstName("Jake");
name1.setLastName("Schmidt");
name1.setMidInit("K.");You have the general idea, I think. You are just doing it backwards.
You create and advisor and assign it to a student. But you don't give
the advisor a name until after you assign it to the student.
You should create an advisor, give the advisor a name and then add it to the student.
//create the name
Name name1 = new Name();
name1.setFirstName("John");
name1.setLastName("Smith");
name1.setMidInit("K.");
//create the advisor
Advisor advisor = new Advisor();
advisor.setAdvisorName(name1);
//create the student
Student student = new Student();
//assign the advisor to the student
student.setAdvisor(advisor);
//now the student has an advisor named John K. Smith
//What is the name of the advisor?
String name = st.advisor.getAdvisorName().getFullName();
//I know that line looks complicated...but that's how you have created your class structure.
Instead you could have done:
Class Student{
private Advisor advisor;
public String getAdvisorName(){
return advisor.getFullName();
class Advisor{
private Name advisorName;
public getFullName(){
return advisorName.getFullName();
This way, if you wanted to know the advisor's name you would go:
String name = st.getAdvisorName();
which is much easier.
I think it would be much easier to help you if we were both in the same room, on the same computer :) -
Can someone help me with this program?
Can someone make this program for me?
Make a Java-webapplication containing a few webpages (html-files and servlets, but NO jsp's). With this application you can get bankdata from a database, for example:
page 1: html-file: Welcome on the website, type your bankaccount and password
page 2: error if bankaccount doesn't exist or wrong password
page 3: welcome with name and option to choose for your balance or a list with transactions from that account (the user can give a starting date)
page 4: showing the balance or the list with transactions, name and accountnumber
Store the information about the account and name in sessionsvariables
the database is an access-file with two tables
table Accounts with colums: accountnumber, name, balance and password
table Transactions with colums: accountnumber, amount, plus/minus, date, sorttransaction and contra-account
(when I need to send you the database by mail, you can ask me ...)
maybe someone can help me,
thanks in advance
greetings BastiaanSure we can help you. Post the code you have already and explain any problems you are currently having together with any and all complete compiler error messages and/or exceptions.
But no, we are not going to do your homework for you. -
Hi guys, I need help in debugging this code I made, which is a GUI minesweeper. Its extremely buggy...I particularly need help fixing the actionListener part of the code as everytime I press a button on the GUI, an exception occurs.
help please!
package minesweeperGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MinesweeperGUI implements ActionListener
//Declaration of attributes
static int length = 0;
JMenuItem menuItemNew = new JMenuItem();
JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
JMenuItem menuItemExit = new JMenuItem();
JButton buttonReset = new JButton();
JButton buttonGrid[][] = null;
JFrame frame = new JFrame();
int getBombsTotal = 0;
JLabel setBombsLabel = new JLabel();
int a = 0;
int b = 0;
//No constructor created. Uses default constructor
//Create the menu bar
public JMenuBar newMenuBar()
//Sets up the menubar
JMenuBar menuBar = new JMenuBar();
//Sets up the Game menu with choice of new, grid size, and exit
JMenu menu = new JMenu ("Game");
menuBar.add (menu);
menuItemNew = new JMenuItem ("New");
menuItemNew.addActionListener (this);
menu.add (menuItemNew);
menu.addSeparator();
//Sets up sub-menu for grid size with choice of easy and hard radio buttons
JMenu subMenu = new JMenu ("Grid Size");
rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
rbEasy.addActionListener (this);
subMenu.add (rbEasy);
rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
rbHard.addActionListener (this);
subMenu.add (rbHard);
menu.add (subMenu);
menu.addSeparator();
menuItemExit = new JMenuItem ("Exit");
menuItemExit.addActionListener (this);
menu.add (menuItemExit);
return menuBar;
//Setting up of Bomb Grid
public int [][] setGrid (int length)
int grid[][] = null;
grid = new int[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
return grid;
//Setting up of the of the graphical bomb grid
public JButton[][] setButtonGrid (int length)
JButton buttonGrid[][] = null;
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = new JButton();
return buttonGrid;
//Setting up of a way to count the total number of bombs in the bomb grid
public int getBombsTotal (int length, int setGrid[][])
int bombsTotal = 0;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (setGrid[i][j] == 1)
bombsTotal += 1;
return bombsTotal;
//Create a label for number of bombs left
public JLabel setBombsLabel (int getBombsTotal)
JLabel bombsLabel = new JLabel(String.valueOf (getBombsTotal) + " Bombs Left");
return bombsLabel;
//Setting up a way to count the number of bombs around a button
public String setBombs (int length, int setGrid[][], int x, int y)
int bombs[][] = new int[length][length];
String bombsString = null;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (i == 0 && j == 0)
bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i ==0 && j == (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else if (i == (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1];
else if (i == (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1];
else if (i == 0 && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
setGrid[i+1][j-1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i == (length - 1) && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1];
else if (i != 0 && i != (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i != 0 && i != (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1] + setGrid[i+1][j-1] +
setGrid[i+1][j] + setGrid[i+1][j+1];
bombsString = String.valueOf (bombs[x][y]);
return bombsString;
//create the panel for the bombs label and reset button
public JPanel newTopPanel(int length)
int setGridNew [][] = null;
setGridNew = new int[length][length];
int getBombsTotalNew = 0;
JLabel setBombsLabelNew = new JLabel();
setGridNew = setGrid (length);
getBombsTotalNew = getBombsTotal (length, setGridNew);
setBombsLabelNew = setBombsLabel (getBombsTotalNew);
JPanel topPanel = new JPanel ();
topPanel.setLayout (new BorderLayout (50,50));
JLabel bombsLabel = new JLabel ();
bombsLabel = setBombsLabelNew;
topPanel.add (bombsLabel, BorderLayout.WEST);
buttonReset = new JButton("Reset");
buttonReset.addActionListener (this);
topPanel.add (buttonReset, BorderLayout.CENTER);
return topPanel;
//create the panel for the play grids
public JPanel newBottomPanel(int length)
JButton setButtonGridNew[][] = null;
setButtonGridNew = new JButton [length][length];
setButtonGridNew = setButtonGrid (length);
JPanel bottomPanel = new JPanel ();
bottomPanel.setLayout (new GridLayout (length, length));
buttonGrid = new JButton[length][length];
for (a = 0; a < length; a++)
for (b = 0; b < length; b++)
buttonGrid[a] = setButtonGridNew[a][b];
buttonGrid[a][b].addActionListener (this);
bottomPanel.add (buttonGrid[a][b]);
return bottomPanel;
//Overiding of abstract method actionPerformed
public void actionPerformed(ActionEvent e)
if (e.getSource() == menuItemNew)
launchFrame(length);
else if (e.getSource() == menuItemExit)
frame.setVisible (false);
System.exit(0);
else if (e.getSource() == rbEasy)
length = 5;
launchFrame(length);
else if (e.getSource() == rbHard)
length = 10;
launchFrame(length);
else if (e.getSource() == buttonReset)
launchFrame(length);
else if (e.getSource() == buttonGrid[a][b])
int setGridNew [][] = null;
setGridNew = new int[length][length];
JButton bombButton [][] = null;
bombButton = new JButton [length][length];
String bombString [][] = null;
bombString = new String[length][length];
setGridNew = setGrid (length);
bombString[a][b] = setBombs (length, setGridNew, a, b);
bombButton[a][b] = new JButton (bombString[a][b]);
if (setGridNew[a][b] == 0)
buttonGrid[a][b] = bombButton[a][b];
getBombsTotal--;
JLabel setBombsLabelNew = new JLabel();
setBombsLabelNew = setBombsLabel (getBombsTotal);
else if (setGridNew[a][b] == 1 )
buttonGrid[a][b] = new JButton("x");
JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
System.exit(0);
//create the content pane
public Container newContentPane(int length)
JPanel topPanel = new JPanel();
JPanel bottomPanel = new JPanel();
topPanel = newTopPanel(length);
bottomPanel = newBottomPanel (length);
JPanel contentPane = new JPanel();
contentPane.setOpaque (true);
contentPane.setLayout (new BorderLayout(50,50));
contentPane.add (topPanel, BorderLayout.NORTH);
contentPane.add (bottomPanel, BorderLayout.CENTER);
return contentPane;
public void launchFrame (int length)
//Makes sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
//Sets up the top-level window
frame = new JFrame ("Minesweeper");
//Exits program when the closed button is clicked
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
Container contentPane = new Container();
menuBar = newMenuBar();
contentPane = newContentPane (length);
//Sets up the menu bar and content pane
frame.setJMenuBar (menuBar);
frame.setContentPane (contentPane);
//Displays the window
frame.pack();
frame.setVisible (true);
public static void main (String args[])
//Default length is 5
length = 5;
MinesweeperGUI minesweeper = new MinesweeperGUI();
minesweeper.launchFrame(length);hi, thanks. that removed the exception; although now the buttons action listener won't work :(
here is the revised code:
To anyone out there, can you guys run this code and help me debug it?
I'm really desperate as this is a school project of mine and the deadline is 7 hours away. I have already been working on it for 3 days, but the program is still very buggy.
thanks!
/* Oliver Ian C. Wee 04-80112
* CS12 MHRU
* Machine Problem 2
package minesweeperGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MinesweeperGUI implements ActionListener
//Declaration of attributes
static int length = 0;
JMenuItem menuItemNew = new JMenuItem();
JRadioButtonMenuItem rbEasy = new JRadioButtonMenuItem();
JRadioButtonMenuItem rbHard = new JRadioButtonMenuItem();
JMenuItem menuItemExit = new JMenuItem();
JButton buttonReset = new JButton();
JButton buttonGrid[][] = null;
JFrame frame = new JFrame();
int getBombsTotal = 0;
JLabel setBombsLabel = new JLabel();
int a = 0;
int b = 0;
//No constructor created. Uses default constructor
//Create the menu bar
public JMenuBar newMenuBar()
//Sets up the menubar
JMenuBar menuBar = new JMenuBar();
//Sets up the Game menu with choice of new, grid size, and exit
JMenu menu = new JMenu ("Game");
menuBar.add (menu);
menuItemNew = new JMenuItem ("New");
menuItemNew.addActionListener (this);
menu.add (menuItemNew);
menu.addSeparator();
//Sets up sub-menu for grid size with choice of easy and hard radio buttons
JMenu subMenu = new JMenu ("Grid Size");
ButtonGroup bg = new ButtonGroup();
rbEasy = new JRadioButtonMenuItem ("Easy: 5x5 grid");
bg.add (rbEasy);
rbEasy.addActionListener (this);
subMenu.add (rbEasy);
rbHard = new JRadioButtonMenuItem ("Hard: 10x10 grid");
bg.add (rbHard);
rbHard.addActionListener (this);
subMenu.add (rbHard);
menu.add (subMenu);
menu.addSeparator();
menuItemExit = new JMenuItem ("Exit");
menuItemExit.addActionListener (this);
menu.add (menuItemExit);
return menuBar;
//Setting up of Bomb Grid
public int [][] setGrid (int length)
int grid[][] = null;
grid = new int[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
grid[i][j] = ((int)Math.round(Math.random() * 10))% 2;
return grid;
//Setting up of the of the graphical bomb grid
public JButton[][] setButtonGrid (int length)
JButton buttonGrid[][] = null;
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = new JButton();
return buttonGrid;
//Setting up of a way to count the total number of bombs in the bomb grid
public int getBombsTotal (int length, int setGrid[][])
int bombsTotal = 0;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (setGrid[i][j] == 1)
bombsTotal += 1;
return bombsTotal;
//Create a label for number of bombs left
public JLabel setBombsLabel (int getBombsTotal)
JLabel bombsLabel = new JLabel(" " +String.valueOf (getBombsTotal) + " Bombs Left");
return bombsLabel;
//Setting up a way to count the number of bombs around a button
public String setBombs (int length, int setGrid[][], int x, int y)
int bombs[][] = new int[length][length];
String bombsString = null;
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
if (i == 0 && j == 0)
bombs[i][j] = setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i ==0 && j == (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else if (i == (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1];
else if (i == (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1];
else if (i == 0 && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i][j-1] + setGrid[i][j+1] +
setGrid[i+1][j-1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i == (length - 1) && j != 0 && j != (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1];
else if (i != 0 && i != (length - 1) && j == 0)
bombs[i][j] = setGrid[i-1][j] + setGrid[i-1][j+1] +
setGrid[i][j+1] + setGrid[i+1][j] +
setGrid[i+1][j+1];
else if (i != 0 && i != (length - 1) && j == (length - 1))
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i][j-1] + setGrid[i+1][j-1] +
setGrid[i+1][j];
else
bombs[i][j] = setGrid[i-1][j-1] + setGrid[i-1][j] +
setGrid[i-1][j+1] + setGrid[i][j-1] +
setGrid[i][j+1] + setGrid[i+1][j-1] +
setGrid[i+1][j] + setGrid[i+1][j+1];
bombsString = String.valueOf (bombs[x][y]);
return bombsString;
//create the panel for the bombs label and reset button
public JPanel newTopPanel(int length)
int setGridNew [][] = null;
setGridNew = new int[length][length];
int getBombsTotalNew = 0;
JLabel setBombsLabelNew = new JLabel();
setGridNew = setGrid (length);
getBombsTotalNew = getBombsTotal (length, setGridNew);
setBombsLabelNew = setBombsLabel (getBombsTotalNew);
JPanel topPanel = new JPanel ();
topPanel.setLayout (new BorderLayout (20,20));
JLabel bombsLabel = new JLabel ();
bombsLabel = setBombsLabelNew;
topPanel.add (bombsLabel, BorderLayout.WEST);
buttonReset = new JButton("Reset");
buttonReset.addActionListener (this);
topPanel.add (buttonReset, BorderLayout.CENTER);
return topPanel;
//create the panel for the play grids
public JPanel newBottomPanel(int length)
JButton setButtonGridNew[][] = null;
setButtonGridNew = new JButton [length][length];
setButtonGridNew = setButtonGrid (length);
JPanel bottomPanel = new JPanel ();
bottomPanel.setLayout (new GridLayout (length, length));
buttonGrid = new JButton[length][length];
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
buttonGrid[i][j] = setButtonGridNew[i][j];
buttonGrid[i][j].addActionListener (this);
bottomPanel.add (buttonGrid[i][j]);
return bottomPanel;
//Overiding of abstract method actionPerformed
public void actionPerformed(ActionEvent e)
if (e.getSource() == menuItemNew)
closeFrame();
launchFrame(length);
else if (e.getSource() == menuItemExit)
frame.setVisible (false);
System.exit(0);
else if (e.getSource() == rbEasy)
closeFrame();
length = 5;
launchFrame(length);
else if (e.getSource() == rbHard)
closeFrame();
length = 10;
launchFrame(length);
else if (e.getSource() == buttonReset)
closeFrame();
launchFrame(length);
else if (e.getSource() == buttonGrid[a])
int setGridNew [][] = null;
setGridNew = new int[length][length];
JButton bombButton [][] = null;
bombButton = new JButton [length][length];
String bombString [][] = null;
bombString = new String[length][length];
setGridNew = setGrid (length);
for (int i = 0; i < length; i++)
for (int j = 0; j < length; j++)
bombString[i][j] = setBombs (length, setGridNew, i, j);
bombButton[i][j] = new JButton (bombString[i][j]);
if (setGridNew[a][b] == 0)
buttonGrid[a][b] = bombButton[a][b];
getBombsTotal--;
JLabel setBombsLabelNew = new JLabel();
setBombsLabelNew = setBombsLabel (" " String.valueOf (getBombsTotal) " Bombs Left");
else if (setGridNew[a][b] == 1 )
buttonGrid[a][b] = new JButton("x");
JOptionPane.showMessageDialog (null, "Game Over. You hit a Bomb!");
System.exit(0);
//create the content pane
public Container newContentPane(int length)
JPanel topPanel = new JPanel();
JPanel bottomPanel = new JPanel();
topPanel = newTopPanel(length);
bottomPanel = newBottomPanel (length);
JPanel contentPane = new JPanel();
contentPane.setOpaque (true);
contentPane.setLayout (new BorderLayout(5,5));
contentPane.add (topPanel, BorderLayout.NORTH);
contentPane.add (bottomPanel, BorderLayout.CENTER);
return contentPane;
public void closeFrame ()
frame = new JFrame ("Minesweeper");
frame.dispose();
public void launchFrame (int length)
//Makes sure we have nice window decorations
JFrame.setDefaultLookAndFeelDecorated(true);
//Sets up the top-level window
frame = new JFrame ("Minesweeper");
//Exits program when the closed button is clicked
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
Container contentPane = new Container();
menuBar = newMenuBar();
contentPane = newContentPane (length);
//Sets up the menu bar and content pane
frame.setJMenuBar (menuBar);
frame.setContentPane (contentPane);
//Displays the window
frame.pack();
frame.setVisible (true);
public static void main (String args[])
//Default length is 5
length = 5;
MinesweeperGUI minesweeper = new MinesweeperGUI();
minesweeper.launchFrame(length); -
Urgent Help Needed in this Report
hi frd. help me in this report.
parameter : plant,material no,company code,storage location.
display: material no, material desc, UOM, ROL, warehouse, open po, open po qty, open pr no, open pr qty.
Kindly Give me tips for doing this report.
thank u
Pari Vendhan.RHi Pari,
Go to se38 --Abap editior..
chose the includes u like to be as
Include <>_top.
Include <>_subr.
then follow the events....
Initialization.
( as per requirement).
At selection-screen.
Perform fetch _data.
Perform fefilloutput.
any other logic to be followed for u r report.
end-of-selection.
Perform output.
In include top.
Put the declarartion part and the selection-screen block.
SELECTION SCREEN
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : pa_werks LIKE table name-werks
pa_material no like tablename-field.
SELECTION-SCREEN END OF BLOCK b1.
like wise u need to put the logic for the requirement
Thanks
Mohinder Singh Chauhan -
PLEASE HELP ME. THIS PROGRAM IS KILLING ME.
Hi. I am getting so sick of this program. I have been trying to do it for the past couple of weeks and I am getting nowhere. I really wish someone can help me on it ... like totaly help me on it. I am getting so frustrated. I would appreciate all the help.
This is the program:
In Belageusia, a plorg has these properties:
Data:
A plorg has a name
A plorg has a contentment index (CI), which is an integer between 0 and 100
The population of plorgs in Belagersia is further subdivided into three mutually exclusive classes: Plebeians, Equidians, and Elitians.
A Plorg?s stature is completely determined by their contentment index and witht that designation comes certain burdens and/or advantages.
Plebeians have a contentment index in [0, 24].
Each new Plebeian is welcomed with a contentment index of 2 and burdened with a debt of $10.00
Plebeians never manage to break even, so they have no taxes imposed upon them. Furthermore, since they can never get out debt, they cannot accumulate any wealth.
Equidians have a contentment index in [25, 75]
Each new Equidian is welcomed with a contentment index of 50 and burdened with taxes of $20.00
Equidians have taxes imposed upon them. Furthermore, since they do manage to break even, they have no debt. However, since they only manager to break even, they do not accumulate any wealth.
Elitians have a contentment index in [76, 100]
Each new Elitian is welcomed with a contentment index of 87 and burdened with taxes of $20.00, but also provided with a ?silver spoon? of $30.00 in accumulated wealth.
Elitians manage to expand upon their wealth, sot hey have taxes imposed upon them. Furthermore, since they are accumulating wealth, they have no debt.
At each interim time epoch the population of Belageusia retracts with a death rate randomly selected between 0% and 10%. If a plorg survives the purge, they have an opportunity to move one class higher and/or one class lower. However, remember that a plorg?s name is final. It never changes.
For Plebeians this is transition is determined by randomly selecting a CI in [0, 49]. If this new CI is les than 25 then the plorg remains a Plebeian, with this newly assigned CI, and their debt increases 3.7%. If this new CI is in [25, 49], the Plebeian ascends to a Equidian, with this newly assigned CI, their debt is forgiven, but taxes of $20 are assessed.
For Equidians this is determined by randomly selecting a CI in [0,100].
If this new CI is in [25, 75] then the plorg remains a Equidian, with this newly assigned CI, but their taxes are increased 6.1%.
If this new CI is in [0, 24] then the plorg becomes a Plebeian, with this newly assigned CI, their taxes are forgiven, but they are burdened with a debt of $10.00.
If this new CI is in [76, 100] then the plorg becomes a Plebeian, with this newly assigned CI, but their taxes are increased 6.1%. However, they are bewtowed a wealth of $30.00.
For Eletians this is determined by randomly selecting a CI in [51, 100]. If this new CI is greater than 76 then the plorg remains an Eletian, with this newly assigned CI, their taxes increase 6.1% and their wealth increases 4.9%. If this new CI is in [51, 75], then this plorg becomes an Equidian, with this newly assigned CI, their wealth is eliminated, and their taxes are increased 6.1%.
At each time epoch, the population of Belageusia at a birth rate randomly selected between 0% and 10%. A randomly chosen number between 0-100 determines each newly born plorg?s stature. If this random number is in the range 0-24, create a new Plebeian. In the range 25-75, create a new Equidian, and if in the range 76-100, create a new Elitian.
We are supposed to output the population characteristics of Belageusia, after 1000 time epochs.
This is the code that I wrote down but got no where with:
import javax.swing.*;
import java.util.*;
import java.text.*;
public class Belageusiaplorg
public static void main (String[] args)
ArrayList Plebs = new ArrayList(350);
ArrayList Equids = new ArrayList(600);
ArrayList Elits = new ArrayList(350);
ArrayList Holding = new ArrayList(600);
for (int i=0; i<25; i++)
Plebs.add(new plebian());
for (int i=0; i<50; i++)
Equids.add(new equidian());
for (int i=0; i<25; i++)
Elits.add(new Elitian());
long population = Plebs.size() + Equids..size() + Elits.size();
System.out.println("Current Belageusia Population is "+population);
System.out.println("Current Plebeians Population is "+Plebs.size);
System.out.println("Current Equidians Population is "+Equids.size);
System.out.println("Current Elitians Population is "+Elits.size);
Random generator = new Random();
int x = generator.nextInt(11);
for (int j=0; j=plebs.size(); j++)
System.out.println(Plebs.g(j));
long Equids_size = Equids.size();
long Elits_size = Elits.size();
for(int j=1; j<Plebs.size(); j++)
Plebian e = (Plebian) Plebs.get(j);
int new_ci = generator.nextInt(50);
if (new_ci < 25)
e.setCI(new_ci);
e.raiseDebt();
else
Plebs.rename(j);
Equids.add(new Equidian(e.getName().newCI));
j++;
for(int j=0; j < Equids.size; j++)
Equidian e = (Equidian) Equids.get(j);
int newCI = generator.nextInt(101);
if(new_ci < 25)
Equids.remove(j);
Plebs.add(nwe Plebian(e.getName().new_ci));
Equids_size --;
j++;
else
if (new_ci > 75)
Equids.remove(j);
Elitian f = new Elitian(e.getName(),new_ci,e.getTaxes());
Elits.add(f);
Equids_size --;
j--;
else
e.setCI(new_CI);
e.raiseTaxes();
for (int j=0; j<Elits.size; j++)
Elitian e = (Elitian) Elits.get(j);
int ci = e.getCI();
int r = generator.nextINT(50);
int new_ci = 51+r;
if(new_ci > 75)
e.setCI(new_ci);
e.raisetaxes();
e.raisewealth();
else
Elitians.remove(j);
Equidian g = new Equidian(e.getName(), new_ci);
g.raisetaxes();
Equids.add(g);
Elits_size --;
j--;
if(deathrate != 0)
int multiple = 100/deathrate;
int count 1;
for (int j=0; j=Plebs.size(); j++)
if(count % multiple == 0)
Plebs.remove(j);
j--;
count++;
class Plorg
private final String name;
private int CI;
private static long nextID = 1;
public Plorg()
name = "Plorg" + nextID;
nextID++;
public Plorg(int CI)
name = "Plorg" + nextID;
nextID++;
this.CI = CI;
public Plorg (String name, int CI)
this.name = name;
this.CI = CI;
public void setCI(int new_CI)
CI = new_CI;
public String getName()
return name;
public int getCI()
return CI;
public Plorg Plebs()
public Plorg Equids()
public Plorg Elits()Sounds a lot like a homework question to me. Still it was interesting enough to try out. I have not tried to change your code, just made one of my own. Here is my solution. I have made the Plorg class an inner class of the Belageusia. This is just so I dont have to put up two java files. You could easily split it into two though.
import java.util.Random;
import java.util.ArrayList;
import java.util.Iterator;
* @author Jonathan Knight
public class Belageusia
/** Random number generator - Seeded with the current time. */
private static Random random = new Random(System.currentTimeMillis());
/** A list of all of the Plorgs */
private ArrayList population = new ArrayList();
/** A list of all of the Plebians. */
private ArrayList plebians = new ArrayList();
/** A list of all of the Equidians. */
private ArrayList equidians = new ArrayList();
/** A list of all of the Elitians. */
private ArrayList elitians = new ArrayList();
/** A count of the Epochs that have passed */
private int epochs = 0;
* Main method.
* Create a new world of Belageusia and run it for 1000 epochs.
public static void main(String[] args)
Belageusia world;
world = new Belageusia();
for (int i = 0; i < 1000; i++)
world.epoch();
System.out.println("The Belageusia population after 1000 epochs");
world.printPopulation();
* Create a new World of Belageusia and create some Plorgs to live there.
* The world will be created with 25 Plebians, 50 Equidians and 25 Elitians.
public Belageusia()
for (int i = 0; i < 25; i++)
plebians.add(Plorg.createPlebian());
for (int i = 0; i < 50; i++)
equidians.add(Plorg.createEquidian());
for (int i = 0; i < 25; i++)
elitians.add(Plorg.createElitian());
* Print the current population to System.out
public void printPopulation()
int total;
int plebianCount;
int equidianCount;
int elitianCount;
plebianCount = plebians.size();
equidianCount = equidians.size();
elitianCount = elitians.size();
total = plebianCount + equidianCount + elitianCount;
System.out.println("Current Belageusia population is " + total);
System.out.println("Current Plebian population is " + plebianCount);
System.out.println("Current Equidian population is " + equidianCount);
System.out.println("Current Elitian population is " + elitianCount);
* At each interim time epoch the population of Belageusia retracts with a death rate
* randomly selected between 0% and 10%. If a plorg survives the purge, they have an
* opportunity to move one class higher and/or one class lower. However, remember that
* a plorgs name is final. It never changes.
* For Plebeians this transition is determined by randomly selecting a CI in [0, 49].
* If this new CI is les than 25 then the plorg remains a Plebeian, with this newly assigned CI,
* and their debt increases 3.7%. If this new CI is in [25, 49], the Plebeian ascends to a
* Equidian, with this newly assigned CI, their debt is forgiven, but taxes of $20 are assessed.
* For Equidians this is determined by randomly selecting a CI in [0,100].
* If this new CI is in [25, 75] then the plorg remains a Equidian, with this newly assigned CI,
* but their taxes are increased 6.1%.
* If this new CI is in [0, 24] then the plorg becomes a Plebeian, with this newly assigned CI,
* their taxes are forgiven, but they are burdened with a debt of $10.00.
* If this new CI is in [76, 100] then the plorg becomes a Plebeian, with this newly assigned CI,
* but their taxes are increased 6.1%. However, they are bewtowed a wealth of $30.00.
* For Eletians this is determined by randomly selecting a CI in [51, 100].
* If this new CI is greater than 76 then the plorg remains an Eletian, with this newly assigned CI,
* their taxes increase 6.1% and their wealth increases 4.9%. If this new CI is in [51, 75],
* then this plorg becomes an Equidian, with this newly assigned CI, their wealth is eliminated,
* and their taxes are increased 6.1%.
* At each time epoch, the population of Belageusia at a birth rate randomly selected between 0% and 10%.
* A randomly chosen number between 0-100 determines each newly born plorg?s stature.
* If this random number is in the range 0-24, create a new Plebeian. In the range 25-75, create a new Equidian,
* and if in the range 76-100, create a new Elitian.
public void epoch()
ArrayList newPlebians = new ArrayList();
ArrayList newEquidians = new ArrayList();
ArrayList newEletians = new ArrayList();
Iterator it;
Plorg plorg;
int deathRate;
double deathCount;
int birthRate;
double birthCount;
int population;
int subClass;
int newCI;
int kill;
epochs++;
System.out.println("Epoch = " + epochs);
printPopulation();
population = plebians.size() + equidians.size() + elitians.size();
// The death rate is random 0 to 10%
deathRate = random.nextInt(11);
// work out the death count. population is cast to a double to avoid rounding errors
deathCount = (double)population * deathRate / 100;
// round up the result. We do this as once the population falls below 10
// we would never kill anything
deathCount = Math.ceil(deathCount);
// We now work out the birth rate based on the population before we kill
// anything otherwise the population tends to go down and down
// The birth rate is random 0 to 10%
birthRate = random.nextInt(11);
// work out the birth count. population is cast to a double to avoid rounding errors
birthCount = Math.ceil((double)population * birthRate / 100);
// As with the deathCount round up the result.
// We do this as once the population falls too low we would never create any more
birthCount = Math.ceil(birthCount);
System.out.println("About to kill " + deathRate + "% which is " + deathCount + " Plorgs out of " + population);
for(int i=0; i<deathCount; i++)
// get a random number between 0 and 2
kill = random.nextInt(population);
population--;
// kill the specified Plorg
if( kill < plebians.size() )
// kill a random Plebian
plebians.remove( random.nextInt(plebians.size()) );
else if( kill < plebians.size() + equidians.size() )
// kill a random Equidian
equidians.remove( random.nextInt(equidians.size()) );
else
// kill a random Elitian
elitians.remove( random.nextInt(elitians.size()) );
System.out.println("Transitioning Plebians");
// Transition period for Plebians
it = plebians.iterator();
while ( it.hasNext() )
plorg = (Plorg) it.next();
// select a new CI from 0 to 49 at random
newCI = random.nextInt(50);
plorg.setCI(newCI);
if( newCI < 25 )
// Oh dear, this one stays as a Plebian; increase its dept by 3.7%
plorg.setDept( plorg.getDept() * 1.037 );
else
// Congratulations this one is now an Equidian
newEquidians.add(plorg);
// remove from the Plebian list.
// NOTE we must do the remove via the Iterator
it.remove();
plorg.setDept(0);
plorg.setTaxes(20);
System.out.println("Transitioning Equidians");
// Transition period for Equidians
it = equidians.iterator();
while ( it.hasNext() )
plorg = (Plorg) it.next();
// select a new CI from 0 to 100 at random
newCI = random.nextInt(101);
plorg.setCI(newCI);
if( newCI < 25 )
// Oh dear, this one becomes a Plebian
newPlebians.add(plorg);
// remove from the Equidian list.
// NOTE we must do the remove via the Iterator
it.remove();
plorg.setDept( 10 );
plorg.setTaxes(0);
else if( newCI < 25 )
// This one stays as an Equidian; increase its taxes by 6.1%
plorg.setTaxes( plorg.getTaxes() * 1.061 );
else
// Congratulations this one is now an Eletian
newEletians.add(plorg);
// remove from the Equidian list.
// NOTE we must do the remove via the Iterator
it.remove();
plorg.setWealth(30);
// Increase its taxes by 6.1%
plorg.setTaxes( plorg.getTaxes() * 1.061 );
System.out.println("Transitioning Elitians");
// Transition period for Eletians
it = plebians.iterator();
while ( it.hasNext() )
plorg = (Plorg) it.next();
// Always increase taxes by 6.1%
plorg.setTaxes( plorg.getTaxes() * 1.061 );
// select a new CI from 51 to 100 at random
newCI = 51 + random.nextInt(50);
plorg.setCI(newCI);
if( newCI > 76 )
// This one stays as an Eletian; increase its wealth by 4.9%
plorg.setWealth( plorg.getWealth() * 1.049 );
else
// Oh dear, this one becomes an Equidian
newEquidians.add(plorg);
// remove from the Plebian list.
// NOTE we must do the remove via the Iterator
it.remove();
// emove its wealth
plorg.setWealth(0);
// now assign the Plorgs that are transitioning
plebians.addAll(newPlebians);
equidians.addAll(newEquidians);
elitians.addAll(newEletians);
System.out.println("Creating " + birthRate + "% new Plorgs from " + population + " which is " + birthCount);
//create the new Plorgs
for (int i = 0; i < birthCount; i++)
// get a random number between 0 and 100
subClass = random.nextInt(101);
// create the specified Plorg
if( subClass <= 24 )
plorg = Plorg.createPlebian();
plebians.add(plorg);
else if( subClass >= 25 && subClass <= 75 )
plorg = Plorg.createEquidian();
equidians.add(plorg);
else
plorg = Plorg.createElitian();
elitians.add(plorg);
public static class Plorg
/** Identifier used to generate unique names */
private static int id = 0;
/** The Plorgs name */
private final String name;
/** The level of wealth for this Plorg */
private double wealth = 0;
/** The level of dept for this Plorg */
private double dept = 0;
/** The level of taxes for this Plorg */
private double taxes = 0;
/** This Plorgs contentment index */
private int ci = 0;
/** Create a new Plorg with the given CI.
* This is a private constructor. The only way for a program to
* create new Plorgs is by calling either createPlebian(),
* createEquidian() or createElitian().
* @param ci
private Plorg(int ci)
// Generate a unique name and iincrement the ID
this.name = "Plorg" + id++;
// assign the CI
this.ci = ci;
* Create a new Plebian.
* Plebeians have a contentment index in [0, 24].
* Each new Plebeian is welcomed with a contentment index of 2 and burdened
* with a debt of $10.00. Plebeians never manage to break even, so they have
* no taxes imposed upon them. Furthermore, since they can never get out debt,
* they cannot accumulate any wealth.
* @return a new Plebian.
public static Plorg createPlebian()
Plorg plebian;
plebian = new Plorg(2);
plebian.setDept(10);
return plebian;
* Create a new Equidian
* Equidians have a contentment index in [25, 75].
* Each new Equidian is welcomed with a contentment index of 50 and burdened
* with taxes of $20.00. Equidians have taxes imposed upon them. Furthermore,
* since they do manage to break even, they have no debt. However, since they
* only manager to break even, they do not accumulate any wealth.
* @return a new Equidian.
public static Plorg createEquidian()
Plorg equidian;
equidian = new Plorg(50);
equidian.setTaxes(20);
return equidian;
* Create a new Elitian.
* Elitians have a contentment index in [76, 100].
* Each new Elitian is welcomed with a contentment index of 87 and burdened
* with taxes of $20.00, but also provided with a ?silver spoon? of $30.00 in
* accumulated wealth. Elitians manage to expand upon their wealth, so they
* have taxes imposed upon them. Furthermore, since they are accumulating
* wealth, they have no debt.
* @return a new Elitian.
public static Plorg createElitian()
Plorg equidian;
equidian = new Plorg(87);
equidian.setWealth(30);
equidian.setTaxes(20);
return equidian;
* Returns this Plorgs name.
public String getName()
return name;
* Returns the CI of this Plorg.
public int getCI()
return ci;
* Set the new Contentment index for this Plorg
* @param ci
public void setCI(int ci)
this.ci = ci;
* Returns the Dept of this Plorg
* @return
public double getDept()
return dept;
* Set the dept of this Plorg.
* @param dept - the new dept for the Plorg.
public void setDept(double dept)
this.dept = dept;
* Returns the wealth of this Plorg.
public double getWealth()
return wealth;
* Sets the wealth of this Plorg.
* @param wealth - the new wealth of this Plorg.
public void setWealth(double wealth)
this.wealth = wealth;
* Returns the taxes of this Plorg.
public double getTaxes()
return taxes;
* Set the taxes of this Plorg.
* @param taxes - the new taxes for this Plorg.
public void setTaxes(double taxes)
this.taxes = taxes;
* Check for equality. If the object specified is a Plorg with the same name as this
* Plorg they are deemed to be equal.
* @param o - The object to check
public boolean equals(Object o)
if ( this == o ) return true;
if ( !(o instanceof Plorg) ) return false;
final Plorg plorg = (Plorg) o;
if ( name != null ? !name.equals(plorg.name) : plorg.name != null ) return false;
return true;
* Create a Hash Code for this Plorg
public int hashCode()
return (name != null ? name.hashCode() : 0);
} -
HI ALL,
I have created a queue table and queue as below. i call enqueue procedure in after update of a trigger. With a package variable 'FISCFILE' . When I execute the update Of it it tells invalid queue name . can anyone help me with this
SQL> ed select
SQL> ed select
SQL> SELECT Name FROM User_Queues WHERE Name LIKE '%FISC%';
NAME
AQ$_QT_FISCFILE_E
Q_FISCFILE
SQL>
SQL> SELECT Queue_Table FROM User_Queue_Tables WHERE Queue_Table LIKE '%FISC%';
QUEUE_TABLE
QT_FISCFILE
SQL> Spool Off
Value Of PACKAGE variable:-
Package VARIABLE :='FISCFILE';
UPDATE TL_PYMT_DETAILS
SET PYMT_TYPE ='RTGS',
STATUS_CODE =91,
FISC_STATUS ='N',
PROC_DATE = TRUNC(SYSDATE)
WHERE PYMT_REF ='R0421141' ;
Queue Name :- STS_AQ_ADM.Q_FISCFILE
UPDATE TL_PYMT_DETAILS
ERROR AT line 1:
ORA-20001: QUEUE NAME INVALID PLEASE RERUN WITH CORRECT QUEUE NAME
ORA-06512: AT "STS_TW_DBA.TRG_FISC_GEN", line 16
ORA-04088: error during execution OF TRIGGER 'STS_TW_DBA.TRG_FISC_GEN'Dear All,
Sorry For the delayed reply. The Payload name was given wrong. -
Help needed in Dialog programming
Hi,
I am in a module pool program. This contains a subscreen which has a tablecontrol. Based on one of the entry in the table control. I need to stop the user to change the value.
So I have coded like the below.
If i_tc-value = 0.
v_scrno = sy-dynnr.
leave to screen v_scrno.
endif.
But the above code gives an ABEND error with message
<b>SET SCREEN not allowed in subscreen (screen: <Program name> <Screen nbr>)</b>
Please help to solve the above issue. User must make the entry in the table control. How to stop the user for changing the entry?Hi Murphy,
I don't know on wot entry you want to stop the user to changes , i hope for stoping your user you may have some condiation once that condation pass make use screen properties to make that field into display mode such that the user again not able to edit.
Thanks,
saleem. -
Can anyone help me with this program using the Scanner Class?
I have to write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. Such as 1 hour will equal 40 miles traveled, 2 hours will equal 80, 3 hours will equal 120, etc. This is what I've come up with thus far. Any help is appreciated.
import java.util.Scanner;
public class DistanceTraveled
public static void main(String[] args)
int speed;
int hours;
int distance;
Scanner keyboard = new Scanner(System.in);
System.out.print("What is the speed of the vehicle in miles-per-hour?");
speed = keyboard.nextInt();
System.out.print("How many hours has the vehicle traveled for?");
hours = keyboard.nextInt();
distance = speed*hours;
while (speed < 0)
while (hours < 1)
System.out.println("Hour Distance Traveled");
System.out.println("------------------------");
System.out.println(hours + " " + distance);
}When you post code, wrap it in code tags. Highlight it and click the CODE button above the text input area.
You seem to be trying to reuse the speed and hours variables in your loop. That's probably a mistake at this point. Keep it simpler by defining a loop variable.
Also I don't see the need for two loops. You just want to show how far the vehicle has traveled for each one-hour increment, assuming constant speed, for the number of hours it has been traveling, right? So a single for loop should be sufficient. -
2 Layout's for 2 screens different F4 Help needed for same program
Hi Friends,
I have 2 layouts in the selection screen the first layout is for screen 1 and the second layout is for screen 2.
I save the layouts when I run the report.
Now when I do F4 Help for the first layout it shows me all the layouts available for the program and the same thing
for Second layout too.
Is there a way for the first layout I need to get only the layouts for the first screen when I hit the F4 button
and for the second layout I need to get only the layouts for the second screen when I hit the F4 button. in order to choose
I am using REUSE_ALV_VARIANT_F4 and passing report name to is_variant and i_save = 'X'.
Thanks,
chaithanya.I think this is not possible.
Variant names get stored on Report Name as key.
a®
Maybe you are looking for
-
Hi, I am working on EP 7.0 SP 18. I have created an Activity Report iView to track which users have used my WebDynpro application.My Wedynpro application is on a page and the Monitor User property of the page is also turned on. I am able to see the d
-
Treo 755p, Leopard, missing sync, no event syncing
i initially had entourage but decided it *****, so i'd simply use ical and apple mail. when i had entourage i installed the palm software, but used isync to sync and everything worked fine. once i stopped uing entourage, and deleted the conduits, isy
-
Trace to Pads Net Group Options not Avalible
Hello, To explain my problem I have prepared as easy example as it is possible. Let suppose that we have a circuit diagram that is shown below in the attached figure (Figure A). As can be seen the circuit diagram consists of three resistors R1, R2,
-
Create Report Plan & Actual Balance Sheet
Hi, I want to create report BL with plan data. I use t-code FSE5N to input plan but in FSI3 plan data is not come out. Please help me, or there's another report painter that I should use. I use ECC 6 btw. Thanks for your help.
-
No Canon printer profiles in CS5
Canon Printer Profiles do not appear after upgrading to Mountain Lion. I upgraded the Canon drivers, still no success. Canon techs suggested that I had to upgrade my CS5 to run with Mountain Lion. I've tried to find just where one would find the upgr