Need help with query for converting columns to rows
Hello,
I know this is a very common question asked in the forum. I have searched regading this, i did find some threads, but i was not able to achieve what i require from the answers posted. So anybody please help me.
I have a table which is having multiple columns as follows:
Insert into table_1 (X,Y,Z,A,B,C,D,E,F,G,H,I) values (0,0,2,0,0,1,3,0,0,0,0,0);I want to convert the result into a two column, multiple rows i.e., I want the result as follows:
Col1 Col2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
I 0Please anybody help me in writing the query for this..
Is this what you are expecting:
SQL> WITH T AS
2 (
3 SELECT 0 X, 0 Y, 2 Z, 0 A, 0 B, 1 C, 3 D, 0 E, 0 F, 0 G, 0 H, 0 I FROM DUAL
4 )
5 SELECT 'X' col1, X col2 FROM T
6 UNION ALL
7 SELECT 'Y' col1, Y col2 FROM T
8 UNION ALL
9 SELECT 'Z' col1, Z col2 FROM T
10 UNION ALL
11 SELECT 'A' col1, A col2 FROM T
12 UNION ALL
13 SELECT 'B' col1, B col2 FROM T
14 UNION ALL
15 SELECT 'C' col1, C col2 FROM T
16 UNION ALL
17 SELECT 'D' col1, D col2 FROM T
18 UNION ALL
19 SELECT 'E' col1, E col2 FROM T
20 UNION ALL
21 SELECT 'F' col1, F col2 FROM T
22 UNION ALL
23 SELECT 'G' col1, G col2 FROM T
24 UNION ALL
25 SELECT 'H' col1, H col2 FROM T
26 UNION ALL
27 SELECT 'I' col1, I col2 FROM T
28 /
C COL2
X 0
Y 0
Z 2
A 0
B 0
C 1
D 3
E 0
F 0
G 0
H 0
C COL2
I 0
12 rows selected.
Similar Messages
-
I want to query a list that gives me all OnHand quantities for the Warehouses in one line per item:
Item, Qty Whs1, Qty Whs2 ...
Item1, Qty1_1, Qty1_2 ...
Item2, Qty2_1, Qty2_2 ...
Could somebody put me in the right direction?
Thanks
FranzTry this:
SELECT P.Itemcode, T.ItemName,
(Select U_NF_LagPlatz1 from OITW where WhsCode = 'NFE-1' and itemcode = T.Itemcode),
(Select U_NF_LagPlatz2 from OITW where WhsCode = 'NFE-1' and itemcode = T.Itemcode),
[NFE-1] AS Q1, [2] AS Q2, [3] AS Q3, [4] AS Q4,
[5] AS Q5, [6] AS Q6, [7] AS Q7, [8] AS Q8,
[9] AS Q9, [10] AS Q10
FROM dbo.OITM T
INNER JOIN
(select Itemcode,OnHand, Whscode from oitw) s
PIVOT
sum(onhand)
FOR whscode IN ([NFE-1],[2],[3],[4],[5],[6],[7],[8],[9],[10])
) p ON P.ItemCode = T.ItemCode
ORDER BY P.[Itemcode]
Regards,
Bala
Edited by: Balakumar Viswa on Jul 26, 2010 3:06 PM -
Hi guys, been reading your forums, blogposts, etc and am getting more confused. I'm just a video girl trying to produce meaningful content through web videos for small to mid sized businesses and want to come over from the dark side.
Good news,, I dont need a super giant system, I do simple editing for web videos, minimal graphics, no motion graphics, no animation etc. currently using CS4, will probably end up with 5.5.
I want to get imac 21.5 or 27 if i have to.. So here's the question we all have,,, what do I really need besides an Apple fairy godmother to figure this crazy stuff out?????
I want to be able to have firewire add on, but the rest is what I need help with. So i've been looking at cs6 specs, even though im not there yet, eventually will be,, so just need to run cs4 now and build from there. I also want to eventually move to final cut down the road so I want imac able to upgrade to final cut.
WHAT DO I REALLY NEED MINIMALLY FOR NOW? WHAT CAN I GET LATER IF i CHOOSE TO DO MORE AND NEED MORE POWER?
cs6:
Multicore Intel processor with 64-bit support
Mac OS X v10.6.8, v10.7, or v10.8**
4GB of RAM (8GB recommended)
4GB of available hard-disk space for installation; additional free space required during installation (cannot install on a volume that uses a case-sensitive file system or on removable flash storage devices)
Additional disk space required for preview files and other working files (10GB recommended)
1280x900 display
7200 RPM hard drive (multiple fast disk drives, preferably RAID 0 configured, recommended)
OpenGL 2.0–capable system
DVD-ROM drive compatible with dual-layer DVDs (SuperDrive for burning DVDs; Blu-ray burner for creating Blu-ray Disc media)
QuickTime 7.6.6 software required for QuickTime features
Optional: Adobe-certified GPU card for GPU-accelerated performance
Any responses would be great. I know you guys are busy answering the really high end tech questionsAll the current iMac models (both 21.5" and 27" with OS X Mt. Lion 10.8) will run CS4, 5.5 and 6 just fine. They will also run Final Cut Pro X just fine. Ditto for most any application you may want to use.
Below are some notes (specific to your apparent requirements) that may help you with your purchase decision:
Notes on purchasing a 21.5" iMac
All 21.5" iMacs come with 8GB RAM but you cannot add more later. I strongly suggest getting the maximum RAM (16GB) when you order the iMac.
The basic hard drive is a 1TB 5400rpm drive. It will work fine with Adobe CS but you will probably want the added speed of the optional 1TB Fusion drive for better performance. Some people will recommend/argue for one of the optional SSD drives instead, but they are very expensive and still only come in relatively small capacities - I don't recommend the SSD drives. Get the Fusion drive and spend any extra money on a good external hard drive for backup and/or extra storage instead of an SSD.
Notes on purchasing a 27" iMac
All 27" iMacs come with 8GB RAM and you can add more later, up to 32GB
The basic hard drive is a 1TB 7200rpm drive - it will be fine with Adobe CS. There are upgrade options to a 3TB 7200rpm drive or a 1TB or 3TB fusion drive - these will be fine also. There are also SSD drive options, but I do not recommend them. (Same comments as above.)
Notes on all the current iMacs
iMacs no longer come with built-in CD/DVD drives. If you need one, you will need to purchase the Apple Superdrive accessory drive ($79)
All of the iMac graphic processors (GPU's) are compatible with Adobe CS 4, 5.5, 6
It is very difficult to impossible to change or upgrade the hard drive later on, so don't buy low-end thinking you can add a better internal hard drive later.
Be aware that Macs always come with the latest (most recent) version of OS X. And OS X Mavericks (10.9) is due to be released soon (in the next month or two). There is no guarantee that the older Adobe CS 4 or 5.5 versions will run on OS X Mavericks. If you cannot upgrade to CS 6 in the near future, you may want to purchase now rather than after OS X Mavericks is released.
For what it's worth, I'd recommend the 27" iMac if your budget can afford it. You will appreciate the larger screen size and added capabilities over the years you will use the computer. -
Need Help With Download For Airport Express
Ok, computer dummy here needing help with airport express. We were given airport express last night from a friend who recently purchased a newer gadget. He told us we would need to come here to download the operating system. I see lots of links to updates but no links for someone like me who has never had anything like this on my computer before. Does anyone know what link I would need to use? We have a pc with windows XP. Thanks so much for your help!
Hello jesschambers. Welcome to the Apple Discussions!
The AirPort Express Base Station (AX) doesn't have an "operating system" per se, but it does have built-in firmware which pretty much is the same thing. In addition, in order to administer the AX, you will need the AirPort Admin Utility for your Windows PC.
Here are the links for the latest versions of both:
o AirPort Express Firmware Update 6.3 for Windows
o AirPort 4.2 for Windows -
Need help with pagination for book
I am working on a book and need help with the pagination. I was able to make the TOC and front matter show the numbers as Roman numerals, and the body of the text as Arabic numerals, but I can't figure out how to restart the numbering sequence for the body of the text. So the front matter is numbered i-xvi, and the text is 17-681. I need the text to start with the number 1. Each subsequent chapter is a section break as well, if that makes a difference.
Many thanks,
JClick on the page that shall start on number one. Open Inspector palette > Layout inspector (2nd tab) >
Section > Start at: > 1 -
Need help with coding for HTML5 Video with Flash fallback
Hello, need help with my coding in Dreamweaver CS5.5 for HTML5 video with Flash fallback. Not sure if the coding is correct. Do I need anything else Javascipt etc?
The reason you see a blank page is because it's trying to load the file that is pretty humungous and there is no preloader. So, you see a white screen till it complets loading.
Also, the reason why its loading a SWF file and not any of HTML5 type video is because your doctype declaration is XHTML1.0 and not HTML5.
Change the 1st line in your .html file from:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
to:
<!DOCTYPE html>
Then see if your HTML5 video types load with <video> tag. -
Need help with LikeFilter for querying the keyset instead of value
Hi,
I'm looking for help with the LikeFilter.
I need to query the cache to get all entries with key starting with a particular string.
I could see samples using LikeFilter for querying the values in the cache but not the keyset.
Can someone help?
E.g:
Cache Entries:
abc123 - value1
abc234 - value2
bcd123 - value3
I want to get all entries with key starting with 'abc'.
thanks,
rama.NJ, thanks for the quick reply.
I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
KeyExtractor extractor = new KeyExtractor("getKey");
Filter filter = new LikeFilter(extractor, id+":%",'-',false);
-rama.
Edited by: 911950 on Feb 2, 2012 1:18 PM -
Need help with query joining several tables into a single return line
what i have:
tableA:
puid, task
id0, task0
id1, task1
id2, task2
tableB:
puid, seq, state
id0, 0, foo
id0, 1, bar
id0, 2, me
id1, 0, foo
id2, 0, foo
id2, 1, bar
tableC:
puid, seq, date
id0, 0, 12/21
id0, 1, 12/22
id0, 2, 12/22
id1, 0, 12/23
id2, 0, 12/22
id2, 1, 12/23
what i'd like to return:
id0, task0, 12/21, 12/22, 12/22
id1, task1, 12/23, N/A, N/A
id2, task2, 12/22, 12/23, N/A
N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
id0, task0, 12/21
id0, task0, 12/22
id0, task0, 12/23
id1, task1, 12/23
is this possible fairly easily?
Edited by: user9979830 on Mar 29, 2011 10:53 AM
Edited by: user9979830 on Mar 29, 2011 10:58 AMHi,
Welcome to the forum!
user9979830 wrote:
what i have:...Thanks for posting that so clearly!
Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
CREATE TABLE tablea
( puid VARCHAR2 (5)
, task VARCHAR2 (5)
INSERT INTO tablea (puid, task) VALUES ('id0', 'task0');
INSERT INTO tablea (puid, task) VALUES ('id1', 'task1');
INSERT INTO tablea (puid, task) VALUES ('id2', 'task2');
CREATE TABLE tablec
( puid VARCHAR2 (5)
, seq NUMBER (3)
, dt DATE -- DATE is not a good column name
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 0, DATE '2010-12-21');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 1, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id0', 2, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id1', 0, DATE '2010-12-23');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 0, DATE '2010-12-22');
INSERT INTO tablec (puid, seq, dt) VALUES ('id2', 1, DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
It doesn't look like tableb plays any role in this problem, so I didn't post it.
Explain how you get the results from that data. For example, why do you want this row in the results:
PUID TASK DT1 DT2 DT3
id0 task0 12/21/2010 12/22/2010 12/22/2010rather than, say
PUID TASK DT1 DT2 DT3
id0 task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
WITH got_r_num AS
SELECT puid
, dt
, ROW_NUMBER () OVER ( PARTITION BY puid
ORDER BY seq -- and/or dt
) AS r_num
FROM tablec
-- WHERE ... -- If you need any filtering, put it here
SELECT a.puid
, a.task
, MIN (CASE WHEN r.r_num = 1 THEN r.dt END) AS dt1
, MIN (CASE WHEN r.r_num = 2 THEN r.dt END) AS dt2
, MIN (CASE WHEN r.r_num = 3 THEN r.dt END) AS dt3
, MIN (CASE WHEN r.r_num = 4 THEN r.dt END) AS dt4
FROM tablea a
JOIN got_r_num r ON a.puid = r.puid
GROUP BY a.puid
, a.task
ORDER BY a.puid
;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
Here's the output I got from the query above:
PUID TASK DT1 DT2 DT3 DT4
id0 task0 12/21/2010 12/22/2010 12/22/2010
id1 task1 12/23/2010
id2 task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
For various ways to deal with a variable number of pivoted coolumns, see the following thread:
PL/SQL
This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
PL/SQL
If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one. -
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100I want the output to look like this:
ACCT_CODE CURRENT_YEAR(11) PRIOR_YEAR(10)
A123 100 50
A456 200 100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!
Edited by: user5737516 on Jun 29, 2011 6:48 AM
Edited by: user5737516 on Jun 29, 2011 6:50 AMuser5737516 wrote:
Hi,
Good day everyone! I need help writing a query. I have this table with the following data in them...
ACCT_CODE FSYR YTD_AMT
A123 11 100
A456 11 200
A123 10 50
A456 10 100
I want the output to look like this:
ACCT_CODE CURRENT_YEAR PRIOR_YEAR
A123 100 50
A456 200 100
The user will input the fiscal year and based on that input, I want to get the prior year value as well.
Thank you for all your help!!what is prior year? -
Need help with assignment for class. its for my high school project :(
i really need help, my problem is that with my code i cannot get the "previous", "done" and "next" buttons to work.they cannot seem to find the items from each other. so could someone look at those buttons in the code and tell me how to fix please? the code is as follows:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GradeCalculator extends JFrame {
private JTextField gradeA = new JTextField(3);
private JTextField gradeB = new JTextField(3);
private JTextField gradeC = new JTextField(3);
private JTextField gradeD = new JTextField(3);
private JTextField gradeE = new JTextField(3);
private JTextField studentsName = new JTextField(15);
private JTextField assignmentOne = new JTextField(5);
private JTextField assignmentTwo = new JTextField(5);
private JTextField assignmentThree = new JTextField(5);
private JTextField examOne = new JTextField(5);
private JTextField examTwo = new JTextField(5);
private JTextArea textOutput;
private JPanel buttonJPanel;
public GradeCalculator(){
JMenu fileMenu = new JMenu("File");
JMenuItem aboutItem = new JMenuItem( "About" );
fileMenu.add( aboutItem );
aboutItem.addActionListener(
new ActionListener()
public void actionPerformed( ActionEvent event )
JOptionPane.showMessageDialog( GradeCalculator.this,
"Grade Calculator Version 1.00. \nMade by Carlson Smith.\nSchool: Pre-University\nSubject: Cape Computer Science.",
"About", JOptionPane.PLAIN_MESSAGE );
JMenuItem exitItem = new JMenuItem( "Exit" );
fileMenu.add( exitItem );
exitItem.addActionListener(
new ActionListener()
public void actionPerformed( ActionEvent event )
System.exit( 0 );
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(fileMenu);
JTabbedPane tabbedPane = new JTabbedPane();
buttonJPanel = new JPanel();
buttonJPanel.setLayout(new GridLayout(1,2));
JButton ok = new JButton("OK");
ok.addActionListener(new OkBtnListener());
JButton edit = new JButton("EDIT");
edit.addActionListener(new EditBtnListener());
/**JButton previous = new JButton("PREVIOUS");
previous.addActionListener(new PreviousBtnListener());
JButton done = new JButton("DONE");
done.addActionListener(new DoneBtnListener());
JButton next = new JButton("NEXT");
next.addActionListener(new NextBtnListener());
JPanel contentPane = new JPanel();
contentPane.setLayout(new FlowLayout());
contentPane.add(new JLabel("Grade A")/**,BorderLayout.NORTH*/);
contentPane.add(gradeA/**,BorderLayout.NORTH*/);
contentPane.add(new JLabel("Grade B")/**,BorderLayout.WEST*/);
contentPane.add(gradeB/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade C")/**,BorderLayout.WEST*/);
contentPane.add(gradeC/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade D")/**,BorderLayout.WEST*/);
contentPane.add(gradeD/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade E")/**,BorderLayout.WEST*/);
contentPane.add(gradeE/**,BorderLayout.WEST*/);
tabbedPane.addTab("Grade Entry Tab", null, contentPane, "Grade Tab");
//contentPane.add(ok,BorderLayout.WEST);
//contentPane.add(edit,BorderLayout.WEST);
buttonJPanel.add(ok);
buttonJPanel.add(edit);
contentPane.add(buttonJPanel, BorderLayout.WEST);
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("Student's Name")/**,BorderLayout.EAST*/);
content.add(studentsName/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 1 score:")/**,BorderLayout.EAST*/);
content.add(assignmentOne/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 2 score:")/**,BorderLayout.EAST*/);
content.add(assignmentTwo/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 3 score:")/**,BorderLayout.EAST*/);
content.add(assignmentThree/**,BorderLayout.EAST*/);
content.add(new JLabel("Exam 1 score:")/**,BorderLayout.EAST*/);
content.add(examOne/**,BorderLayout.EAST*/);
content.add(new JLabel("Exam 2 score:")/**,BorderLayout.EAST*/);
content.add(examTwo/**,BorderLayout.EAST*/);
//content.add(previous,BorderLayout.EAST);
//content.add(done,BorderLayout.EAST);
//content.add(next,BorderLayout.EAST);
Box box = Box.createVerticalBox();
String output = "test";
String outputTwo = output;
textOutput = new JTextArea(outputTwo,10,30);
box.add(new JScrollPane(textOutput));
textOutput.setEditable(false);
content.add(box,BorderLayout.SOUTH);
tabbedPane.addTab("Calculator Tab", null, content, "Calculation & Output Tab");
setContentPane(tabbedPane);
pack();
setTitle("Grade Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
class OkBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String gradeAA = gradeA.getText();
double gradA = Double.parseDouble(gradeAA);
gradeA.setText(" "+gradA);
String gradeBB = gradeB.getText();
double gradB = Double.parseDouble(gradeBB);
gradeB.setText(" "+gradB);
String gradeCC = gradeC.getText();
double gradC = Double.parseDouble(gradeCC);
gradeC.setText(" "+gradC);
String gradeDD = gradeD.getText();
double gradD = Double.parseDouble(gradeDD);
gradeD.setText(" "+gradD);
String gradeEE = gradeE.getText();
double gradE = Double.parseDouble(gradeEE);
gradeE.setText(" "+gradE);
gradeA.setEditable(false);
gradeB.setEditable(false);
gradeC.setEditable(false);
gradeD.setEditable(false);
gradeE.setEditable(false);
class EditBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gradeA.setEditable(true);
gradeB.setEditable(true);
gradeC.setEditable(true);
gradeD.setEditable(true);
gradeE.setEditable(true);
/**class PreviousBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if (i <= 0){
i = 0;
}else if(i > 0){
i = i-1;
class DoneBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
output = "Results \n";
output+= studentName[i]+" Assignment Average = "+averageO[i]+" Exam Average = "+averageT[i]+" Overall average = ";
output+= tAverage[i]+" Letter Grade = "+letterGrade;
class NextBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String [] studentName = new String [40];
double [] assignOne = new double [40];
double [] assignTwo = new double [40];
double [] assignThree = new double [40];
double [] gradeOne = new double [40];
double [] gradeTwo = new double [40];
double [] averageO = new double [40];
double [] averageT = new double [40];
double [] tAverage = new double [40];
char [] letterGrade = new char [40];
double max = 0;
double min = 100;
int i = 0;
while(i < studentName.length){
studentName[i] = studentsName.getText();
studentsName.setText(studentName[i]);
String aOne = assignmentOne.getText();
assignOne[i] = Double.parseDouble(aOne);
assignmentOne.setText(assignOne[i]);
String aTwo = assignmentTwo.getText();
assignTwo[i] = Double.parseDouble(aTwo);
assignmentTwo.setText(assignTwo[i]);
String aThree = assignmentThree.getText();
assignThree[i] = Double.parseDouble(aThree);
assignmentThree.setText(assignThree[i]);
String gOne = examOne.getText();
gradeOne[i] = Double.parseDouble(gOne);
examOne.setText(gradeOne[i]);
String gTwo = examTwo.getText();
gradeTwo = Double.parseDouble(gTwo);
examTwo.setText(gradeTwo[i]);
averageO[i] = (assignOne[i]+assignTwo[i]+assignThree[i])/3;
averageT[i] = (gradeOne[i]+gradeTwo[i])/2;
tAverage[i] = (averageO[i]+averageT[i])/2;
if (tAverage[i] >= gradeA){
letterGrade[i] = 'A';
}else if(tAverage[i] >= gradeB){
letterGrade[i] = 'B';
}else if(tAverage[i] >= gradeC){
letterGrade[i] = 'C';
}else if(tAverage[i] >= gradeD){
letterGrade[i] = 'D';
}else if(tAverage[i] <= gradeE){
letterGrade[i] = 'E';
public static void main(String[]args){
GradeCalculator calWindow = new GradeCalculator();
calWindow.setVisible(true);i have to apologize to jittei for the misunderstand i do not know which defination of terms is for which line of code but i know what they do, to solve the problem i have actually made another class in the workspace file called students and now all the bottons work, all i have to do now is properly arrange and put in some additional lines of code and it will be completed. teacher gave me the idea of putting in a new class to help in calling codes from other subclasses in the main program. ah well guess non of you could think of that thanks for the help-ish and hope yall will atleast try to be nice to new people that come in the room. the new coding is:
of course all the commented out lines are not being used in the program anymore but just there till i have the program working with everything in it runs and performs the actions required now though ^_^
*Group CAPE Computer Science 2007/8
*GradeCalculator.java
*@author Carlson Smith
*@version 3.01 07/02/2008
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GradeCalculator extends JFrame {
private JTextField gradeA = new JTextField(3);
private JTextField gradeB = new JTextField(3);
private JTextField gradeC = new JTextField(3);
private JTextField gradeD = new JTextField(3);
private JTextField gradeE = new JTextField(3);
private JTextField studentsName = new JTextField(15);
private JTextField assignmentOne = new JTextField(5);
private JTextField assignmentTwo = new JTextField(5);
private JTextField assignmentThree = new JTextField(5);
private JTextField examOne = new JTextField(5);
private JTextField examTwo = new JTextField(5);
private JTextArea textOutput;
private JPanel buttonJPanel;
private JPanel buttonJPanelTwo;
private Student [] students = new Student[40];
private int current = 0;
private String output;
public GradeCalculator(){
JMenu fileMenu = new JMenu("File");
JMenuItem aboutItem = new JMenuItem( "About" );
for (int i=0;i<40;i++){
students[i] = new Student("");
fileMenu.add( aboutItem );
aboutItem.addActionListener(
new ActionListener()
public void actionPerformed( ActionEvent event )
JOptionPane.showMessageDialog( GradeCalculator.this,
"Grade Calculator Version 1.00. \nMade by Carlson Smith.\nSchool: Pre-University\nSubject: Cape Computer Science.",
"About", JOptionPane.PLAIN_MESSAGE );
JMenuItem exitItem = new JMenuItem( "Exit" );
fileMenu.add( exitItem );
exitItem.addActionListener(
new ActionListener()
public void actionPerformed( ActionEvent event )
System.exit( 0 );
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(fileMenu);
JTabbedPane tabbedPane = new JTabbedPane();
buttonJPanel = new JPanel();
buttonJPanel.setLayout(new GridLayout(1,2));
JButton ok = new JButton("OK");
ok.addActionListener(new OkBtnListener());
JButton edit = new JButton("EDIT");
edit.addActionListener(new EditBtnListener());
buttonJPanelTwo = new JPanel();
buttonJPanelTwo.setLayout(new GridLayout(1,3));
JButton previous = new JButton("PREVIOUS");
previous.addActionListener(new PreviousBtnListener());
JButton done = new JButton("DONE");
done.addActionListener(new DoneBtnListener());
JButton next = new JButton("NEXT");
next.addActionListener(new NextBtnListener());
JPanel contentPane = new JPanel();
contentPane.setLayout(new FlowLayout());
contentPane.add(new JLabel("Grade A")/**,BorderLayout.NORTH*/);
contentPane.add(gradeA/**,BorderLayout.NORTH*/);
contentPane.add(new JLabel("Grade B")/**,BorderLayout.WEST*/);
contentPane.add(gradeB/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade C")/**,BorderLayout.WEST*/);
contentPane.add(gradeC/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade D")/**,BorderLayout.WEST*/);
contentPane.add(gradeD/**,BorderLayout.WEST*/);
contentPane.add(new JLabel("Grade E")/**,BorderLayout.WEST*/);
contentPane.add(gradeE/**,BorderLayout.WEST*/);
tabbedPane.addTab("Grade Entry Tab", null, contentPane, "Grade Tab");
//contentPane.add(ok,BorderLayout.WEST);
//contentPane.add(edit,BorderLayout.WEST);
buttonJPanel.add(ok);
buttonJPanel.add(edit);
contentPane.add(buttonJPanel, BorderLayout.WEST);
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(new JLabel("Student's Name")/**,BorderLayout.EAST*/);
content.add(studentsName/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 1 score:")/**,BorderLayout.EAST*/);
content.add(assignmentOne/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 2 score:")/**,BorderLayout.EAST*/);
content.add(assignmentTwo/**,BorderLayout.EAST*/);
content.add(new JLabel("Assignment 3 score:")/**,BorderLayout.EAST*/);
content.add(assignmentThree/**,BorderLayout.EAST*/);
content.add(new JLabel("Exam 1 score:")/**,BorderLayout.EAST*/);
content.add(examOne/**,BorderLayout.EAST*/);
content.add(new JLabel("Exam 2 score:")/**,BorderLayout.EAST*/);
content.add(examTwo/**,BorderLayout.EAST*/);
//content.add(previous,BorderLayout.EAST);
//content.add(done,BorderLayout.EAST);
//content.add(next,BorderLayout.EAST);
buttonJPanelTwo.add(previous);
buttonJPanelTwo.add(done);
buttonJPanelTwo.add(next);
content.add(buttonJPanelTwo, BorderLayout.EAST);
Box box = Box.createVerticalBox();
//String outputTwo = output;
//textOutput.setText(output);
textOutput = new JTextArea(output,10,30);
box.add(new JScrollPane(textOutput));
//textOutput.setEditable(true);
content.add(box,BorderLayout.SOUTH);
tabbedPane.addTab("Calculator Tab", null, content, "Calculation & Output Tab");
setContentPane(tabbedPane);
pack();
setTitle("Grade Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
class OkBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String gradeAA = gradeA.getText();
double gradA = Double.parseDouble(gradeAA);
gradeA.setText(" "+gradA);
String gradeBB = gradeB.getText();
double gradB = Double.parseDouble(gradeBB);
gradeB.setText(" "+gradB);
String gradeCC = gradeC.getText();
double gradC = Double.parseDouble(gradeCC);
gradeC.setText(" "+gradC);
String gradeDD = gradeD.getText();
double gradD = Double.parseDouble(gradeDD);
gradeD.setText(" "+gradD);
String gradeEE = gradeE.getText();
double gradE = Double.parseDouble(gradeEE);
gradeE.setText(" "+gradE);
gradeA.setEditable(false);
gradeB.setEditable(false);
gradeC.setEditable(false);
gradeD.setEditable(false);
gradeE.setEditable(false);
class EditBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
gradeA.setEditable(true);
gradeB.setEditable(true);
gradeC.setEditable(true);
gradeD.setEditable(true);
gradeE.setEditable(true);
class PreviousBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Student currentStudent = students[current];
currentStudent.setStudentName(studentsName.getText());
currentStudent.setAssignOne(Double.parseDouble(assignmentOne.getText()));
currentStudent.setAssignTwo(Double.parseDouble(assignmentTwo.getText()));
currentStudent.setAssignThree(Double.parseDouble(assignmentThree.getText()));
currentStudent.setExamOneGrade(Double.parseDouble(examOne.getText()));
currentStudent.setExamTwoGrade(Double.parseDouble(examTwo.getText()));
currentStudent = students[current];
if (current <= 0){
current = 0;
}else if(current > 0){
current = current-1;
refresh();
System.out.println(current);
class DoneBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Student currentStudent = students[current];
//output = "Result \n";
output = currentStudent.getStudentName()+". Assignment Average = "+currentStudent.getAverage()+". Exam Average = "+currentStudent.getExamAverage()+". Overall average = ";
output+= currentStudent.getTotalAverage()/**+" Letter Grade = "+letterGrade[current]*/;
textOutput.setText(output);
System.out.println(output);
currentStudent = students[current];
class NextBtnListener implements ActionListener{
public void actionPerformed(ActionEvent e){
// String [] studentName = new String [40];
// double [] assignOne = new double [40];
// double [] assignTwo = new double [40];
// double [] assignThree = new double [40];
// double [] gradeOne = new double [40];
// double [] gradeTwo = new double [40];
// double [] averageO = new double [40];
// double [] averageT = new double [40];
// double [] tAverage = new double [40];
// char [] letterGrade = new char [40];
//double max = 0;
//double min = 100;
Student currentStudent = students[current];
currentStudent.setStudentName(studentsName.getText());
currentStudent.setAssignOne(Double.parseDouble(assignmentOne.getText()));
currentStudent.setAssignTwo(Double.parseDouble(assignmentTwo.getText()));
currentStudent.setAssignThree(Double.parseDouble(assignmentThree.getText()));
currentStudent.setExamOneGrade(Double.parseDouble(examOne.getText()));
currentStudent.setExamTwoGrade(Double.parseDouble(examTwo.getText()));
// currentStudent = students[current];
current++;
refresh();
/** while(i < studentName.length){
String aOne = assignmentOne.getText();
assignOne[i] = Double.parseDouble(aOne);
assignmentOne.setText(" "+assignOne);
String aTwo = assignmentTwo.getText();
assignTwo[i] = Double.parseDouble(aTwo);
assignmentTwo.setText(" "+assignTwo[i]);
String aThree = assignmentThree.getText();
assignThree[i] = Double.parseDouble(aThree);
assignmentThree.setText(" "+assignThree[i]);
String gOne = examOne.getText();
gradeOne[i] = Double.parseDouble(gOne);
examOne.setText(" "+gradeOne[i]);
String gTwo = examTwo.getText();
gradeTwo[i] = Double.parseDouble(gTwo);
examTwo.setText(" "+gradeTwo[i]);
averageO[i] = (assignOne[i]+assignTwo[i]+assignThree[i])/3;
averageT[i] = (gradeOne[i]+gradeTwo[i])/2;
tAverage[i] = (averageO[i]+averageT[i])/2;
if (tAverage[i] >= Double.parseDouble(gradeA.getText())){
letterGrade[i] = 'A';
}else if(tAverage[i] >= Double.parseDouble(gradeB.getText())){
letterGrade[i] = 'B';
}else if(tAverage[i] >= Double.parseDouble(gradeC.getText())){
letterGrade[i] = 'C';
}else if(tAverage[i] >= Double.parseDouble(gradeD.getText())){
letterGrade[i] = 'D';
}else if(tAverage[i] <= Double.parseDouble(gradeE.getText())){
letterGrade[i] = 'E';
public void refresh(){
Student currentStudent = students[current];
studentsName.setText(currentStudent.getStudentName());
assignmentOne.setText(currentStudent.getAssignOne()+"");
assignmentTwo.setText(currentStudent.getAssignTwo()+"");
assignmentThree.setText(currentStudent.getAssignThree()+"");
examOne.setText(currentStudent.getExamOneGrade()+"");
examTwo.setText(currentStudent.getExamTwoGrade()+"");
public static void main(String[]args){
GradeCalculator calWindow = new GradeCalculator();
calWindow.setVisible(true);
Second class implemented./**
*Group CAPE Computer Science 2007/8
*Student.java
*@author Carlson Smith
*@version 3.01 07/02/2008
public class Student {
private String studentName;
private double assignOne;
private double assignTwo;
private double assignThree;
private double examOneGrade;
private double examTwoGrade;
public Student(String sName){
studentName = sName;
public String getStudentName(){
return studentName;
public double getAssignOne(){
return assignOne;
public double getAssignTwo(){
return assignTwo;
public double getAssignThree(){
return assignThree;
public double getExamOneGrade(){
return examOneGrade;
public double getExamTwoGrade(){
return examTwoGrade;
public void setStudentName(String sName){
studentName = sName;
public void setAssignOne(double assignOne){
this.assignOne = assignOne;
public void setAssignTwo(double assignTwo){
this.assignTwo = assignTwo;
public void setAssignThree(double assignThree){
this.assignThree = assignThree;
public void setExamOneGrade(double examOneGrade){
this.examOneGrade = examOneGrade;
public void setExamTwoGrade(double examTwoGrade){
this.examTwoGrade = examTwoGrade;
public double getAverage(){
return (assignOne + assignTwo + assignThree)/3;
public double getExamAverage(){
return (examOneGrade + examTwoGrade)/2;
public double getTotalAverage(){
return (getAverage() + getExamAverage())/2;
this thread can be closed now. l8rz :P
Edited by: Jacal on Feb 10, 2008 7:28 AM -
Need help with accessories for new 4th Generation Nano-speakers, etc
I just purchased the new 16GB 4th generation nano and I want accessories to play with it but am concerned with compatibility and charing issues. I am new to this so my questions may not make sense!
1. I am looking for speakers and the Logitech Anywhere Speakers have good reviews. Will I be able to play my Nano with these and charge it? If not, what ones will that are reasonably priced?
2. What accessory can I use to play my nano in my car (older model) that will also charge it? Or are there no accessories for this as of yet.
3. If I want to plug it into a stereo, I only need the mini/RCA cable converter, correct?
4. To plug into the wall, I need the USB adapter-but do I need a dock as well?
Thank you and sorry for such simple questions! This is my first iPod! :-D2. If you have a cassette adaptor with the 3.5mm audio plug and want to also charge your iPod. You can plug it into a Griffin AutoPilot.
http://www.griffintechnology.com/products/autopilot
For the car with no tape or aux you need an FM transmitter, if your in a city with a lot of stations you will get interferance (I was glad to dump mine when I got a new car). Most are 12 volt! The Griffin iTrip has 5 volt charge and works with the iPod Nano 4th Gen.
http://www.griffintechnology.com/products/itripautopilot
Griffin seems to be one of the few companies that switched to 5 volt charging some time ago.
3. A line out cable is something like this...
http://www.amazon.com/Cables-Go-35507-Connector-Cable/dp/B000JG3WBY/ref=sr111?ie=UTF8&s=electronics&qid=1221776257&sr=1-11
Better then using the headphone jack to hook up to a stereo.
4. For the dock a 3.5mm to RCA cable should be all you need to get line out to your stereo. -
Need help with PayPal for a conference Registration Form
I created a conference registration page and enabled PayPal. I tested it with no issues.
My client distributed the URL, and two people tried to register today, one of whom was my client. She called me to say she never got a confirmation email and that when she entered her AMEX information, and hit the pay button, the message she got back was "Done but with Errors."
Both people show up on my view responses report, but there are no values in the last three columns, which indicates an issue with PayPal. When I check PayPal, there is no recent activity in my account.
I need help resolving this ASAP. Tech support couldn't help, he promised to escalate my case (#183366842) and have someone call me back within an hour.
Is this forum monitored by FormsCentral staff who might be able to help?
Thanks!
PaulaWe're following up with PayPal and the [email protected] offline.
-
I need help with searching for an image inside another image
I need to write a program that checks for a specific image (a jpg) inside another, larger, image (a jpg). If so, it returns a value of true. Can anyone help me?
Winner takes all. First person to solve this gets 10 dukes.
Please help.Hi,
I would use a full screen image Sequence made with png for transparency and put your article behind. no auto play, stop at first and last image. and information for swipe to display article. -
I need help with my for loop in this array
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
import javax.swing.JOptionPane;
public class Runner
public static void main (String[] args)
String timeStr;
int time, again, optiStr;
Inbound[] in = new Inbound[25];
in[0]=new Inbound ("",0,"On Time num0");
in[1]=new Inbound ("",2,"On Time num1");
in[2]=new Inbound ("",3,"Delayed num2");
in[3]=new Inbound ("",4,"On Time");
in[4]=new Inbound ("",5,"On Time");
in[5]=new Inbound ("",6,"Canceled");
in[6]=new Inbound ("",1,"Canceled num6");
in[7]=new Inbound ("",8,"On Time");
in[8]=new Inbound ("",9,"Delayed");
in[9]=new Inbound ("",10,"On Time");
in[10]=new Inbound ("",11,"Delayed");
in[11]=new Inbound ("",12,"On Time");
in[12]=new Inbound ("",13,"Delayed");
in[13]=new Inbound ("",14,"On Time");
in[14]=new Inbound ("",15,"On Time");
in[15]=new Inbound ("",16,"On Time");
in[16]=new Inbound ("",17,"Canceled");
in[17]=new Inbound ("",18,"On Time");
in[18]=new Inbound ("",19,"On Time");
in[19]=new Inbound ("",20,"Canceled");
in[20]=new Inbound ("",21,"On Time");
in[21]=new Inbound ("",22,"Delayed");
in[22]=new Inbound ("",23,"On Time");
in[23]=new Inbound ("",24,"Cancled");
in[24]=new Inbound ("",7,"On Time num24");
do{
timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
time = Integer.parseInt(timeStr);
if (time<=0 || time>24)
JOptionPane.showMessageDialog (null, "Error");
optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
if (optiStr==JOptionPane.YES_OPTION)
//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
// else JOptionPane.showMessageDialog (null, "else");
}//temp return else if failed to find time asked for
// else
// if (optiStr==JOptionPane.CANCEL_OPTION)
// JOptionPane.showMessageDialog(null,"Canceled");
// else
// {Outbound.run();
// JOptionPane.showMessageDialog (null, "outbound");}//temp
again=JOptionPane.showConfirmDialog(null, "Try again?");
while (again==JOptionPane.YES_OPTION);
}any help would be greatly appriciated.rumble14 wrote:
Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
>//(ok this is the for loop i am talking about )
for (int index = 0; index < in.length; index++)
if ( time == Inbound.getTime())
JOptionPane.showMessageDialog (null, Inbound.tostring()); //return the time asked for
Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
Edited by: darb on Mar 26, 2008 11:12 AM -
Need Help with spry for uploading to a website
Sorry if there is already a thread about this but i cant seem to get this to work. So I have looked around an dfound that you need to have the spry files uploaded to the server and i have done that, but the page still looks wrong. Here is a link so you guys can see what it looks like and i'm sorry about the page being in norwegian.
http://miljopose.net/kjop.html
I really need help because this is for a project i am doing at school.None of these files can be found
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
Please upload the files in the correct directory
Gramps
Maybe you are looking for
-
Steps for creation of DSO in BI7.....
Hi, Can anyone help me out with the steps for creation of DSO in BI7..... Points will be assigned... Cheers Shankar
-
When an app is free and it asks for account information which is correct why does it keep saying payment type invalid please choose another payment type.?
-
Problem creating non-persistent Child Objects
I have the need to create a non persistable child object in the jdoPreStore of a parent object. I then perform some tests on the parent to determine if the child object needs to be persisted or not. If I leave the child non persistent it still writes
-
Third Party plugs don't seem to work on nodes
I've got a node working with Logic 8 and it works great with the Logic plugs. I've tried several third party plugs and none of them work: Ozone, Trash, Vintage Warmer, Airwindows Iron Oxide. The manual says ". . . some Audio Unit effects may not supp
-
Can't get movie compressed for iweb
B"H A friend emailed me a quicktime file that is 29.9 MB, and when I drop it into iweb, I am told it should be under 10 MB. After buying Quicktime pro to export the movie, I am being befuddled that when I try the different compression settings, I eit