Java again please help me

Statistics from a list
CODE
import java.io.*;
import java.util.*;
public class Ex1qu206 {
   public static int min(List l) {
   List mylist = new LinkedList ();
   ListIterator itr = l.listIterator();
   while (itr.hasNext()) {
       Object i = itr.next();
       Integer k = (Integer) i;
       int h = k.intValue();
       Integer j = new Integer(h == 0);
       mylist.add(j);
   return mylist;
   public static double average(List l) {
   List mylist = new LinkedList ();
   ListIterator itr = l.listIterator();
   while (itr.hasNext()) {
       Object i = itr.next();
       Integer k = (Integer) i;
       int h = k.intValue();
       Integer j = new Integer(h * l);
       mylist.add(j);
   return mylist;
  public static void main(String[] args) throws IOException {
   List mylist = new LinkedList();
   BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter a list of integers, separated by a space, all on one line");
   String S = in.readLine();
   StringTokenizer T = new StringTokenizer (S);
   while (T.hasMoreTokens()) {
       mylist.add(new Integer(Integer.parseInt(T.nextToken())));
   System.out.println("Smallest number is " + min(mylist));
   System.out.println("Average is " + average(mylist));
} // Ex1qu1 Merging lists
CODE 
import java.io.*;
import java.util.*;
public class Merge06 {
public static List merge (List l1, List l2) {
     //Fill in code here
public static void main(String[] args) throws IOException {
   List mylist = new LinkedList ();
   List mylist2 = new LinkedList ();
   BufferedReader in =  new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter a list of characters, all on one line, separated by spaces");
   String S = in.readLine();
   StringTokenizer T = new StringTokenizer (S);
   while (T.hasMoreTokens()) {
   mylist.add(new Character((T.nextToken()).charAt(0)));
   System.out.println("Enter another list of characters, all on one line");
   S = in.readLine();
   T = new StringTokenizer (S);
   while (T.hasMoreTokens()) {
   mylist2.add(new Character((T.nextToken()).charAt(0)));
   Collections.sort(mylist);
   Collections.sort(mylist2);
   System.out.println(merge(mylist, mylist2));
} // Merge Merge sort
CODE
import java.io.*;
import java.util.*;
public class MSort06 {
static List  take (List l, int n) {
   List tmp = new LinkedList ();
   ListIterator itr = l.listIterator();
   for (int i = 1; i <= n && itr.hasNext(); i++) {
     tmp.add(itr.next());
   return tmp;
static List drop (List l, int n) {
   List tmp = new LinkedList ();
   ListIterator itr = l.listIterator();
   while (itr.hasNext()) {
     tmp.add(itr.next());
   for (int i = 1; i <= n && ! tmp.isEmpty(); i++) {
     tmp.remove(0);
   return tmp;
static List merge (List l1, List l2) {
     //Fill in code here
public static void msort (List l) {
     //Fill in code here
public static void main(String[] args) throws IOException {
   List mylist = new LinkedList ();
   System.out.println("Enter a list of characters, all on one line, separated by spaces");
   BufferedReader in =  new BufferedReader(new InputStreamReader(System.in));
   String S = in.readLine();
   StringTokenizer T = new StringTokenizer (S);
   while (T.hasMoreTokens()) {
   mylist.add(new Character((T.nextToken()).charAt(0)));
   msort(mylist);
   System.out.println(mylist);
} // MSort06 i am trying to write the codes which are empty above but it dont work. Please check my program for me.
Thanks in advance 

complete the methods so that they satisfy the pre- and post- conditions shown below.
   *Method : min
   *Pre : l is not null, and all the objects in it are Integer
   *Post : the smallest integer value is returned.
    public static int min(List l) {
     //Fill in code here
   *Method : average
   *Pre : l is not null, and all the objects in it are Integer
   *Post : the average of the integer values is returned.
    public static double average(List l) {
     //Fill in code here
    }thats the Ex1qu206.java
a sample run might be:
Enter a list of characters, all on one line, separated by spaces
a n d y
Enter another list of characters, all on one line
g e o r g e
[a, d, e, e, g, g, n, o, r, y]
this is for Merge06.java.
       *Method : msort
       *Pre : l is a list of Comparable objects
       *Post : l has been sorted into ascending order
       */this is the MSort06.java
i hope that helps

Similar Messages

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

  • HT1349 The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only t

    The nice man Joseph Shen helped me with my google problem on my iPhone and worked for 2 days and now not working again please help me solve this problem were I can retrieve my messages on the I phone when I am not at home  on my wi Fi is the only time it works correct. Bill. [email protected]  708 752  3667 

    http://lifehacker.com/5852948/what-to-do-if-youve-forgotten-your-iphones-passcod e

  • I am not able to sign into i message, it keeps giving me a message "could not sign in. Please check your network connection and try again" Please help!!

    i am not able to sign into i message, it keeps giving me a message "could not sign in. Please check your network connection and try again" Please help!!

    FaceTime, Game Center, Messages: Troubleshooting sign in issues

  • After cleaning my mac it opens and shuts down again please help!!!

    after cleaning my mac it opens and shuts down again please help!!!

    I opened the cover (there where the battery is) and I cleaned the dust gently with a dry napkin ...remove the battery and placed it again ...closed the cover and when i turn on my macbook bro now it shows the Apple logo and after some seconds it just shuts down (i have OSX 10.9 Mavericks)....
    I tried to boot in safe mode, also tried to repair it and even re-install Mavericks and so on, but I could not fix it. I did a hardware test and the no problems occurred.

  • When i turn on my iphone 5s gold,it keeps on showing the apple logo then turns off. i have put it in recovery mode twice. it will work a week or two then back again. please help! thanks you

    when i turn on my iphone 5s gold,it keeps on showing the apple logo then turns off. i have put it in recovery mode twice. it will work a week or two then back again. please help! thanks you

    hi
    ... i  have  a similar problem
    but  just  with  the sleep botton.
    fist use  your adapter with other iphone/itouch ... is posible itś the  problem
    second ..  let your  phone charging
    ...normally if  we  conect  our  phone ... after  some minuts  it's put on.
    after 2 hours ... trate   to use  it ... if  after  it  your phone continue same... could  be qaa electrical/physic problem
    please  if you  have a guaranty use it.
    im  sorry but  my english   is terrible.

  • I am using iphone 4 (MC603B, version 4.3(8F190) and never updated it. as i have formated my laptop; i have to download itunes again. please help me to download itunes which suits this version. where can i get the link. thank you.

    I am using iPhone 4 (MC603B, version 4.3(8F190) and never updated it. as i have formatted my laptop; i have to download iTunes again. please help me to download iTunes which suits this version. where can i get the link. thank you.

    Older iTunes versions can be downloaded here: Apple - Support - Downloads
    Follow these steps to get your data to your new computer:
    Syncing to a "New" Computer or replacin…

  • My ipod keeps asking me to restore and when i do restore it just restarts and asks me to connect to itunes and starts again.please help its my sons bday and this is his present

    my ipod keeps asking me to restore and when i do restore it just restarts and asks me to connect to itunes and starts again.please help its my sons bday and this is his present

    Maybe:
    Restore loop (being prompted to restore again after a restore successfully completes)
    Troubleshoot your USB connection. If the issue persists, out-of-date or incorrectly configured third-party security software may be causing this issue. Please follow Troubleshooting security software issues. .
    Next try placing in DFU mode and then restoring.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    Then try restoring on another computer.
    Last, make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • I intended to install windows on my macbook, but I removed Mac os X wrongly! Now I don't know how to install Mac again please help me.

    I intended to install windows on my macbook, but I removed Mac os X wrongly! Now I don't know how to install Mac again please help me.

    I still don't know which version of OSX you have but assuming it's 10.7 or 10.8 .....
    You need to press command-R (at the sound of the chime) to get into recovery, try that, if it does not work try command-option-R for Internet Recovery.

  • Novice Java Test- please help!

    hi I'm new to java and am required to know how to program a certain problem.
    please any help is much appreciated. If you can solve the problem that would be nice or if you could tell me how to go about solving it that would be fine too.
    here's the problem:
    "1. Write a class UniDBug that models a bug moving along a horizontal line, the x number line. The bug moves either to the right or left. Initially, the bug moves in the direction it is facing, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide a constructor and default constructor. (Default constructor not shown)
    Public Bug(int intialPosition, int facingDirection)
    // facingDirection 1 means to the left, and 2 means to the right
    and the following methods:
    public void turn()
    public void move()
    public int getPosition()
    2. Write the test program for this class with two bugs, *redBug*, and *blueBug* facing each other, one starting at position 15 and the other at position 3. They should take enough steps to both bugs meet at location 23. Include a print statement whenever a change happens and make sure you identify the bug and the location."
    again any help is much appreciated
    thank you for your time

    thx im gonna do that right now:
    "public class UniDBug
         Public Bug(int initialPosition, int faceingDirection);
         UniDBug myBug = new UniDBug();
         public void myBug.drive(100);
         public void move();
              public int getPosition(x);
                   position=3;
                        public void turn(1,2);"
    obviously, it needs a lot of work

  • URGENT!!! Java Gurus Please Help with adf issue!

    PLEASE SEE MY LATEST POST BELOW TIMO'S RESPONSE. THE REQUIREMENT HAS CHANGED. THAT IS THE ISSUE I AM LOOKING A SOLUTION FOR.
    Hello All,
    We have a requirement where our adf/jsf app needs to pick an EXCEL file from the server where the application is deployed. The sequence is :
    User comes to the page
    Clicks on "Open EXCEL" button
    EXCEL file located in the c:/ of the server opens up.
    How can this be done? I do not see any coding needed because the EXCEL file is being opened as is (and after user views it he closes the file) and the data is not being transferred to the jspx page.
    *We are totally flexible in how this is implemented - ie, using button, link , html etc etc. What ever works!!!!*
    Thanks,
    Edited by: user12054715 on Aug 17, 2010 8:54 PM
    Edited by: user12054715 on Aug 18, 2010 4:11 PM
    Edited by: user12054715 on Aug 18, 2010 4:13 PM

    Hello Timo,
    I am using 10.1.3g so your response is not going to help me.
    However, I have another question that I have already posted on the Forum. Please help me...
    Requirement:
    *1. Java application should be able to write "Hello World" in the excel file, when the user opens it.*
    I CAN DO THIS WITH THE FOLLOWING CODE:
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("newSheet");
    HSSFRow row = sheet.createRow(1);
    row.createCell(1).setCellValue("HelloWorld!!!!!!!!!");
    *2. A "Write To Excel" button on jsf page opens a dialog asking user to Save or Open the excel file. (user can save the file anywhere on his machine)*
    I CAN DO THIS WITH THE FOLLOWING CODE:
    In jsf:
    <af:commandButton text="Download" action="#{myBackingBean.writeToExcel}" useWindow="true"/>
    In backing bean:
    public static void writeToExcel() throws IOException
    String filename = "workbook.xls";
    // //Setup the output
    String contentType = "application/vnd.ms-excel";
    FacesContext fc = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse();
    response.setHeader("Content-disposition", "attachment; filename=" + filename);
    response.setContentType(contentType);
    PrintWriter out = response.getWriter();
    BOTTLENECK: When the user opens the excel how do I show "HelloWorld!!!!!!!!!" ?

  • No Java? Please help me

    Every Javascript I try to load always gives me a Coffee Cup with a "!" in the middle of it. I have the latest version of Mac OS and Safari. What can I do?

    Ok..
    Try troubleshooting the Safari .plist file.
    Open a Finder window. Select your Home Folder in the Sidebar on the left. It has a small house icon. Then open the Library folder then the Preferences folder.
    Move the com.apple.Safari.plist file from the Preferences folder to the Desktop. Now launch Safari. If Java loads on sites correctly, them move the .plist file to the Trash.
    Also, click the Apple logo top left in your screen, then scroll down and click: Software Update.
    Make sure your system software is up to date.
    If nothing above helped, go to Applications/Utilities. Launch the Java Preferences applications.
    Select the Network tab. Click: Delete Files
    Relaunch Safari and try Java again.

  • HT204380 have anyone have problem activating their facetime? it says...could not sign in. please check your network connection and try again. please help.

    when activating facetime, it says...could not sign in. please check your network connection and try again. never tried facetime with my account. i tried to register with other apple ID but it does not help. please help.

    a lot of us are in the same boat - no help from anyone as of yet

  • How to program this in java? Please help

    How to program this in java?
    please explain steps, it has to come out like this:
    example
    input: 3b1w3b
    output:
    BBBWBBB

    import java.io.*;
    public class Test {
    static java.io.PrintStream o = java.lang.System.out;
    public static void main(String[] args)throws Exception {      
         BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Enter plot for printing: ");
         String s = BR.readLine();
         char[] cs = s.toLowerCase().toCharArray();
         for(int i=0, j=0; i < cs.length-0x1; i+=0x2, j=0)
              while(j++ < (int)(cs[i]-0x30))
                   o.print((char)(cs[i+0x1]-0x20));
    I tried changeing it to this so I can enter my own string, but I want to change it some more so that it can enter multiple input separated by space, so that it can form a sort of picture line by line. I tried using tolkenizer but I get errors. I dont know how to use tolkenizer properly can anyone please TEACH. you dont have to tell how or give me the code if you dont want to. yes I know Im a noob and I dont know java as good as everyone here, If everyone thinks I don't deserve help then DON'T help, I'm just trying to learn programming

  • Java Import -- please help!!!

    I look into http://otn.oracle.com/sample_code/products/forms/content.html for the demo of Java Importer.
    Does anyone knows where / how can I get the source code?
    According to that demo, the Importer creates functions called new() for each of the constructors in the class.
    For me, after I imported one of the class "successfully",
    I can't see this function new().
    How can I get it? Does anyone has the sample code for the package body?
    Please help!!! Anybody?
    thanks

    Hi Shay,
    Where is this src subdirectory?
    I see other demo (i.e the Oracle 9i forms demos) with source in it, but not Java Importer demo. It only has Viewlet next to it.
    Am I looking into the wrong thing?
    thanks

Maybe you are looking for