Need HELP with objects and classes problem (program compiles)

Alright guys, it is a homework problem but I have definitely put in the work. I believe I have everything right except for the toString method in my Line class. The program compiles and runs but I am not getting the right outcome and I am missing parts. I will post my problems after the code. I will post the assignment (sorry, its long) also. If anyone could help I would appreciate it. It is due on Monday so I am strapped for time.
Assignment:
-There are two ways to uniquely determine a line represented by the equation y=ax+b, where a is the slope and b is the yIntercept.
a)two diffrent points
b)a point and a slope
!!!write a program that consists of three classes:
1)Point class: all data MUST be private
a)MUST contain the following methods:
a1)public Point(double x, double y)
a2)public double x ()
a3public double y ()
a4)public String toString () : that returns the point in the format "(x,y)"
2)Line class: all data MUST be private
b)MUST contain the following methods:
b1)public Line (Point point1, Point point2)
b2)public Line (Point point1, double slope)
b3)public String toString() : that returns the a text description for the line is y=ax+b format
3)Point2Line class
c1)reads the coordinates of a point and a slope and displays the line equation
c2)reads the coordinates of another point (if the same points, prompt the user to change points) and displays the line equation
***I will worry about the user input later, right now I am using set coordinates
What is expected when the program is ran: example
please input x coordinate of the 1st point: 5
please input y coordinate of the 1st point: -4
please input slope: -2
the equation of the 1st line is: y = -2.0x+6.0
please input x coordinate of the 2nd point: 5
please input y coordinate of the 2nd point: -4
it needs to be a diffrent point from (5.0,-4.0)
please input x coordinate of the 2nd point: -1
please input y coordinate of the 2nd point: 2
the equation of the 2nd line is: y = -1.0x +1.0
CODE::
public class Point{
     private double x = 0;
     private double y = 0;
     public Point(){
     public Point(double x, double y){
          this.x = x;
          this.y = y;
     public double getX(){
          return x;
     public double setX(){
          return this.x;
     public double getY(){
          return y;
     public double setY(){
          return this.y;
     public String toString(){
          return "The point is " + this.x + ", " + this.y;
public class Line
     private double x = 0;
     private double y = 0;
     private double m = 0;
     private double x2 = 0;
     private double y2 = 0;
     public Line()
     public Line (Point point1, Point point2)
          this.x = point1.getX();
          this.y = point1.getY();
          this.x2 = point2.getX();
          this.y2 = point2.getY();
          this.m = slope(point1, point2);
     public Line (Point point1, double slope)
          this.x = point1.getX();
          this.y = point1.getY();
     public double slope(Point point1, Point point2)//finds slope
          double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
          return m1;
     public String toString()
          double temp = this.x- this.x2;
          return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
          //y-y1=m(x-x1)
public class Point2Line
     public static void main(String[]args)
          Point p = new Point(3, -3);
          Point x = new Point(10, 7);
          Line l = new Line(p, x);
          System.out.println(l.toString());
}My problems:
I dont have the right outcome due to I don't know how to set up the toString in the Line class.
I don't know where to put if statements for if the points are the same and you need to prompt the user to put in a different 2nd point
I don't know where to put in if statements for the special cases such as if the line the user puts in is a horizontal or vertical line (such as x=4.7 or y=3.4)
Edited by: ta.barber on Apr 20, 2008 9:44 AM
Edited by: ta.barber on Apr 20, 2008 9:46 AM
Edited by: ta.barber on Apr 20, 2008 10:04 AM

Sorry guys, I was just trying to be thorough with the assignment. Its not that if the number is valid, its that you cannot put in the same coordinated twice.
public class Line
     private double x = 0;
     private double y = 0;
     private double m = 0;
     private double x2 = 0;
     private double y2 = 0;
     public Line()
     public Line (Point point1, Point point2)
          this.x = point1.getX();
          this.y = point1.getY();
          this.x2 = point2.getX();
          this.y2 = point2.getY();
          this.m = slope(point1, point2);
     public Line (Point point1, double slope)
          this.x = point1.getX();
          this.y = point1.getY();
     public double slope(Point point1, Point point2)//finds slope
          double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
          return m1;
     public String toString()
          double temp = this.x- this.x2;
          return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
          //y-y1=m(x-x1)
public class Point2Line
     public static void main(String[]args)
          Point p = new Point(3, -3);
          Point x = new Point(10, 7);
          Line l = new Line(p, x);
          System.out.println(l.toString());
}The problem is in these lines of code.
public double slope(Point point1, Point point2) //if this method finds the slope than how would i use the the two coordinates plus "m1" to
          double m1 = (point1.getY() - point2.getY())/(point1.getX() - point2.getX());
          return m1;
     public String toString()
          double temp = this.x- this.x2;
          return this.y + " = " +temp + "" + "(" + this.m + ")" + " " + "+ " + this.y2;
          //y-y1=m(x-x1)
     }if slope method finds the slope than how would i use the the two coordinates + "m1" to create a the line in toString?

Similar Messages

  • Help with objects and classes

    the only problems i have is getting the bestTime value to display at the end and also getting the proper message dialog boxes to appear by calling the other program instead of putting JOptionPane.showInputDialog...... in this part
    Swimmer swim = new Swimmer();
              swim.setName(JOptionPane.showInputDialog(null, "Input user's name"));
              swim.setInitTime(Double.parseDouble(JOptionPane.showInputDialog(null, "Enter initial time")));
              swim.setFinTime(Double.parseDouble(JOptionPane.showInputDialog(null, "Enter final time")));there should be a way i can call the other program where i have the methods in but im not sure as to how to do it.
    import javax.swing.JOptionPane;
    public class Swimmer
         private String name;
         private double initTime;
         private double finalTime;
         private double bestTime = 0;
         public void setName(String n)
              name = n;
         public void setInitTime(double t)
              initTime = t;
         public void setFinTime(double f)
              finalTime = f;
         public void setBest(double b)
              bestTime = b;
         public String getName()
         String userName = "";
              userName = JOptionPane.showInputDialog(null,
              "Input swimmer's name");
              return name;
         public double getInitTime()
              double initialT;
              initialT = Double.parseDouble(
                   JOptionPane.showInputDialog(null, "Enter initial time"));     
              return initTime;
         public double getFinTime()
              double finalT;
              finalT = Double.parseDouble(
                   JOptionPane.showInputDialog(null, "Enter final time"));
              return finalTime;
         public double getBest(double initTime, double finalTime)
              initTime = 0;
              finalTime = 0;     
              double bestTime = 0;
              if (finalTime > initTime)
                   bestTime = initTime;
              else
                   if (initTime > finalTime)
                        bestTime = finalTime;
                   return bestTime;
         public void output()
         String outString = "";
         outString += name + "\n";
         outString += "Best Time: " + bestTime + " seconds\n";
         JOptionPane.showMessageDialog(null, outString);
    }new other java file. the problem i was talking about up top is for this program. instead of using the joption dialog boxes there should be a way to call the other program where i have methods but im not sure how to do it.
    import javax.swing.JOptionPane;
    public class Swimmer2
         public static void main(String[] args)
              Swimmer swim = new Swimmer();
              swim.setName(JOptionPane.showInputDialog(null, "Input user's name"));
              swim.setInitTime(Double.parseDouble(JOptionPane.showInputDialog(null, "Enter initial time")));
              swim.setFinTime(Double.parseDouble(JOptionPane.showInputDialog(null, "Enter final time")));
              swim.output();
    }

    swim.setName(swim.getName());would seem to work.
    Very odd design though.

  • Need help with updates and new apple programs

    something happened to my pc. having problems with my pc when it restarts.
    wondered if anyone whichapple updates require a restart, and which don't?
    if they require a restart to finish installation, they fail, and my pc crashes, and i have to resintall os.
    i know the iwork does not require a restart, where ilife does. so for now, i can install iwork, but not ilife.
    in anyone familiar with 10.5.6 knows which updates/add ond require a restart and which don't, please post. any help appreciated. 4th re install now.

    Hey network --
    Sorry to hear of your problems . . .
    What Mac are you running there?
    Did the installation of 10.5.6 finally go well?
    You're having problems with iLife, but what about Snow Leopard?

  • MOVED: [Athlon64] Need Help with X64 and Promise 20378

    This topic has been moved to Operating Systems.
    [Athlon64] Need Help with X64 and Promise 20378

    I'm moving this the the Administration Forum.  It seems more apporpiate there.

  • Need help with JTextArea and Scrolling

    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import javax.swing.*;
    public class MORT_RETRY extends JFrame implements ActionListener
    private JPanel keypad;
    private JPanel buttons;
    private JTextField lcdLoanAmt;
    private JTextField lcdInterestRate;
    private JTextField lcdTerm;
    private JTextField lcdMonthlyPmt;
    private JTextArea displayArea;
    private JButton CalculateBtn;
    private JButton ClrBtn;
    private JButton CloseBtn;
    private JButton Amortize;
    private JScrollPane scroll;
    private DecimalFormat calcPattern = new DecimalFormat("$###,###.00");
    private String[] rateTerm = {"", "7years @ 5.35%", "15years @ 5.5%", "30years @ 5.75%"};
    private JComboBox rateTermList;
    double interest[] = {5.35, 5.5, 5.75};
    int term[] = {7, 15, 30};
    double balance, interestAmt, monthlyInterest, monthlyPayment, monPmtInt, monPmtPrin;
    int termInMonths, month, termLoop, monthLoop;
    public MORT_RETRY()
    Container pane = getContentPane();
    lcdLoanAmt = new JTextField();
    lcdMonthlyPmt = new JTextField();
    displayArea = new JTextArea();//DEFINE COMBOBOX AND SCROLL
    rateTermList = new JComboBox(rateTerm);
    scroll = new JScrollPane(displayArea);
    scroll.setSize(600,170);
    scroll.setLocation(150,270);//DEFINE BUTTONS
    CalculateBtn = new JButton("Calculate");
    ClrBtn = new JButton("Clear Fields");
    CloseBtn = new JButton("Close");
    Amortize = new JButton("Amortize");//DEFINE PANEL(S)
    keypad = new JPanel();
    buttons = new JPanel();//DEFINE KEYPAD PANEL LAYOUT
    keypad.setLayout(new GridLayout( 4, 2, 5, 5));//SET CONTROLS ON KEYPAD PANEL
    keypad.add(new JLabel("Loan Amount$ : "));
    keypad.add(lcdLoanAmt);
    keypad.add(new JLabel("Term of loan and Interest Rate: "));
    keypad.add(rateTermList);
    keypad.add(new JLabel("Monthly Payment : "));
    keypad.add(lcdMonthlyPmt);
    lcdMonthlyPmt.setEditable(false);
    keypad.add(new JLabel("Amortize Table:"));
    keypad.add(displayArea);
    displayArea.setEditable(false);//DEFINE BUTTONS PANEL LAYOUT
    buttons.setLayout(new GridLayout( 1, 3, 5, 5));//SET CONTROLS ON BUTTONS PANEL
    buttons.add(CalculateBtn);
    buttons.add(Amortize);
    buttons.add(ClrBtn);
    buttons.add(CloseBtn);//ADD ACTION LISTENER
    CalculateBtn.addActionListener(this);
    ClrBtn.addActionListener(this);
    CloseBtn.addActionListener(this);
    Amortize.addActionListener(this);
    rateTermList.addActionListener(this);//ADD PANELS
    pane.add(keypad, BorderLayout.NORTH);
    pane.add(buttons, BorderLayout.SOUTH);
    pane.add(scroll, BorderLayout.CENTER);
    addWindowListener( new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    public void actionPerformed(ActionEvent e)
    String arg = lcdLoanAmt.getText();
    int combined = Integer.parseInt(arg);
    if (e.getSource() == CalculateBtn)
    try
    JOptionPane.showMessageDialog(null, "Got try here", "Error", JOptionPane.ERROR_MESSAGE);
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Got here", "Error", JOptionPane.ERROR_MESSAGE);
    if ((e.getSource() == CalculateBtn) && (arg != null))
    try{
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 1))
    monthlyInterest = interest[0] / (12 * 100);
    termInMonths = term[0] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 2))
    monthlyInterest = interest[1] / (12 * 100);
    termInMonths = term[1] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    if ((e.getSource() == CalculateBtn) && (rateTermList.getSelectedIndex() == 3))
    monthlyInterest = interest[2] / (12 * 100);
    termInMonths = term[2] * 12;
    monthlyPayment = combined * (monthlyInterest / (1 - (Math.pow (1 + monthlyInterest,  -termInMonths))));
    lcdMonthlyPmt.setText(calcPattern.format(monthlyPayment));
    catch(NumberFormatException ev)
    JOptionPane.showMessageDialog(null, "Invalid Entry!\nPlease Try Again", "Error", JOptionPane.ERROR_MESSAGE);
    }                    //IF STATEMENTS FOR AMORTIZATION
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 1))
    loopy(7, 5.35);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 2))
    loopy(15, 5.5);
    if ((e.getSource() == Amortize) && (rateTermList.getSelectedIndex() == 3))
    loopy(30, 5.75);
    if (e.getSource() == ClrBtn)
    rateTermList.setSelectedIndex(0);
    lcdLoanAmt.setText(null);
    lcdMonthlyPmt.setText(null);
    displayArea.setText(null);
    if (e.getSource() == CloseBtn)
    System.exit(0);
    private void loopy(int lTerm,double lInterest)
    double total, monthly, monthlyrate, monthint, monthprin, balance, lastint, paid;
    int amount, months, termloop, monthloop;
    String lcd2 = lcdLoanAmt.getText();
    amount = Integer.parseInt(lcd2);
    termloop = 1;
    paid = 0.00;
    monthlyrate = lInterest / (12 * 100);
    months = lTerm * 12;
    monthly = amount *(monthlyrate/(1-Math.pow(1+monthlyrate,-months)));
    total = months * monthly;
    balance = amount;
    while (termloop <= lTerm)
    displayArea.setCaretPosition(0);
    displayArea.append("\n");
    displayArea.append("Year " + termloop + " of " + lTerm + ": payments\n");
    displayArea.append("\n");
    displayArea.append("Month\tMonthly\tPrinciple\tInterest\tBalance\n");
    monthloop = 1;
    while (monthloop <= 12)
    monthint = balance * monthlyrate;
    monthprin = monthly - monthint;
    balance -= monthprin;
    paid += monthly;
    displayArea.setCaretPosition(0);
    displayArea.append(monthloop + "\t" + calcPattern.format(monthly) + "\t" + calcPattern.format(monthprin) + "\t");
    displayArea.append(calcPattern.format(monthint) + "\t" + calcPattern.format(balance) + "\n");
    monthloop ++;
    termloop ++;
    public static void main(String args[])
    MORT_RETRY f = new MORT_RETRY();
    f.setTitle("MORTGAGE PAYMENT CALCULATOR");
    f.setBounds(600, 600, 500, 500);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }need help with displaying the textarea correctly and the scroll bar please.
    Message was edited by:
    new2this2020

    What's the problem you're having ???
    PS.

  • Need help with trim and null function

    Hi all,
    I need help with a query. I use the trim function to get the first three characters of a string. How do I write my query so if a null value occurs in combination with my trim to say 'Null' in my results?
    Thanks

    Hi,
    Thanks for the reply. What am I doing wrong?
    SELECT trim(SUBSTR(AL1.user_data_text,1,3)),NVL
    (AL1.user_data_text,'XX')
    FROM Table
    I want the XX to appear in the same column as the
    trim.The main thing you're doing wrong is not formatting your code. The solution may become obvious if you do.
    What you're saying is:
    SELECT  trim ( SUBSTR (AL1.user_data_text, 1, 3))
    ,       NVL ( AL1.user_data_text, 'XX' )
    FROM    Tablewhich makes it clear that you're SELECTing two columns, when you only want to have one.
    If you want that column to be exactly like the first column you're currently SELECTing, except that when that column is NULL you want it to be 'XX', then you have to apply NVL to that column, like this:
    SELECT  NVL ( trim ( SUBSTR (AL1.user_data_text, 1, 3))
                , 'XX'
    FROM    Table

  • 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 JFormattedTextField and DocumentListener

    I can't get my JTextField to work with my DocumentListener. I'm very new to Java so the solution might be quite simple. Any help is very appreciated!
    Here is my complete code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.JFormattedTextField.AbstractFormatter;
    import java.text.*;
    public class Test extends JFrame {
    private JFormattedTextField eingabeFeld;
    private JFormattedTextField ausgabeFeld;
    private String eingabe;
    private String ausgabe;
    public Test() {
         super("DocumentListener-Test");
         NumberFormatter textFormatter = new NumberFormatter(new DecimalFormat("###,##0.0#"));
         textFormatter.setCommitsOnValidEdit(true);
         textFormatter.setAllowsInvalid(false);
         DefaultFormatterFactory fmtFactory = new DefaultFormatterFactory(textFormatter);
         EingabeListener eingabeListener = new EingabeListener();
         JFormattedTextField eingabeFeld = new JFormattedTextField();
         eingabeFeld.getDocument().addDocumentListener(eingabeListener);
         eingabeFeld.getDocument().putProperty("name", "EingabeFeld");
         eingabeFeld.setFormatterFactory(fmtFactory);
         AbstractFormatter formatter = eingabeFeld.getFormatter();
         JFormattedTextField ausgabeFeld = new JFormattedTextField();
         ausgabeFeld.setEditable(false);
         // this is not needed!
         //ausgabeFeld.getDocument().addDocumentListener(eingabeListener);
         //ausgabeFeld.getDocument().putProperty("name", "AusgabeFeld");
         //ausgabeFeld.setText("1");
         JPanel contentPane = new JPanel();
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints c = new GridBagConstraints();
         contentPane.setLayout(gridbag);
         c.gridx = 0;
         c.gridy = 0;
         c.ipadx = 200;
         gridbag.setConstraints(eingabeFeld, c);
         contentPane.add(eingabeFeld);
         c.gridx = 0;
         c.gridy = 1;
         c.ipadx = 200;
         gridbag.setConstraints(ausgabeFeld, c);
         contentPane.add(ausgabeFeld);
         setContentPane(contentPane);
    class EingabeListener implements DocumentListener {
         public void insertUpdate(DocumentEvent e) {
              Calculate(e);
         public void removeUpdate(DocumentEvent e) {
              Calculate(e);
         public void changedUpdate(DocumentEvent e) {
         private void Calculate(DocumentEvent e) {
              // this does not work!
              //eingabe = eingabeFeld.getText();
              //double wert = Double.parseDouble(eingabe);
              //wert = wert/2;
              //ausgabe = Double.toString(wert);
              //ausgabeFeld.setText(eingabe);
    public static void main(String[] args) {
         final Test frame = new Test();
         frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
                   System.exit(0);
         frame.pack();
         frame.setVisible(true);
    }

    Thanks that worked! Now I changed
    JFormattedTextField ausgabeFeld = new JFormattedTextField(); to
    ausgabeFeld = new JFormattedTextField(); as well.
    I changed eingabe, ausgabe from String to Object and .getText and .setText into .getValue and .setValue. I also added ausgabeFeld.setFormatterFactory(fmtFactory);
    AbstractFormatter formatteraus = ausgabeFeld.getFormatter();
    But now I have the probelm, that I don't know how to parse the eingabe Object into a double and back to be able to calculate with it.
    And another problem is, that the ausgabeFeld get's only updated and the eingabeFeld formatted if the eingabeFeld loses focus.
    I hope anybody can help me with these problems now! Thanks in advance.

  • Need help with User defined class

    I need to create two Java classes. The first class will be used as a template for objects which represent students, the second will be a program which creates two student object and calls some of their methods.
    Create a file called "Student.java" and in it definr a class called Student which has the following Attributes:
    * a String variable which can hold the student's name
    * a double variable which can hold the studnet's exam mark.
    In the student class, define public methods as follows:
    1 a constructor method which accepts no arguments. This method should initialise the student's name to "unknown" and set the examination mark to zero
    2 A constructor method which accepts 2 arguments- the first being a string representing the student's name and the other being a double which represents their exam mark. These arguments should be used to initialise the state variables with one proviso- the exam mark must not be set to a number outside the range 0...100. If the double argument is outside this range,set the exam mark attribute to 0.
    3 A reader method which returns the students name
    4 A reader method which returns the students exam mark.
    5 A writer method which sets the student's name
    6 A writer method which sets the student's eeam mark. If the exam mark argument is outside the the 0...100 range,the exam mark attibute should not be modified.
    7 A method which returns the studnet's grade. The grade is a string such as "HD" or "FL" which can be determined from the following table.
    Grade Exam Mark
    HD 85..100
    DI 75..84
    CR 65..74
    PS 50..64
    FL 0..49
    Part2 Client Code
    Write a program in a file called "TestStudent.java"
    Make sure the file is in the same directory as tne "Student.java" file
    In the main method of "TestStudent.java" write code to do each of the following tasks
    1 Create a student object using the no argument constructor.
    2 Print this student's name and their exam mark
    3 Create another student object using the other constructor-supply your own name as the string argument and whatever exam mark you like as the double argument
    4 Print this studnet's name and their exam mark
    5 Change the exam mark of this student to 50 and print their exam mark and grade.
    6 Change the examination mark of this studnet to 256 and print their exam mark and grade.
    Can someone please help
    goober

    Sorry, I have sent you the wrong version. Try this,
    public class Student {
         private String name;
         private double examMark;
         public Student() {
              name = "unknown";
              examMark = 0.0;
         public Student(String n, double em) {
              name = n;
              if(em >0 && em < 100) {
                   examMark = em;
              } else {
                   examMark = 0.0;
         public String getName() {
              return name;
         public void setName(String n) {
              name = n;
         public double getExamMark() {
              return examMark;
         public void setExamMark(double em) {
              if(em >0 && em < 100) {
                   examMark = em;
              } else {
                   examMark = 0.0;
         public String getGrade() {
              if ( examMark > 84) return "HD";
              else if(examMark > 74) return "DI";
              else if(examMark > 64) return "CR";
              else if(examMark > 49) return "PS";
              else return "FL";
    } and
    class TestStudent {
         public static void main(String a[]) {
              Student st = new Student();
              System.out.println("Student Name is : "+st.getName());
              System.out.println("Student Marks is : "+st.getExamMark());
              Student st1 = new Student("XXXX",78);
              System.out.println("Student Name is : "+st1.getName());
              System.out.println("Student Marks is : "+st1.getExamMark());
              st1.setExamMark(67);
              System.out.println("Student Marks is : "+st1.getExamMark());
              System.out.println("Student Grade is : "+st1.getGrade());
              st1.setExamMark(256);
              System.out.println("Student Marks is : "+st1.getExamMark());
              System.out.println("Student Grade is : "+st1.getGrade());
    }Hope this helps.
    Sudha

  • I need help with the https class please.

    Hello, i need add an authentication field in my GET request using HTTPS to authenticate users. I put the authentication field using the setRequestProperty method, but it doesn't appear when i print all properties using the getRequestProperties method. I wrote the following code:
    try{
    URL url = new URL ("https://my_url..");
    URLConnection conexion;
    conexion = url.openConnection();
    conexion.setRequestProperty("Authorization",my_urlEncoder_string);
    conexion.setRequestProperty("Host",my_loginServer);
    HttpsURLConnection httpsConexion = (HttpsURLConnection) conexion;
    httpsConexion.setRequestMethod("GET");
    System.out.println("All properties\r\n: " + httpsConexion.getRequestProperties());
    }catch ....
    when i run the program it show the following text:
    All properties: {Host=[my_loginServer]}
    Only the Host field is added to my HttpsURLConnection. The authentication field doesnt appear in standar output. How can i add to my HttpsURLConnection an Authentication field?
    thanks

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • I need help with an Apple ID problem...

    I own a Macbook and an iPod touch, I have downloaded numerous apps for the iPod over the years. 18 months ago my boyfriend got an iPhone 3GS and created an Apple ID but it would not let him download apps due to some kind of issue registering his bank card. At the time I tried to sort it out and told him to get in touch with Apple support but he was impatient and wanted to start getting apps right away so I caved in and let him use my Apple ID. The next day I realised this was a stupid thing to do when all his apps started appearing in my iTunes. However I didn't see it as too much of a problem at the time...
    Tomorrow I am going to pick up my shiny new iPhone 5 (my first iPhone ) and I am worried about plugging it into my Mac and having all these apps that I really don't want around in my iTunes. I am imagining an absolute pain in the bum trying to sort all these apps out and syncing them to the right devices? I would absolutely love to just shift all his apps over to his Apple ID, he has loads of stuff that he needs to keep now. He does not have a computer himself, but there is no real need to plug his iPhone into my macbook ever again. After having a quick read around the forums, there seems to be no simple answer to this problem. If anyone could help with this I would be extremely grateful!

    DoubleSkin wrote:
    I would absolutely love to just shift all his apps over to his Apple ID,
    You can't. All apps are forever tied to the ID used to originally obtain them. In your case, that would be your ID. He really needs to get his own ID, delete these apps, then purchase them using his ID.
    For you, just delete what you don't want from your iTunes library.

  • Need help with  HTML and Swing Components

    Dear All,
    I am using HTML text for Jbutton and Jlabel and MenuItem.
    But when i am trying to disable any of these, its foreground color is not being grayed out.
    For that, I have overrided the setEnable() method as mentioned below:
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.*;
    import javax.swing.plaf.FontUIResource;
    * HtmlLabelEx.java
    public class HtmlLabelEx extends javax.swing.JDialog implements MouseListener{
         * Creates new form HtmlLabelEx
        public HtmlLabelEx(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            initComponents();
            setLayout(null);
            this.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent event)
                    System.exit(0);
            JLabel jLabel1 = new JLabel()
                public void setEnabled(boolean b)
                  super.setEnabled(b);
                  setForeground(b ? (Color) UIManager.get("Label.foreground") : (Color) UIManager.get("Label.disabledForeground"));
            JButton jButton1 = new JButton()
                public void setEnabled(boolean b)
                  super.setEnabled(b);
                  setForeground(b ? (Color) UIManager.get("Label.foreground") : (Color) UIManager.get("Label.disabledForeground"));
            add(jButton1);
            String str = "<html><body><b>Label</b></body></html>";
            System.out.println("str = "+str);
        jLabel1.setText(str);
        add(jLabel1);
        jLabel1.setBounds(10,10,100,20);
        jLabel1.setEnabled(false);
        jButton1.setText("<html><body><b>Button</b></body></html>");
        jButton1.setEnabled(true);
        jButton1.setBounds(10,50,100,20);
        System.out.println("getText = "+jLabel1.getText());
        setSize(400,400);
        addMouseListener(this);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            getContentPane().setLayout(null);
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new HtmlLabelEx(new javax.swing.JFrame(), true).setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
        public void mouseClicked(MouseEvent e)
            if(e.getButton() == e.BUTTON3)
                JMenuItem mit = new JMenuItem("<html><body><b>Menu Item</b></body></html>");
                JPopupMenu pop = new JPopupMenu();
                pop.add(mit);
                mit.setEnabled(false);
                pop.show(this,e.getX(),e.getY());
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
    But, I think it is difficult to write like this for each component.
    I am looking for an optimized solution so that the change will be only in one place.
    so that, It wont leads to change so many pages or so many places.
    And i have the following assumptions to do this. please let me know the possibility.
    1.Implementing custom UI class, extending the JButton/JMenuItem (As the BasicButton/MenuItemUI class does not have setEnabled() method to override) and putting this in UIManager.put("ButtonUI/MenuItemUI","CustomClass).
    2.If there is any possibility to achieve this, by just overriting any key in the UIManager
    3.By setting any client property globally.
    My requirement is to do this only at one place for entire the application.So, that we need not change all the buttoins, sya some 30 buttions are there in a dialog, then we need to override each button class.
    Please suggest me the possibilties..
    Thank you

    Hi camickr ,
    I know that to set the font we have to use component.setfont().
    But, as per my requirement,i am not setting any font to any component in my application.
    i am just passing HTML text along with FONT tags to all the components in my Application.SO, in this case we will get bold letters and that problem fixed when we set swing.boldMetal = false in UI Manager.
    But actual problem irrespective of font settings is when ever we use HTML rendered text, when the button or menuitem is disabled,then that one will not be changed to gray color. i.e., it still looks like normal controls, even it is disabled.(It is also reported as bug)
    But, as per my knowledge we can fix by overrding setEnabled or paint() methods for each and every component.
    But, if we do like that, for an application that has 200 buttons or MenuItems, it is difficult to follow that approach.
    So, We should find a way to achieve that only in one place like using UIManager or other one as i mentioned in previous posts if possible.
    I hope you understood what my problem is exactly.
    Thank You
    Edited by: sindhumourya on Mar 4, 2010 7:26 AM

  • Day one of my new MacBook Pro & I desparately need help with calendar and email

    It's day one of my new relationship with a Mac, and I need help! I'd like to use microsoft exchange to sync my calendars to iCal &amp; my emails the way I currently do with my iPhone 4 and iPad 2. The problem is that all I get are error messages. They either say that communication with the server cannot be established or communication to ports 80 &amp; 440 cannot be established. One account I'd an ssl and the others are gmail. Please advise!

    anyone? please? i would appreciate any information.

  • I am a rookie and need help with max and min values

    Hello all, i am into this intro to java class. my assignment is to write a program that prompts the user for two integers and then prints the sum, difference, average, product , distance (absolute value of the difference) Maximum(largest of the two) and Minimum(smallest fo the two) here is my code so far
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.lang.Math;
    public class Sample4
       public static void main(String[] args) throws IOException
          try // attempt the following
    {           // create the stream to read from
    InputStreamReader istream = new InputStreamReader(System.in);   // create a buffer to hold the stream
    BufferedReader console = new BufferedReader(istream);           // prompt the user
          System.out.println("Enter a number please");              // get input as a string
          String input = console.readLine();                        // convert to an integer
          int num1 = Integer.parseInt(input);
          System.out.println("Enter a number please");              // get input as a string
          String input2 = console.readLine();                       // convert to an integer
          int num2 = Integer.parseInt(input2);
          int sum = num1 + num2;                                    // get the sum of the two inputs
          int difference = num1 - num2;                             // get the difference of the two inputs
          int product = num1 * num2;                                // get the product of the two inputs
          int average = sum / 2;                                    // get the average of the two inputs
          int abs = Math.abs(difference);                           // get the absolute value of the two inputs
              // new section
                 // display the number
          System.out.println("The total sum = " + sum);
          System.out.println("The total difference = " + difference);
           System.out.println("The total product = " + product);
           System.out.println("The total average = " + average);
           System.out.println("The total absolute value = " + abs);
    } // if something breaks, catch the exception
    catch (IOException e)
       System.out.println(e); // displays the exception
       System.exit(1);  // quits the program
    }what will be the right syntax or code to find the MAX and MIN values of two numbers a User Inputs, hope someone can help with this. thank you for your help.

    Thanks alot man, sheesh i do not know why my book
    doesnt give me all the static methods. but i do really
    appreciate your help. peaceA complete list of the java.lang.Math methods can be found at http://java.sun.com/j2se/1.4/docs/api/java/lang/Math.html
    btw,
    max(a, b) == (a > b) ? a : b
    min(a, b) == (a < b) ? a : b

  • Need help with INSERT and WITH clause

    I wrote sql statement which correctly work, but how i use this statment with INSERT query? NEED HELP. when i wrote insert i see error "ORA 32034: unsupported use of with clause"
    with t1 as(
    select a.budat,a.monat as period,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    c.wrbtr,
    c.matnr,
    c.menge,
    a.monat,
    c.zuonr
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='D'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,t2 as(
    select a.BUKRS,a.BELNR, a.GJAHR,t1.vtweg,t1.budat,t1.monat from t1, ldw_v1.bkpf a
    where t1.zuonr=a.xblnr and a.blart='WL' and bukrs='8431'
    ,tcogs as (
    select t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    sum(bseg.wrbtr) as COGS,bseg.matnr,bseg.kunnr,sum(bseg.menge) as QUANTITY
    from t2, ldw_v1.bseg
    where t2.bukrs=bseg.bukrs and t2.belnr=bseg.BELNR and t2.gjahr=bseg.gjahr and BSEG.KOART='S'
    group by t2.budat,t2.monat,t2.vtweg, bseg.gjahr,bseg.hkont,bseg.prctr,
    bseg.matnr,bseg.kunnr
    ,t3 as
    select a.budat,a.monat,b.vtweg,
    c.gjahr,c.buzei,c.shkzg,c.hkont, c.prctr,
    case when c.shkzg='S' then c.wrbtr*(-1)
    else c.wrbtr end as NTS,
    c.matnr,c.kunnr,
    c.menge*(-1) as Quantity
    from ldw_v1.BKPF a,ldw_v1.vbrk b, ldw_v1.bseg c
    where a.AWTYP='VBRK' and a.BLART='RV' and a.BUKRS='8431' and a.awkey=b.vbeln
    and a.bukrs=c.bukrs and a.belnr=c.belnr and a.gjahr=c.gjahr and c.koart='S'
    and c.ktosl is null and c.gsber='4466' and a.gjahr>='2011' and b.vtweg='01'
    ,trevenue as (
    select t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,
    sum(t3.NTS) as NTS,t3.matnr,t3.kunnr,sum(t3.QUANTITY) as QUANTITY
    from t3
    group by t3.budat,t3.monat,t3.vtweg, t3.gjahr,t3.hkont,t3.prctr,t3.matnr,t3.kunnr
    select NVL(tr.budat,tc.budat) as budat,
    NVL(tr.monat,tc.monat) as monat,
    NVL(tr.vtweg,tc.vtweg) as vtweg,
    NVL(tr.gjahr, tc.gjahr) as gjahr,
    tr.hkont as NTS_hkont,
    tc.hkont as COGS_hkont,
    NVL(tr.prctr,tc.prctr) as prctr,
    NVL(tr.MATNR, tc.MATNR) as matnr,
    NVL(tr.kunnr, tc.kunnr) as kunnr,
    NVL(tr.Quantity, tc.Quantity) as Quantity,
    tr.NTS as NTS,
    tc.COGS as COGS
    from trevenue TR full outer join tcogs TC
    on TR.BUDAT=TC.BUDAT and TR.MONAT=TC.MONAT and TR.GJAHR=TC.GJAHR
    and TR.MATNR=TC.MATNR and TR.KUNNR=TC.KUNNR and TR.QUANTITY=TC.QUANTITY
    and TR.VTWEG=TC.VTWEG and TR.PRCTR=TC.PRCTR
    Edited by: user13566113 on 25.03.2011 5:26

    Without seeing what you tried it is hard to say what you did wrong, but this is how it would work
    SQL> create table t ( n number );
    Table created.
    SQL> insert into t
      2  with test_data as
      3    (select 1 x from dual union all
      4     select 2 x from dual union all
      5     select 3 x from dual union all
      6     select 4 x from dual)
      7  select x from test_data;
    4 rows created.
    SQL>

Maybe you are looking for

  • Reading Camera raw progress

    I have two computers - 1 a MAcBook Pro running CS5, the other a PC on Windows 7 running CS4.  IN BOTH CASES I am having trouble processing Raw photogrpahs, once they have been touched once, the first time I opena file it seems OK.  What happens is a

  • Easy and fast building for multiple sites

    Hi all, my first post. So, I've got a lot of sites but right now I am working on about four main ones - all commercial. In the past I had a webmaster but for the short-term and until my company is stronger financially I'm taking on the building again

  • Drag and Drop UI Items vb net

    Hi everybody. This is my question: I need to use drag and drop onto an item, i really don't have any idea how to do this, if anybody can tell me something i'll be very thankful. I'm working with visual basic .net and SBO 2007

  • Setting pages to open .doc files by default

    I have iWork '08 but not MS Word on my MBP. When I get an e-mail attachment that is a .doc file (or an .xls file), I need to save it to the desktop and then open it with Pages or Numbers. Same with old Word files--I can't just open them in Pages by d

  • Generate file on Server

    I have a JSP and i would like to create file localy and remotly : <%@ page language="java" %> <%@ page import="java.io.*" %> <%! String dcr = request.getParameter("dcr"); String contentTplPath = "";           int DebChaine = dcr.indexOf("Dev_Contrib"