It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

exam prep(1)

exam prep(1)

Postby danielle on Mon Apr 30, 2007 3:32 pm

hi everyone, i am currently studying in university and i am studying object orientated programming. i am struggling quiet a bit and would really appreciate any help whatsoever withe following questions or maybe relevant web links...
( i am not cheating these are genuinely revision questions)

1.. Write a method called multiConcat that takes a String and an integer as
parameters. Return a String that consists of the string parameter concatenated with
itself count times, where count is the integer parameter. For example, if the
parameter values are "hi" and 4, the return value is " h i h i h i h i " . Return the
original string if the integer parameter is less than 2.



2. Create an interface called VCR that has methods that represent the standard operations
on a video cassette recorder (play, stop, etc.). Define the method signatures any way
you desire. Describe how a class might implement this interface.



3
. Write a Java applet that reads in two floating-point numbers and determines if the first
number is smaller than the second. Make use of the input dialogs to read the values
of two floating-point numbers. Display the output in the form:
"<Smallestinput_value> is the Smallest of the two numbers".
danielle
 
Posts: 3
Joined: Mon Apr 30, 2007 3:25 pm

Postby Stiks on Tue May 01, 2007 1:34 am

I think I can answer the first one, but I'm also still learning, so someone can check me on this:

Code: Select all
public String multiConcat(String word, int number)
{
       String concated = "";
       
        if (number >= 2)
        {
                 for (int i = 0; i <= number; i++)
                 {
                          concated += word
                 }
         }

         else
         {
                   return word;
         }

          return concated;
}
Stiks
 
Posts: 7
Joined: Wed Apr 18, 2007 2:25 am

Postby gejixin on Thu May 03, 2007 12:41 pm

you can have a try
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldDemo extends JFrame implements ActionListener {
private JTextField jtfNum1,jtfNum2,jtfResult;
private JButton jbtMini;
public static void main(String [] args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
}
TextFieldDemo frame=new TextFieldDemo();
frame.pack();
frame.setVisible(true);
}
public TextFieldDemo(){
setTitle("TextFieldDemo");
setBackground(Color.YELLOW);
setForeground(Color.BLACK);
JPanel p1=new JPanel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel("Number 1"));
p1.add(jtfNum1=new JTextField(3));
p1.add(new JLabel("Number2"));
p1.add(jtfNum2=new JTextField(5));
p1.add(new JLabel("Result"));
p1.add(jtfResult=new JTextField(8));
jtfResult.setEditable(false);
jtfResult.setBackground(Color.WHITE);
JPanel p2=new JPanel();
p2.setLayout(new FlowLayout());
p2.add(jbtMini=new JButton("The Minimize"));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);
jbtMini.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jbtMini){
int num1=(Integer.parseInt(jtfNum1.getText().trim()));
int num2=(Integer.parseInt(jtfNum2.getText().trim()));
int result=num1>num2?num2:num1;
jtfResult.setText(String.valueOf(result));
}
}
}
gejixin
 
Posts: 2
Joined: Thu May 03, 2007 11:57 am


Who is online

Users browsing this forum: No registered users and 2 guests