EasyIn

I am new to java and trying to get input from the console. Previoud method was to use BufferedReader and get string input first and convert it to int. Now i see this EasyIn.getInt(), getChar(). I do not know how to use these methods. Do i need to override them in a seprate class and use it or what about import uwejava.*;. if i use the import statement my IDE MYEclipse says unable to resolve this name. Can anyone please tell me how to use the EasyIn methods please.

I am new to java and trying to get input from the
console. Previoud method was to use BufferedReader
and get string input first and convert it to int. Now
i see this EasyIn.getInt(), getChar(). I do not know
how to use these methods. Do i need to override them
in a seprate class and use it or what about import
uwejava.*;. if i use the import statement my IDE
MYEclipse says unable to resolve this name. Can
anyone please tell me how to use the EasyIn methods
please.Easyln is apparently some cracked out third party POS. Try:
java.util.ScannerHere is the documentation:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
That should do what you want.

Similar Messages

  • Problem with EasyIn.java

    Well i've found EasyIn.java but when i try to compile my HelloWorld.java program the following error message occurs, can anyone explain this?
    HelloWorld.java :6: cannot resolve symbol
    symbol: variable EasyIn
    location: class HelloWorld
    EasyIn.pause ();
    ^
    1 error
    Thankyou in advance to anyone who can help

    English translation in bold.
    Well i've found EasyIn.java but when i try to compile
    my HelloWorld.java program the following error message
    occurs, can anyone explain this?
    HelloWorld.java :6: cannot resolve symbol
    On line 6 of the file "HelloWorld.java", I found a symbol that I do not recognize.
    symbol: variable EasyIn
    The symbol that I could not recognize at the above location is a variable called "EasyIn".
    location: class HelloWorld
    The location where that variable was used is found in the class "HellowWorld"
    EasyIn.pause ();
    ^
    Here is the line I'm having trouble with. The ^ points to the start of my worries.
    >
    1 error
    By the way, here is a count of how many errors I've found in your code.
    Basically, the compiler is complaining that it could not find the EasyIn class. Make sure you've compiled this class, and your classpath included it's location.

  • EasyIn.java - Who's the author?

    Hi people, newbie poster so please excuse any dumbness...
    A couple of years ago I was given a EasyIn.java file as part of a practical Introducing me to Java. For the last couple of years, whenever I've needed some simple input from the command line, i've used this same class.
    However, I'm now about to submit a Major Software Project for my penultimate year and it has just struck me that I don't know who the author of the class is? There are no comments in the file and a google search has yielded no result.
    So I ask you dear people if anyone knows the author so that I may cite the use of their code in my report?
    Regards
    J

    That seems to be a different class to the one I have:
    import java.io.*;
    public abstract class EasyIn {
         public static String getString() {
              boolean ok = false;
              String s = null;
              while (!ok) {
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        s = s.trim();
                        ok = true;
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return s;
         public static int getInt()
              int i = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        i = Integer.parseInt(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter an integer");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return i;
         public static byte getByte()
              byte i = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        i = Byte.parseByte(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter a byte");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return i;
         public static short getShort()
              short i = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        i = Short.parseShort(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter a short integer");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return i;
         public static long getLong()
              long l = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        l = Long.parseLong(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter a long integer");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return l;
         public static double getDouble()
              double d = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        d = Double.parseDouble(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter a decimal number");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return d;
         public static float getFloat()
              float f = 0;
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        f = Float.parseFloat(s.trim());
                        ok = true;
                   catch (NumberFormatException e)
                        System.out.println("Make sure you enter a decimal number");
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return f;
         public static char getChar()
              char c = ' ';
              boolean ok = false;
              String s;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        s = new String(b);
                        if (s.trim().length() != 1)
                             System.out
                                       .println("Make sure you enter a single character");
                        else
                             c = s.trim().charAt(0);
                             ok = true;
                   catch (IOException e)
                        System.out.println(e.getMessage());
              return c;
         public static void pause()
              boolean ok = false;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.in.read(b);
                        ok = true;
                   catch (IOException e)
                        System.out.println(e.getMessage());
         public static void pause(String messageIn)
              boolean ok = false;
              while (!ok)
                   byte[] b = new byte[512];
                   try
                        System.out.print(messageIn);
                        System.in.read(b);
                        ok = true;
                   catch (IOException e)
                        System.out.println(e.getMessage());
    }

  • EasyIn class?

    ;-) It is a start, I have many battles to face and attack, my lecturer has thrown up this class "EasyIn()" and I don't know where it is to be placed. It controls the size of the plane list. All I know is that it is mentioned in the remove method (AirplaneListTester)
    int plane = EasyIn.getInt();
    this code probably checks the position of the plane in the list.
    placed in the main method of the AirplaneListTester
    int size;
    size = EasyIn.getInt();
    The EasyIn class is :
    // EasyIn.java
    import java.io.*;
    public abstract class EasyIn
    static String s = new String();
    static byte[] b = new byte[512];
    static int bytesRead = 0;
    public static String getString()
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    s=s.trim();
    ok = true;
    catch(IOException e)
    System.out.println(e.getMessage());
         return s;
    public static int getInt()
    int i = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    i = Integer.parseInt(s.trim());
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make sure you enter an integer");
    catch(IOException e)
    System.out.println(e.getMessage());
    return i;
    public static byte getByte()
    byte i = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    i = Byte.parseByte(s.trim());
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make sure you enter a byte");
    catch(IOException e)
    System.out.println(e.getMessage());
    return i;
    public static short getShort()
    short i = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    i = Short.parseShort(s.trim());
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make sure you enter a short integer");
    catch(IOException e)
    System.out.println(e.getMessage());
    return i;
    public static long getLong()
    long l = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    l = Long.parseLong(s.trim());
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make surre you enter a long integer");
    catch(IOException e)
    System.out.println(e.getMessage());
    return l;
    public static double getDouble()
    double d = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    d = (Double.valueOf(s.trim())).doubleValue();
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make sure you enter a decimal number");
    catch(IOException e)
    System.out.println(e.getMessage());
    return d;
    public static float getFloat()
    float f = 0;
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    f = (Float.valueOf(s.trim())).floatValue();
    ok = true;
    catch(NumberFormatException e)
    System.out.println("Make sure you enter a decimal number");
    catch(IOException e)
    System.out.println(e.getMessage());
         return f;
    public static char getChar()
    char c = ' ';
    boolean ok = false;
    while(!ok)
    try
    bytesRead = System.in.read(b);
    s = new String(b,0,bytesRead-1);
    if(s.trim().length()!=1)
    System.out.println("Make sure you enter a single character");
    else
    c = s.trim().charAt(0);
    ok = true;
    catch(IOException e)
    System.out.println(e.getMessage());
    return c;
    public static void pause()
    boolean ok = false;
    while(!ok)
    try
    System.in.read(b);
    ok = true;
    catch(IOException e)
    System.out.println(e.getMessage());
    public static void pause(String messageIn)
    boolean ok = false;
    while(!ok)
    try
    System.out.print(messageIn);
    System.in.read(b);
    ok = true;
    catch(IOException e)
    System.out.println(e.getMessage());
    The code I have made so far is this:
    import javax.swing.JOptionPane; //indicates that the compiler should load class JOptionPane for use in this application.
    public class AirplaneListTester
         public static class AirplaneList
         //Attributes for the AirplaneList
         private String flight = "No plane" ; //Airplane's name
         private int total = 0;     //initial total
         private boolean Empty = true; //initially the list is empty
         private boolean     Full = false; //The list initially has no entries therefore it is not full
         // Constructor method
         public AirplaneList()
              total = 0;
    //     public void add(String Airplane)
    //          flight = Airplane; // The airplane object will be "flight"
    //     }     //add()
    //     public void remove(int inti)
    //          total = inti;
    //     }     //remove()
         public boolean isEmpty()
              Empty = true;
              Full = false;
              return Empty;
         public boolean isFull()
              Empty = false;
              Full = true;
              return Full;
    //     public void item(int inti)
    //          total = inti;
    //          System.out.println(flight+ "is number ");
    //          System.out.println(total+ "");
         public void Total()
              System.out.println(total+ "planes on the list");
              return;
    //     public void getInt()
         public static void main (String[] args)
    throws java.io.IOException
              char choice; //Words choice and size are the names of variables
         //     int size; //This declaration specifies that the variable are of data type char and int
         //     size = EasyIn.getInt(); // Converts size from int to something?
         //Char - a variable that may only hold a single lowercase letter, a single uppercase letter, a single digit or a special character //(such as x, $, 7 and *)
         AirplaneList plane = new AirplaneList(); // Declare AirplaneList variables
         // The code below creates a dialog box for the user to input a choice
         String inputcode;
         inputcode = JOptionPane.showInputDialog("A: add an airplane from the list\n" +
                                  "B: remove an airplane from the list\n" +
                                  "C: check if the list is empty\n" +
                                  "D: check if the list is full\n" +
                                  "E: display the list\n" +
                                  "F: quit\n" );
         //The null first argument indicates that the message dialog will appear in the center of the screen. The 2nd is the message to display
    do
         // get choice from user
         choice = inputcode.toUpperCase().charAt(0);
              System.out.println();
              //process menu options
              switch(choice)
                   case 'A':               
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        //option1(plane); // Checks if plane is empty
                        break;     //done processing case
                   case 'B':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        //option2(plane); // Checks if plane is empty
                        break;     //done processing case
                   case 'C':
                        option3(plane); // Checks if plane is empty
                        break;     //done processing case
                   case 'D':
                        option4(plane); // Checks if plane is full
                        break;     //done processing case
                   case 'E':
                        JOptionPane.showMessageDialog(null, "Case " + inputcode);
                        //option5(plane); // Checks if plane is empty
                        break;     //done processing case
                   case 'F':
                        JOptionPane.showMessageDialog(null, "You have chosen to quit the program");
                        break;     //done processing case
                   default:
                        JOptionPane.showMessageDialog(null, "Invalid entry!, Please choose another option");
                        if (choice!= 'A'||
              choice!= 'B'||      
                        choice!= 'C'||
                        choice!= 'D'||
                        choice!= 'E'||
                        choice!= 'F');
                        inputcode = JOptionPane.showInputDialog("A: add an airplane from the list\n" +
                                  "B: remove an airplane from the list\n" +
                                  "C: check if the list is empty\n" +
                                  "D: check if the list is full\n" +
                                  "E: display the list\n" +
                                  "F: quit\n" );
                        break;     //done processing case
         }while (choice!= 'F' ); //end AirplaneList tester
    System.exit(0); //Terminates the program
    //add Airplane
         public static void option1(AirplaneList plane)
              String flight;
         flight = JOptionPane.showInputDialog("Please enter airplane filght number" );
              //create an Airplane object to add to list          Airplane flight = new Airplane();
              //add string to list if the list is not full
              //access the 'add(Airplane)' method from the AirplaneList class;
              //if the list is full, return a statement to the user indicating that no more plane can be added onto the list
         //remove airplane
         public static void option2(AirplaneList plane)
              //get position of item
         string enterpos;
         enterpos = JOptionPane.showInputDialog("Please enter position to remove" );
              System.out.print(":")
              int plane = Easyln.getint();
              // delete item if it exists
              //access the 'remove(Airplane)' method from the AirplaneList class;
              //if the user enter an invalid number for the position, returen a statement
              //indicating that there is no such posititon.
         //check if empty
         public static void option3(AirplaneList plane)
              if (plane.isEmpty())
                   JOptionPane.showMessageDialog(null, "The list is empty");
              else
                   JOptionPane.showMessageDialog(null, "list is not empty" );
         //check if full
         public static void option4(AirplaneList plane)
              if (plane.isFull())
                   JOptionPane.showMessageDialog(null, "list is full" );
              else
                   JOptionPane.showMessageDialog(null, "list is not full" );
    /*     //display list
         public static void option5 (AirplaneList plane)
              if (plane.isEmpty())     //no need to display if list is empty
                   JOptionPane.showMessageDialog(null, "list is empty" );
              else
                   JOptionPane.showMessageDialog(null, "Airplanes in list are" );
                   //loop through list

    ;-) It is a start, I have many battles to face and
    attack, my lecturer has thrown up this class
    "EasyIn()" and I don't know where it is to be placed.
    It controls the size of the plane list. Not quite. It is simply a utility class to help with reading user input in non-gui applications.
    Just place the class file somewhere in your classpath.

  • Java newbie (what's could be wrong with this program?)

    First things first, I just started programming with JAVA recently so please forgive me if it seems stupid. Since I am so relatively new to the language, in order to get a feel for it I started running some simple scripts. I can compile and execute most of them without any problem. However when I tried to compile this one I get a couple of errors I am not familiar with. So my question is what could be wrong and what needs to be changed in order to get it to work? or if the syntax is correct could there be some other problem?
    On a side note, I am coming more from a C and C++ background so if anyone can recommend a way to start learning the JAVA language from a prespective in C that would be highly appreciated.
    System Environment: I am using j2sdk1.4.2 on a Windows 2000 machine running SP3.
    If anything else needs further clarification please let me know.
    |------------------------- The Code -----------------------------------|
    package RockPaperScissors;
    import java.util.HashMap;
    public class RockPaperScissors {
    String[] weapons = {"Rock", "Paper", "Scissors"};
    EasyIn easy = new EasyIn();
    HashMap winners = new HashMap();
    String playerWeapon;
    String cpuWeapon;
    int cpuScore = 0;
    int playerScore = 0;
    public static void main(String[] args) {
    RockPaperScissors rps = new RockPaperScissors();
    boolean quit = false;
    while (quit == false) {
    rps.playerWeapon = rps.getPlayerWeapon();
    rps.cpuWeapon = rps.getCpuWeapon();
    System.out.println("\nYou chose: " + rps.playerWeapon);
    System.out.println("The computer chose: " + rps.cpuWeapon + "\n");
    rps.getWinner(rps.cpuWeapon, rps.playerWeapon);
    if (rps.playAgain() == false) {
    quit = true;
    System.out.println("Bye!");
    public RockPaperScissors() {
    String rock = "Rock";
    String paper = "Paper";
    String scissors = "Scissors";
    winners.put(rock, scissors);
    winners.put(scissors, paper);
    winners.put(paper, rock);
    System.out.println("\n\t\tWelcome to Rock-Paper-Scissors!\n");
    public String getPlayerWeapon() {
    int choice = 6;
    String weapon = null;
    System.out.println("\nPlease Choose your Weapon: \n");
    System.out.println("1. Rock \n2. Paper \n3. Scissors \n\n0. Quit");
    try {
    choice = easy.readInt();
    } catch (Exception e) {
    errorMsg();
    return getPlayerWeapon();
    if (choice == 0) {
    System.out.println("Quitting...");
    System.exit(0);
    } else {
    try {
    weapon = weapons[(choice - 1)];
    } catch (IndexOutOfBoundsException e) {
    errorMsg();
    return getPlayerWeapon();
    return weapon;
    public void errorMsg() {
    System.out.println("\nInvalid Entry.");
    System.out.println("Please Select Again...\n\n");
    public String getCpuWeapon() {
    int rounded = -1;
    while (rounded < 0 || rounded > 2) {
    double randomNum = Math.random();
    rounded = Math.round(3 * (float)(randomNum));
    return weapons[rounded];
    public void getWinner(String cpuWeapon, String playerWeapon) {
    if (cpuWeapon == playerWeapon) {
    System.out.println("Tie!\n");
    } else if (winners.get(cpuWeapon) == playerWeapon) {
    System.out.println("Computer Wins!\n");
    cpuScore++;
    } else if (winners.get(playerWeapon) == cpuWeapon) {
    System.out.println("You Win!\n");
    playerScore++;
    public boolean playAgain() {
    printScore();
    System.out.print("\nPlay Again (y/n)? ");
    char answer = easy.readChar();
    while (true) {
    if (Character.toUpperCase(answer) == 'Y') {
    return true;
    } else if (Character.toUpperCase(answer) == 'N') {
    return false;
    } else {
    errorMsg();
    return playAgain();
    public void printScore() {
    System.out.println("Current Score:");
    System.out.println("Player: " + playerScore);
    System.out.println("Computer: " + cpuScore);
    |------------------------- Compiler Output ----------------------------|
    C:\ide-xxxname\sampledir\RockPaperScissors>javac RockPaperScissors.java
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    RockPaperScissors.java:8: cannot resolve symbol
    symbol : class EasyIn
    location: class RockPaperScissors
    EasyIn easy = new EasyIn();
    ^
    2 errors

    limeybrit9,
    This importing certainly seems to be the problem, I'm still not used to how compilation works within the JAVA language, I'll play around with it a bit and see if I can get it to work correctly.
    bschauwe,
    The C++ approach has certainly clarified some of the points. I guess I will be sticking to that.
    bsampieri,
    You were correct on the class looking rather generic, but as I mentioned before I was just sort of tinkering to see if I could get it to work.
    Thanks to all for the help, very much appreciated.

  • Needs help.....Please about using different classes

    I don't know how to use differenet classes.
    Please tell me how to write class to suit Start. This stuff me up. Please .... help me
    <<My program>>
    //Start
    public class Start
    {  private Artist[] Artists;
    private Record[] records;
    private Person[] Manager;
    private TextMenu makeMenu = new TextMenu();
    public static void main(String[] args)
         Start studio = new Start();
    studio.menu();
    public Start()
    {  //Person.Manager(ManagerName,HouseNumber,StreetNumber,PhoneNumber)
         Manager = new Person[1];
         Manager[0] = new Person("Yangfan",88,"Young ST",11118888);
         //Artist(GroupID,ArtistName,HouseNumber,StreetNumber,PhoneNumber)
         Artists = new Artist[5];
    Artists[0] = new Artist(1,"Backstreet Boys",58,"Music ST",99998888);
    Artists[1] = new Artist(2,"Santana",68,"Music ST",99998899);
    Artists[2] = new Artist(3,"Macy Gray",78,"Music ST",55558888);
    Artists[3] = new Artist(4,"Ricky Martin",88,"Music AVE",77778888);
    Artists[4] = new Artist(5,"Did Rock",55,"Music Road",66667777);
    //Record(RecordingID,RecordName,Artist,StartTime,FinishTime,RecordingDate,GuestArtist1,GuestArtist2)
    records = new Record[6];
    records[0] = new Record(1,"I want it that way",Artists[0],11,12,"05/08/2001",Artists[1],Artists[3]);
    records[1] = new Record(2,"Smooth",Artists[1],11,12,"05/08/2001",Artists[1],"");
    records[2] = new Record(3,"Do something",Artists[2],11,"05/08/2001",Artists[3],"");
    records[3] = new Record(4,"Livin La Vida Loca",Artists[3],11,12,"05/08/2001",Artists[1],Artists[3]);
    records[4] = new Record(5,"Bawitdaba",Artists[4],11,13,"05/08/2001",Artists[1],"");
    records[5] = new Record(6,"The one",Artists[0],11,14,"05/08/2001",Artists[1],"");
    public void menu()
    {  String[] choices = {">>>List Manager Details",">>>List All Artist Names",">>>List An Artist Telephone-Number",">>>Show Details For One Recording",">>>Add A New Recording",">>>List The Recording Costs For All Artists",">>>List Artist's Reocording",">>>Exit Program"};
    while (true)
    {  switch (makeMenu.getChoice(choices))
    {  case 1: showAllArtists();
    break;
    case 2: showAllRecords();
    break;
    case 3: System.exit(0);
    break;
    case 4: System.exit(0);
    break;
    case 5: System.exit(0);
    break;
    case 6: System.exit(0);
    break;
    case 7: System.exit(0);
    break;
    case 8: System.exit(0);
    break;
    default:
    public void showAllArtists()
    {  int numArtists = Artists.length;
    for(int i = 0; i < numArtists; i++)
    {  Artists[i].displayArtistDetails();
    public void showAllRecords()
    {  for (int i = 0; i < records.length; i++)
    {  System.out.println();
    records.printRecordDetails();
    <<Assignment>>
    Due - midnight, Wednesday August 22nd
    This assignment will test your knowledge of Java programming using classes, encapsulation and javadoc.
    The base requirements
    Write a complete Java class to manage a Digital Recording Studio. The studio wants to keep a list of all Artists that use the studio and also wishes to keep track of all Recordings that have been made. An important function of the program is to calculate the time spent making a recording and charge the Artist for the time used.
    You must create at least the following classes, Start, Studio, Person, Artist, Recording, Address. You may create other classes if needed as well
    Start will contain main(), create one instance of a Studio and execute a Menu of commands to test your code. Studio should contain a studio name, an array of Artist and an array of Recording plus the studio manager (a Person). Each Artist should contain the name of the group and an Address. Each Person will have a name and a home address. Each recording will have a Title (usually song title), an Artist (only one), and a list of guestArtist (they are Artist�s but will not receive royalties) the number of the CD the recording is stored on (numbers are numerical and recordings are saved on CD-R), plus the recording start and finish times for the recording session (suggest you use Java Date class � refer to the API). An Address will contain, house number (integers only), a street name and a telephone number. There is no need to store city and country.
    To enter a set of data for testing your program � main() should call a method in the Start class that will fill in a set of values by creating objects and filling in values by calling methods in each class. This is the ONLY method allowed to be longer than 1 page long � normally we would read the data from a file but there are no O-O principles that can be learnt with simply filling in data values. It is suggested to create say at least 4 Artist�s and 6 Recordings (at least one with 1 guest Artist and one with 2 guestArtist�s)
    A menu for testing your program should be provided (it is suggested to put the Menu into a separate class as you need at least 3 menus). While other commands are possible, only the following ones will receive marks.
    Menu commands needed are
    List the Managers name, address and telephone number
    List all Artist Names
    List an Artist telephone number (a sub menu showing valid Artist�s is required)
    Show all details for one Recording ( sub menu of valid Recordings will be needed and remember there can be more than one guestArtist)
    Add a new Recording, user will need to be prompted for all details.
    List the recording costs for all Artists � show each Artist on a separate line with their name and total amount, charge for using the studio is $1000 per hour or part thereof, example for a 1 hour and 10 minute recording the Artist will be billed for 2 hours.
    List all the Recording�s one Artist has worked on (sub menu of Artists needed), the list should show whether they were the Artist or a guestArtist
    Exit program
    Use fixed sizes for arrays, suggest 20 is suitable for all arrays. Java can handle dynamic data structures (where the number of elements can grow or shrink), but that is beyond a first assignment.
    Do NOT make ANY methods static - this defeats the Object Oriented approach and will result in ZERO marks for the entire assignment.
    Data MUST be encapsulated, this means that all the data relating to an object are to be stored INSIDE an object. None of the data detail is to be globally available within your program - hence do not store Artist names in either Studio or Recordings � just store a reference instead. Do NOT create ID numbers for Artists, you should use References instead � for many students this will be the hardest part as you have to use Objects, not program in a C style to solve the problem. Note that if there are any non-private data in classes then zero will given for marks for encapsulation.
    Good programming style is expected (see web page or lecture notes). In particular, you must use javadoc to generate a set of html pages for your classes. Make sure you use the special javadoc style comments in your source code. Marks will be granted for both using javadoc and also for including sensible javadoc comments on each class and each public method.
    What to Hand In
    Read the turnin page, basically the .java files, a readme.txt to tell the marker which file the program starts from plus the javadoc (html) files. Do NOT send .class files (if you do send these we will delete them and recompile your program), do NOT compress with gtar, tar, zip or use any other tool on your files. Turnin automatically compresses all your files into a single archive for us to mark.
    The simplest way to turnin all your files is to place all files in one directory then just use the *.* wildcard to turn in all files within that one directory.
    You must turnin all files that are not part of Java 1.3. In particular, you are allowed (actually encouraged) to use EasyIn or SavitchIn but should include the one you use in the files you submit. It is STRONGLY suggested that you copy all the files into another directory, test it works there by compiling and executing then turnin files from that directory. A common problem is students adding comments at the last minute then not testing if it still compiles. The assignment will be marked as submitted � no asking later for leniency because you added comments at the last minute and failed to check if it still worked.
    If the tutors are unable to compile your submission, they will mark the source code but you will lose all the execution marks. Sorry, but it is your responsibility to test then hand in all files.
    Comments
    For CS807 students, this program should be fairly easy if it was to be programmed in C (you would use several struct). The real art here is to change over to programming objects. Data is contained in an object and is not global. This idea is essential to using Java effectively and is termed encapsulation. Instead of using function(data), you use objectName.method( ). Effectively you switch the data and functions around, the data has a method (function) attached to it, not the other way around as in C (where you have a function and send data to it).
    While there will be some marks for execution, the majority of the marks will be given for how well you write your code (including comments and documentation) and for how well you used O-O principles. Programs written in a C style with most of the code in one class or using static will receive ZERO marks regardless of how well they work.
    You are responsible for checking your turnin by reading the messages turnin responds with. Failure to read these messages will not be an acceptable excuse for submitting an incorrect assignment. About 2% of assignments sent to turnin are unreadable (usually empty) and obtain 0.
    Late submissions
    Late submissions will only be accepted with valid reasons for being late. All requests for assignment extensions must be made via email to the lecturer. Replies for acceptance or refusal will made by email. Instant replies are unrealistic (there is usually a flood of queries into my mail box around assignment due dates) and the best advice is to ask at least 4 days in advance so that you will have a reasonable chance of getting a timely reply and allow yourself enough time to submit something on time if the extension is not granted.
    ALL late submissions will be marked LAST and will NOT be sent to tutors for marking until all other assignments have been marked. As an example, if you submit late and your assignment is not yet marked by the time assignment 2 is due then it will be pushed to the end of the marking pile as the assignments that were submitted on time for assignment 2 will take priority.
    If you make a second submission after the submission date, only the first submission will be marked. We will not mark assignments twice! You can update your submission BEFORE the submission date if you need to - this will just overwrite the first submission. The latest time for a late submission is 5pm on the Wednesday after the due date. This is because, either a solution will be handed out at that lecture or details of the assignment will be discussed at the lecture. I cannot accept any assignment submissions after that time for any reason at all including medical or other valid reasons. For those who are given permission to be later than the maximum submission time � a different assignment will be handed out. Remember, if you decide to submit late you are VERY UNLIKELY to receive feedback on your assignments during semester.
    Assignments will be removed from turnin and archived elsewhere then forwarded to tutors for marking on the morning after the assignment is due. A different tutor will mark each of your assignments � do not expect the tutor you see at the tutorials to be your marker.
    Marks will be returned via email to your computer science yallara account � ideally within 2 weeks. I will send marks out when I receive them so do not send email asking where your marks are just because a friend has theirs. If you want your email forwarded to an external account, then place a valid .forward file into your yallara account. The Help Desk on level 10 can assist you in setting this up if you do not know how to do it.

    I have seen other people who have blatantly asked for
    other people to do their homework for them, but you
    are the first person I've seen to actually cut and
    paste the entire assignment as it was handed to you.
    Amazing.
    Well, unlike some of the people you're talking about, it seems like zyangfan did at least take a stab at it himself, and does have a question that is somewhat more sepcific that "please do this homework for me."
    Zyangfan,
    marendoj is right, though. Posting the entire assignment is kind of tacky. If you want to post some of it to show us what you're trying to do, please trim it down to the essential points. We don't need to see all the instructor's policies and such.
    Anyway, let me see if I understand what you're asking. You said that you know how to write the code, but only by putting it all in one class, is that right? What part about using separate classes do you not understand? Do you not know how to make code in one class aware that the other class exists? Do you not know how code in class A can call a method in class B?
    Please be a bit more specifice about what you don't understand. And at least try using multiple classes, then when you can't figure out why something doesn't work, explain what you did, and what you think should have happened, and what did happen instead.
    To get you started on the basics (and this should have been covered in your course), you write the code for two classes just like for one class. That is, for class A, you create a file A.java and compile it to A.class. For class B, you create a file B.java and compile it to B.class. Given how rudimentary you question is, we'll skip packages for now. Just put all your class files in the same directory, and don't declare packages in the .java files.
    To call a method in class B from code that's in class A, you'll need an object of class B. You instantiate a B, and then call its methods.
    public class B {
      int count;
      public B() { // constructor
      public void increment() {
        count++;
    public class A {
      public static void main(String args[]) {
        B b = new B();
        b.increment();
    }Is this what you were asking?

  • Writing and  Reading serialized Objects

    [code=java]
    /*hey guys i'm new to java and i have been given an exercise to make a cd collection, write it into a file and read the data back to the program.
    the program is suppose to show you a menu to select from where you can add, delete, view sort, CD's when you add a CD it must be written to a file as an Object and when you want to view CDs or search for a CD the program must read the CD objects from the file they have been written to and must return a cd nam, artist and release date. the code looks like it is writing the Cd to a file but when i try to read (view or search for a cd from the file it gives an error null). so i think i'm note reading the right way.
    thank you for helping .
    import java.io.Serializable;
    public class cd implements Serializable {
         //creating attributes
              private String cdname = null;
              private double price = 0.0;
              private String artist =null;
              private int ratings =0;
              private String genre=null;
              private String releaseDate =null;
         // creating an Empty constructor
              public cd(){
              public cd (String cdname,double price, int ratings, String genre, String artist, String releaseDate){
              this.cdname=cdname;
              this.price=price;
              this.artist=artist;
              this.ratings=ratings;
              this.genre=genre;
              this.releaseDate=releaseDate;
              public String getGenre(){
                   return genre;
              public void setGenre(String genre){
                   this.genre =genre;
              public String getArtist(){
                   return artist;
              public void setArtist(String artist){
                   this.artist=artist;
              public String getName(){
              return cdname;
              public void setName(String cdname){
              this.cdname = cdname;
              public Double getPrice(){
              return price;
              public void setPrice(double price){
              this.price = price;
              public String getReleaseDate(){
              return releaseDate;
              public void setReleaseDate(String releaseDate){
              this.releaseDate = releaseDate;
              public int getRatings(){
              return ratings;
              public void setRatings( int ratings){
              this.ratings = ratings;
    import java.util.*;
    public class hipHopCollection {
    ArrayList<cd> list = new ArrayList <cd> ();
    EasyIn ei = new EasyIn();
         private cd invoke;
         private int b;
         public void load()
              System.out.println(" You Entered " + b + " To Add A CD ");
              invoke = new cd();
              System.out.println("Please Enter A CD Name ");     
              invoke.setName(ei.readString());
              System.out.println("Please Enter A CD Price");
              invoke.setPrice(ei.readDouble());
              System.out.println("Please Give Ratings For The CD");
              invoke.setRatings(ei.readInt());
              System.out.println("Please Enter A CD release date ");
              invoke.setReleaseDate(ei.readString());
              System.out.println("Please Enter artist Name ");
              invoke.setArtist(ei.readString());
              System.out.println("Please Enter A CD Genre ");
              invoke.setGenre(ei.readString());
              list.add(invoke); // trying to add cd information to invoke.
         }// end of load
    // The following method should return the Object variable invoke that holds the cd INFO
         public Object getInvoke()
         return invoke;
         public int getB()
         return b;
         public void setB()
         b=ei.readInt();
         public void menu(){
              System.out.println("......................................................... ");
              System.out.println("Hi There Please Enter A Number For Your Choice");
              System.out.println(" Pess >>");
              System.out.println("1 >> Add A CD");
              System.out.println("2 >> View List Of CD's");
              System.out.println("3 >> Sort CD's By Price");
              System.out.println("4 >> Search CD By Name");
              System.out.println("5 >> Remove CD(s) By Name");
              System.out.println("0 >> Exit");
              System.out.println(".........................................................");
              System.out.print("Please Enter Chioce >> ");     
         }// end of menu
         public void GoodBye()
              System.out.println(" You Entered " + b + " To exit Good_bye" );
              System.exit(0);
         }//end of GoodBye
         public void PriceSort()
              System.out.println(" You Entered " + b + " To Sort CD(s) By price ");
              Collections.sort(list, new SortByPrice());
              for(cd s : list)
              System.out.println(s.getName() + ": " + s.getPrice());
         }// end of PriceSort
         public void NameSearch()
                   System.out.println(" You Entered " + b + " To Search CD(s) By Name ");
                   System.out.println("Please Enter The Name Of The CD You Are Searching For " );
                   String search = ei.readString();
                   for(int i=0; i<list.size();i++){
                   if(search.equalsIgnoreCase(list.get(i).getName() )){
                   System.out.println(list.get(i).getName() + " " + list.get(i).getPrice() + " " + list.get(i).getRatings() + " " + list.get(i).getGenre() );
    }//end of NameSearch
         public void ViewList()
                   System.out.println(" You Entered " + b + " To view CD(s) By Name ");
                   for(int i=0; i<list.size();i++)
                   System.out.println(list.get(i).getName() + " " + list.get(i).getPrice() + " " + list.get(i).getRatings() + " " + list.get(i).getGenre() );
         }// end of ViewList
         public void DeleteCd()
                   System.out.println(" You Entered " + b + " To Delete CD(s) By Name ");
                   System.out.println("Please Enter The Name Of The CD You Want to Delete ");
                   String search = ei.readString();
                   for(int i=0; i<list.size();i++)
                   if(search.equalsIgnoreCase(list.get(i).getName() ))
                   System.out.println(list.get(i).getName());
                   list.remove(i);
         }// end of DeleteCD
         public static void main(String[] args) {
         //creating an Instance of EasyIn by object ei. Easy in is a Scanner class for reading
              EasyIn ei = new EasyIn();
              ArrayList<cd> list = new ArrayList <cd> (); // creating an array cd list
              hipHopCollection call = new hipHopCollection();
              ReadWrite rw = new ReadWrite();
                   while (true){
                   call.menu();
                   call.setB();
                   //b = ei.readInt();
                   if(call.getB()==0)
                        call.GoodBye();
                   if(call.getB()==1)
                        call.load();
                        rw.doWriting();// trying to write the cd object to a file
                   if(call.getB()==2)
                   rw.doReading();// trying to read the cd object from a file
                   //call.ViewList();
                   if(call.getB()==3)
                   call.PriceSort();
                   if(call.getB()==4)
                        call.NameSearch();
                   if(call.getB()==5)
                        call.DeleteCd();
         }// end of while
    }// end of main
    }// end of class
    // importing all the packages that we will use
    import java.io.ObjectInputStream;
    import java.io.FileInputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.io.Serializable;
    public class ReadWrite {
    // these are all the attributes
         private String FileName ="CdCollections.dat";     
         private OutputStream output;
         private ObjectOutputStream oos;
         private FileOutputStream fos;
         private File file;
         private FileInputStream fis;
         private ObjectInputStream ois;
         //creating an empty constructor
         public ReadWrite()
         // we could initialise all the attributes inside this empty constructor
         //creating a constructor with arguments of a file name.
         public ReadWrite(File file)
              this.file=file;
              try
                   //Use a FileOutputStream to send data to a file called CdCollections.dat
                   fos = new FileOutputStream(file,true);
                   Use an ObjectOutputStream to send object data to the
                   FileOutputStream for writing to disk.
                   oos = new ObjectOutputStream (fos);
                   fis=new FileInputStream(file);
                   ois = new ObjectInputStream(fis);
              catch(FileNotFoundException e)
                   System.out.println("File Not Found");
              catch(IOException a)
                   System.out.println(a.getMessage());
                   System.out.println("Please check file permissions of if file is not corrupt");
         }// end of the second constructor
         //the following lines of code will be the accessors and mutators
         * @return the output
         public OutputStream getOutput() {
              return output;
         * @param output the output to set
         public void setOutput(OutputStream output) {
              this.output = output;
         * @return the objStream
         public ObjectOutputStream getOos() {
              return oos;
         * @param objStream the objStream to set
         public void setObjStream(ObjectOutputStream objStream) {
              this.oos = oos;
         public File getFile() {
              return file;
         public void setFile(File file) {
              this.file = file;
         public FileInputStream getFis() {
              return fis;
         public void setFis(FileInputStream fis) {
              this.fis = fis;
         public ObjectInputStream getOis() {
              return ois;
         public void setOis(ObjectInputStream ois) {
              this.ois = ois;
         // the following lines of code will be the methods for reading and writing
    the following method doWriting will write data from the hipHopCollections source code.
    that will be all the cd information.
    Pass our object to the ObjectOutputStream's
    writeObject() method to cause it to be written out
    to disk.
    obj_out.writeObject (myObject);
         public void doWriting()
              hipHopCollection call = new hipHopCollection();
    //creating an Object variable hold that will hold cd data from hipHopCollections invoke
              Object hold = call.getInvoke();// THI COULD BE THE PART WHERE I MADE A MISTAKE
              ReadWrite stream = new ReadWrite (new File(FileName));
              try
              Pass our object to the ObjectOutputStream's
              writeObject() method to cause it to be written out to disk.
              stream.getOos().writeObject(hold);
                   stream.getOos().writeObject(hold);
                   stream.getOos().close();
                   System.out.println("Done writing Object");
              catch (IOException e)
                   System.out.println(e.getMessage());
                   System.out.println("Program Failed To Write To The File");     
              finally
                   System.out.println("The program Has come To An End GoodBye");
         }// end of method DoWriting
    The following method is for reading data from the file written by the above method named
    DoWriting
    // PLEASE NOT THIS IS THE METHOD THAT GIVES ME NULL EXCEPTION
         public void doReading()
         ReadWrite read = new ReadWrite(new File(FileName));
              try{
                   //System.out.println("I AM NOW INSIDE THE TRY TO READ");
                   Object obj = read.getOis().readObject();
                   System.out.println("tried reading the object");
                   cd c = (cd)obj; // trying to cast the object back to cd type
                   System.out.println("I have typed cast the Object");               
                   System.out.println(c.getName());
                   System.out.println(c.getGenre());
                   System.out.println(c.getArtist());
                   System.out.println(c.getPrice());
                   System.out.println(c.getRatings());
                   System.out.println(c.getReleaseDate());
                   read.getOis().close();
              catch(ClassNotFoundException e)
              System.out.println(e.getMessage());
              System.out.println("THE CLASS COULD NOT BE FOUND");
              catch(IOException e)
              System.out.println(e.getMessage());// null
              System.out.println("WE COULD NOT READ THE DATA INSIDE THE FILE");
         }//end of method doReading
    }// end of class ReadWrite

    Cross posted
    http://www.java-forums.org/new-java/59965-writing-reading-serialized-java-object.html
    Moderator advice: Please read the announcement(s) at the top of the forum listings and the FAQ linked from every page. They are there for a purpose.
    Then edit your post and format the code correctly.
    db

  • Method Limits? a stressed newbie

    pls can anyone tell me if i can have the following in a method?
    (WHOLE CLASS)
    class SuperMethod
         public static double aTaxRate (double currentSalary)
              if (currentSalary < 6000)
                   currentSalary = currentSalary * 0.15;
                   return (currentSalary);
              else if ((currentSalary >=6001)|(currentSalary <= 15000))
                   currentSalary = currentSalary * 0.25;
                   return (currentSalary);
              else if (currentSalary >= 15001)
                   currentSalary = currentSalary * 0.45;
                   return(currentSalary);
         public static void main (String[]args)
              double currentSalaryInput;
              System.out.println("Howdy !! please enter the feckin current salary");
              currentSalaryInput = EasyIn.getDouble();
              System.out.println(aTaxRate(currentSalaryInput));
    i use EasyIn to get the integer value, basically i need to evaluate the salary rate and then output the new salary based on 3 different tax rates 15%, 25% and 45%, but it keeps outputting an error on line 4!!
    much thanks

    You have an error in your code here...
    else if ((currentSalary >=6001)|(currentSalary <= 15000))
    replace the | with ||, | means bitwise OR, || is logical OR which is probably what you want here :)

  • Transfering elements to new array and doubling values.

    Hi my problem is that I need to ask a user to enter 5 integers that stores them in an array. Transfer them to a new array by doubling the values when trasferred.
    Please help I have 3 errors.
    class arrays
         public static void main (String[] args)
              int numbers[] = new int [5];
              byte array1Size = 0;
              int input = 0;
              char goon = 'y';
                   //create and initialise an array of 5 integers
                   int array1[] = new int [5];
                   // loop and fill each element
                   for (int x = 0; x < array1.length; x++)
                        System.out.println("Enter a number: ");
                        array1[x] = EasyIn.getInt();
                        // Filling array
                        if (array1Size >= array1.length)
                             //Make a new array doubling the values od the integers
                             int array2 [] = new int [2 * array1.length]; // 10 integers
                             //Copying integers
                             System.arrayCopy (array1, 0, array2, 0, array1.length);
                             //Make old reference point to new array
                             array1 = array2;
                        else
                             //normal
                             do
                                  System.out.print("Enter an integer: ");
                                  input = EasyIn.getInt();
                                  anotherArray[anotherArraySize] = input;
                                  anotherArraySize++;
                                  System.out.print ("Another number? Enter Y or N: ");
                                  goon = EasyIn.getChar();
                             }     while(goon = = 'y' | goon = = 'Y');
    the errros >>>
    G:\Java\Practical 7\Practical74.java:33: '.class' expected
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:33: not a statement
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:41: 'else' without 'if'
                        else
    ^
    3 errors
    Tool completed with exit code 1
    Thanks

    Hi,
    it seems you forgot the curly braces in the if-else statement:
    if (array1Size >= array1.length){
    //Make a new array doubling the values od the integers
    int array2 [] = new int [2 * array1.length]; // 10 integers
    //Copying integers
    System.arrayCopy (array1, 0, array2, 0, array1.length);
    //Make old reference point to new array
    array1 = array2;
    else{
    //normal
    do
    System.out.print("Enter an integer: ");
    input = EasyIn.getInt();
    anotherArray[anotherArraySize] = input;
    anotherArraySize++;
    System.out.print ("Another number? Enter Y or N: ");
    goon = EasyIn.getChar();
    } while(goon = = 'y' | goon = = 'Y');
    }

  • Stars program problem

    Hi, I got Java running about 5 weeks ago to anyone that helped me thanks, but now I got a small problem:-
    When a user enters a number for example 6, I am trying to get it to output 6 lines of:
    please help I have 3 errors,
    public class stars1
    public static void main(String[]args);
         int counter1 = 1;
         int counter2 = 1;
         int table;
         System.out.print("Please enter an integer: ")
         table = EasyIn.getInt();
              do
                   do
                        System.out.print("*")
                        counter1++;
                   } while (counter1 <= table);
                   System.out.println();
                   counter1 = 1;
              } while (counter1 <= counter2);
    errors are:-C:\Java Code\stars1.java:10: <identifier> expected
         System.out.print("Please enter an integer: ")
    ^
    C:\Java Code\stars1.java:13: illegal start of type
              do
    ^
    C:\Java Code\stars1.java:25: <identifier> expected
              } while (counter1 <= counter2);
    ^
    3 errors
    Tool completed with exit code 1
    Thanks in advance

    Hi, I got Java running about 5 weeks ago to anyone
    that helped me thanks, but now I got a small
    problem:-
    When a user enters a number for example 6, I am
    trying to get it to output 6 lines of:
    please help I have 3 errors,
    public class stars1
    public static void main(String[]args);
         int counter1 = 1;
         int counter2 = 1;
         int table;
         System.out.print("Please enter an integer: ")
         table = EasyIn.getInt();
              do
                   do
                        System.out.print("*")
                        counter1++;
                   } while (counter1 <= table);
                   System.out.println();
                   counter1 = 1;
              } while (counter1 <= counter2);
    errors are:-C:\Java Code\stars1.java:10: <identifier>
    expected
         System.out.print("Please enter an integer: ")
    ^
    C:\Java Code\stars1.java:13: illegal start of type
              do
    ^
    C:\Java Code\stars1.java:25: <identifier> expected
              } while (counter1 <= counter2);
    3 errors
    Tool completed with exit code 1
    Thanks in advanceI think this would solve your problem,
    import java.io.*;
    public class program_name
        public static void main(String args[]) throws IOException
        String input_string;
        BufferedReader myInput = new BufferedReader(new InputStreamReader(System.in));//set up input
        System.out.print("Enter the number : ");   
        input_string = myInput.readLine();     //read in the input
        int number = Integer.parseInt(input_string);            
        for (int i = 1; i <= number; i++)
        int counter=1;
         while (counter<=number)
             System.out.print("*");
             counter++;
         System.out.println(); 
    }It a simple nested loop that asks for a number from the user, loop for that number and loop again within the outer loop!
    Hope it helps!

  • Compare the last Char to the First Char in a Sting

    Hello, this should be easy but I'm having problems so here goes.
    I get the user to input a Stirng and I want it to compare the last Char to the first Char. I have writen this but StartWith can take a Char?
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            char lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.charAt(length);
           if( strA.endsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }I have tried lastLetter.endsWith(strA) but that dosn't work some thing to do with it not taking Char
    From reading you can go strA.startWith("R") and that would look for R but you can't put a char in that would be a single letter.
    I also tried to lastletter to a string but then charAt wouldn't work.

    fixed it I used substring as its a string object any one recomend a better way let me know
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            String lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.substring(length);
           if( strA.startsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }

  • There is another error in "TestIntegerStackWithExceptions.java"

    There are two errors in "TestIntegerStackWithExceptions.java". Below are the classes to help you to correct.
    * A class to represent the negative size exception. (NegativeSizeException.java)
    * @author Lam Chou Yin @ Edwin
    * @version 1.0.0 18 October 2004
    public class NegativeSizeException extends Exception
          * Constructor without parameter.
         public NegativeSizeException()
              super("cannot set a negative size");
          * constructor with parameter.
          * @param message message of the exception.
         public NegativeSizeException(String message)
              super(message);
    * A class to represent the invalid stack position exception. (InvalidStackPositionException.java)
    * @author Lam Chou Yin @ Edwin
    * @version 1.0.0 18 October 2004
    public class InvalidStackPositionException extends Exception
          * Constructor without parameter.
         public InvalidStackPositionException()
              super("an invalid stack position was provided");
          * Constructor with parameter.
          * @param message message of the exception.
         public InvalidStackPositionException(String message)
              super(message);
    * A class to represent <code>IntegerStackWithExceptions</code> object. (IntegerStackWithExceptions.java)
    * @author Lam Chou Yin @ Edwin
    * @version 1.0.0 2 October 2004
    public class IntegerStackWithExceptions
          * To hold the stack of integers.
         private int[] stack;
          * To track number of items.
         private int total;
          * A constructor with one argument.
         public IntegerStackWithExceptions(int sizeIn) throws NegativeSizeException
              if (sizeIn < 0)
                   throw new NegativeSizeException();
              else
                   stack = new int[sizeIn];
                   total = 0;
          * Add an item to the array.
          * @return true when the item is successfully added.
         public boolean push(int j)
              if (isFull() == false) // checks if space in stack
                   stack[total] = j; // add item
                   total++; // increment item counter
                   return true; // to indicate success
              else
                   return false; // to indicate failure
          * Remove an item by obeying LIFO rule.
          * @return true when the item is successfully removed.
         public boolean pop()
              if (isEmpty() == false) // makes sure stack is not empty
                   total--; // reduce counter by one
                   return true; // to indicate success
              else
                   return false; // to indicate failure
          * Checks if array is empty.
          * @return true when an array is empty.
         public boolean isEmpty()
              if (total == 0)
                   return true;
              else
                   return false;
          * Checks if array is full.
          * @return true when an array is full.
         public boolean isFull()
              if (total == stack.length)
                   return true;
              else
                   return false;
          * Returns the ith item.
          * @return the ith item.
         public int getItem(int i) throws InvalidStackPositionException
              if (i < 1 || i > total)
                   throw new InvalidStackPositionException();
              else
                   return stack[i - 1]; // ith item at position i - 1
          * Return the number of items in the array.
          * @return the number of items in the array.
         public int getTotal()
              return total;
    // EasyIn.java - allows user to key in.
    import java.io.*;
    public abstract class EasyIn
      public static String getString()
         boolean ok = false;
         String s = null;
         while(!ok)
            byte[] b = new byte[512];
            try
               System.in.read(b);
               s = new String(b);
               s = s.trim();
               ok = true;
            catch(IOException e)
                System.out.println(e.getMessage());
            return s;
       public static int getInt()
          int i = 0;
          boolean ok = false;
          String s ;
          while(!ok)
             byte[] b = new byte[512];
             try
                System.in.read(b);
                s = new String(b);
                i = Integer.parseInt(s.trim());
                ok = true;
             catch(NumberFormatException e)
                System.out.println("Make sure you enter an integer");
             catch(IOException e)
                 System.out.println(e.getMessage());
         return i;
    public static byte getByte()
         byte i = 0;
         boolean ok = false;
         String s ;
         while(!ok)
            byte[] b = new byte[512];
            try
                System.in.read(b);
                s = new String(b);
                i = Byte.parseByte(s.trim());
                ok = true;
            catch(NumberFormatException e)
                System.out.println("Make sure you enter a byte");
            catch(IOException e)
                 System.out.println(e.getMessage());
         return i;
    public static short getShort()
         short i = 0;
         boolean ok = false;
         String s ;
         while(!ok)
            byte[] b = new byte[512];
            try
                System.in.read(b);
                s = new String(b);
                i = Short.parseShort(s.trim());
                ok = true;
            catch(NumberFormatException e)
                System.out.println("Make sure you enter a short integer");
            catch(IOException e)
                 System.out.println(e.getMessage());
         return i;
    public static long getLong()
        long l = 0;
        boolean ok = false;
        String s ;
        while(!ok)
           byte[] b = new byte[512];
           try
               System.in.read(b);
               s = new String(b);
               l = Long.parseLong(s.trim());
               ok = true;
           catch(NumberFormatException e)
               System.out.println("Make surre you enter a long integer");
           catch(IOException e)
                System.out.println(e.getMessage());
        return l;
    public static double getDouble()
        double d = 0;
        boolean ok = false;
        String s ;
         while(!ok)
            byte[] b = new byte[512];
            try
                 System.in.read(b);
                 s = new String(b);
                 d = Double.parseDouble(s.trim());
                 ok = true;
            catch(NumberFormatException e)
                 System.out.println("Make sure you enter a decimal number");
            catch(IOException e)
               System.out.println(e.getMessage());
        return d;
    public static float getFloat()
         float f = 0;
         boolean ok = false;
         String s;
         while(!ok)
            byte[] b = new byte[512];
            try
                System.in.read(b);
                s = new String(b);
                f = Float.parseFloat(s.trim());
                ok = true;
            catch(NumberFormatException e)
                System.out.println("Make sure you enter a decimal number");
            catch(IOException e)
                System.out.println(e.getMessage());
         return f;
      public static char getChar()
         char c = ' ';
         boolean ok = false;
         String s;
         while(!ok)
            byte[] b = new byte[512];
            try
              System.in.read(b);
              s = new String(b);
               if(s.trim().length()!=1)
                 System.out.println("Make sure you enter a single character");
               else
                    c = s.trim().charAt(0);
                    ok = true;
            catch(IOException e)
                System.out.println(e.getMessage());
         return c;
      public static void pause()
         boolean ok = false;
         while(!ok)
             byte[] b = new byte[512];
             try
                 System.in.read(b);
                 ok = true;
             catch(IOException e)
                  System.out.println(e.getMessage());
      public static void pause(String messageIn)
         boolean ok = false;
         while(!ok)
             byte[] b = new byte[512];
             try
                  System.out.print(messageIn);
                  System.in.read(b);
                  ok = true;
             catch(IOException e)
                  System.out.println(e.getMessage());
    }Finally, there are two errors in "TestIntegerStackWithExceptions.java"
    public class TestIntegerStackWithExceptions
         public static void main(String[] args)
              int size;
              IntegerStackWithExceptions stack;
              try
                   char choice;
                   // ask user to fix maximum size of stack
                   System.out.print("Maximum number of items on stack? ");
                   size = EasyIn.getInt();
                   // create new stack
                   stack = new IntegerStackWithExceptions(size);
                   // offer menu
                   do
                        System.out.println();
                        System.out.println("1. Push number onto stack");
                        System.out.println("2. Pop number from stack");
                        System.out.println("3. Check if stack is empty");
                        System.out.println("4. Check if stack is full");
                        System.out.println("5. Display numbers in stack");
                        System.out.println("6. Get any item from the stack");
                        System.out.println("7. Quit");
                        System.out.println();
                        System.out.print("Enter choice [1 - 7]: ");
                        choice = EasyIn.getChar();
                        System.out.println();
                        // process choice
                        switch(choice)
                        { // call static methods
                             case '1': option1(stack); break;
                             case '2': option2(stack); break;
                             case '3': option3(stack); break;
                             case '4': option4(stack); break;
                             case '5': option5(stack); break;
                             case '6': option6(stack); break;
                             case '7': break;
                             default: System.out.println("Invalid entry");
                   while (choice != '7');
              catch (NegativeSizeException e) // from stack constructor call
              { // source and type of error displayed
                   while (size != stack.getTotal())
                        System.out.println(e.getMessage());
                        System.out.println("due to error created by stack constructor");
                        System.out.print("Maximum number of items on stack? ");
                        size = EasyIn.getInt();
              catch (InvalidStackPositionException e) // from 'option6' method call
              { // source and type of error displayed
                   System.out.println(e.getMessage());
                   System.out.println("due to error created by call to 6th menu option");
              catch (Exception e) // just in case any other exception is thrown
                   System.out.println("This exception was not considered");
                   System.out.println(e.getMessage());
              EasyIn.pause("\nPress <Enter> to quit program");
         // static method to push item onto stack
         private static void option1(IntegerStackWithExceptions stackIn)
              System.out.print("Enter number: ");
              int num = EasyIn.getInt();
              boolean ok = stackIn.push(num); // attempt to push
              if (!ok) // check if push was unsuccessful
                   System.out.println("Push unsuccessful");
         // static method to pop item onto stack
         private static void option2(IntegerStackWithExceptions stackIn)
              boolean ok = stackIn.pop(); // attempt to pop
              if (!ok) // check if pop was unsuccessful
                   System.out.println("Pop unsuccessful");
         // static method to check if stack is empty
         private static void option3(IntegerStackWithExceptions stackIn)
              if (stackIn.isEmpty())
                   System.out.println("Stack empty");
              else
                   System.out.println("Stack not empty");
         // static method to check if stack is full
         private static void option4(IntegerStackWithExceptions stackIn)
              if (stackIn.isFull())
                   System.out.println("Stack full");
              else
                   System.out.println("Stack not full");
         // static method to display stack
         private static void option5(IntegerStackWithExceptions stackIn) throws InvalidStackPositionException
              if (stackIn.isEmpty())
                   System.out.println("Stack empty");
              else
                   System.out.println("Numbers in stack are: ");
                   System.out.println();
                   for (int i = 1; i <= stackIn.getTotal(); i++)
                        System.out.println(stackIn.getItem(i));
                   System.out.println();
         // this method throws out any InvalidStackPositionException
         private static void option6(IntegerStackWithExceptions stackIn)
              System.out.print("\nWhich position would you like to get? ");
              int position = EasyIn.getInt();
              try
                   System.out.println("This item is: " + stackIn.getItem(position));
              catch (InvalidStackPositionException ispe)
                   while (position != stackIn.getItem(position)) throws InvalidStackPositionException
                        System.out.println("Invalid position!");
                        System.out.print("\nWhich position would you like to get? ");
                        position = EasyIn.getInt();
              System.out.println();
    TestIntegerStackWithExceptions.java: Illegal start of expression at line 146
    TestIntegerStackWithExceptions.java: ';' expected at line 152Hope to reply soon.

    Next time, please don't paste all your code unless it's relevant to the problem. The compiler is telling you exactly where the problem is (most of the time, anyway), so look at the line it indicates to see if there is anything strange there or in the line above it. This type of error means you've violated the rules of Java syntax.
    In this case you are trying to add a throws clause to a while loop, which is not allowed. You can only add throws clauses to methods (and constructors).

  • Constructor method, Can you easily solve the issue?

    I have had many problems intergrating a constructor method into my program. This is my first time programming in java, can someone please help me. I have contructed a class for an airplanelisttester, that allows the user choice to add or remove planes from the program using a switch method, i have yet to program each "case" accordingly, but i am having trouble at the start of the code. I need to create an "airplanelist" object, i have found some help on the internet, but i am not sure what is going wrong.
    public class AirplaneListTester
         public static void main (String[] args)
    throws java.io.IOException
              char choice;
              int size;
              size = EasyIn.getint();
         AirplaneList plane = new AirplaneList();
         plane.add(Airplane) = "Add a plane?";
         plane.remove(int) = "Remove a plane?";
         plane.isEmpty() = "Is Empty";
         plane.isFull() = "Is Full";
         plane.getitem(int) = "Airplanenumber";
         plane.getTotal() = "size" ;
         public AirplaneList
         private boolean add(Airplane);
         private boolean remove(int);
         private boolean isEmpty();
         private boolean isFull();
         private int getitem(int);
         private int getTotal();
         //..............rest of the program using swtich comands to alow the user to add\remove an airplane , check if a list is empty or      //full and display the list as well as exit the program.
    }

    ok so it should look a little like this? I am not really sure, on how to create these objects? ;-<. I understand that "isEmpty" and "isFull" should bounce back very obvious boolean statements, i.e. isfull or isempty. However I am not sure on what values to initiate for "add(Airplane)" ? Is that null? or should i prompt the user to enter one?
    import javax.swing.JOptionPane;
    public class AirplaneList
         public static void main (String[] args)
    throws java.io.IOException
              char choice;
              int size;
              size = EasyIn.getint();
         AirplaneList plane = new AirplaneList();
         plane.add(Airplane) = "Add a plane?";
         plane.remove(int) = "Remove a plane?";
         plane.isEmpty() = "Is Empty";
         plane.isFull() = "Is Full";
         plane.getitem(int) = "Airplanenumber";
         plane.getTotal() = "size" ;
    //declaration
    private boolean add(Airplane);
    private boolean remove(int);
    private boolean isEmpty;
    private boolean isFull;
    private int getitem(int);
    private int getTotal;
    //constuctor
    public AirPlaneList
    add(Airplane) = null;
    remove(int) = null;
    isEmpty = true;
    isfull = false;
    getitem(int) = size;
    getTotal = null;      //initialisation
    //methods
    public boolean isFull()
    return isfull;
    public boolean isEmpty()
    return isEmpty;
         //..............rest of the program using swtich comands to alow the user to add\remove an airplane , check if a list is empty or      
    //full and display the list as well as exit the program.
    }

  • Acceleration in Scaling - CS4

    I am using CS4 and have used scaling in some still photos to achieve the "Ken Burns" affect.  The result is as expected.  However, I would like to ease in and out of the motion by smoothly changing the acceleration of the motion.  I have read the CS4 manual looking for instructions on doing this and I can't find it.  Nothing is mentioned about acceleration adjustments to scaling and motion.  I can achieve it in a manner by setting keyframes at various points in the clip but the acceleration does not change smoothly.  I want to start the motion slowly, build to the maximum and then gradually slow it at the end of the frame.  Any asistance would be appreciated.
    Roy

    Using easy in/out:
    http://i580.photobucket.com/albums/ss248/cigcypher/accel-using-easyin-easyout.jpg?t=125442 5071
    Using acceleration curve:
    http://i580.photobucket.com/albums/ss248/cigcypher/accel-curve-using-keyframes.jpg?t=12544 25145
    Ops, duplicated post, pls adm remove this one.

  • Help with college assignments ( Please )

    Hi,
    I am new both to Java and programming as a whole. I did a bit of client side scripting during the dot com hey day ( last year ). Recently I signed up on bachelors degree course and this semester is focusing on Java. As I cannot get hold of my lecturer more than once a week I am hoping I can use this forum as resource for my weekly assignments. I am not looking for specifically for code, rather a resource to bounce ideas to formulate into code myself. I have come to agree with my lecturer that a well structured pesuedocode would help to brain storm for the actual java code.
    Therefore it is the pesudocode that I would like to discuss in this forum. Another important factor would be not to use any fancy classes or methods for my assignment. Not at this early stage anyway. It does not matter using tens of if statements even if there was a quicker solution. I need to understand the logic first.
    If I am in the wrong forum I would be grateful if you could point to more suitable forums.
    On the other hand if you can help please let me know so that I can detail my latest assignment based on a vending machine.
    Incidentally, I understand there is a nice freebie text editor called jdeveloper. I have done search for it but not come up with anything. Any ideas.???
    I thank you in advance for your support and co-operation.
    Sincerely
    Siavash Sefidvash

    Hello,
    Thanks for you kind offer of assistance. As mentioned already I find learning the logic of psuedo codes helps a great deal in formulating the java code. My current level is not much beyond "IF" statements and a bit of for/while loops. I am using the EasyIn method without really knowing how it works. I already have attempted code for this, but would like feedback regarding the psuedo code first. I will post the code in a seperate post.
    1. At command prompt select either of keys, p, c, f, s, d.
    2. "if" the selection is c
    3. Print out a coke prompt.
    4. Print out to screen " Enter amount you want".
    4. Enter an integer for the amount.
    5. Subtract or decrement the amount from stock.
    6. Print out updated stock on screen.
    7. "if" p is selected
    8. Print out a pepsi prompt.
    9. Take in an integer for the amount required.
    10. Subtract or decrement from stock.
    11. Print out the updated stock.
    12. if" the selection is f
    13. Print out a fanta prompt. Possibly with a text saying " Enter amount you want".
    14. Enter an integer for the amount.
    15. Subtract or decrement the amount entered from stock.
    16. Print out updated stock on screen.
    17. "if" s is selected
    18. Print out a Sprite prompt.
    19. Take in an integer for the amount required.
    20. Subtract or decrement from stock.
    21. Print out the updated stock.
    23. "if" d is selected
    24. Print out a Diet Coke prompt.
    25. Take in an integer for the amount required.
    26. Subtract or decrement from stock.
    27. Print out the updated stock.
    23. "if" E is selected
    24. Exit program.
    /* This application is a vending machine selling five types of soft drinks. I.e. Pepsi,Coke, Fanta, Sprite, Diet Coke.
    The machine stocks 50 cans of each drink. The application is to subtract or decriment and up date the stock as the
    products are bought. */

Maybe you are looking for

  • Hey, I'm having a hardware issue with my Ipod Charger.

    Hello Apple community! I am having a issue with charging my 3rd Gen 64GB I Touch. I used to get an error where it wouldn't allow me to charge due to the accessory not being compatible to the i Touch (I used 3 different Apple Charger, Apple brand,etc)

  • Can iPhoto meet my user sharing & back-up needs?

    Hi all and happy new year, I have been struggling with iPhoto ever since I switched to a mac a year ago. Most importantly for me I want to share a library of shared family photos with my wife who has her own user profile on our mac, Apple's published

  • Windows 7 Blue Screen Crash

    Hello, I recently have been getting a lot of blue screen crashes simultaneously. I haven't downloaded any games or anything. I just use this laptop for school work mostly. I already ran a memory diagnostic test and no problems found as well as restor

  • Error while Assembling the Component in NWDI

    HI All, I am trying to assemble the component in NWDI . The assemly is failing .When  i check the log file i get the following log. 20091125100727 Info   :Starting Step Check-assembly at 2009-11-25 10:07:27.0253 +5:00 20091125100727 Info   :Checks fo

  • Google Search embedded in an HTML region

    Hello, I tried to embed the standard Google search engine code (see below) into an HTML region within the HTML DB app, but upon hitting "submit" I get an error because the HTML DB engine tries to process the form post, instead of allowing a redirect