Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: I need help in java programming assignment please help?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post I need help in java programming assignment please help?

    Behavior of several SML instructions in the Simpletron:


    REGISTERS:
    accumulator +0000
    instructionCounter 00
    instructionRegister +0000
    operationCode 00
    operand 00
    MEMORY:
    0123456789 0 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    10 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    20 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    30 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    40 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    50 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    60 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    70 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    80 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    90 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help in java programming assignment please help?

    Do you have a question?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help in java programming assignment please help?

    Quote Originally Posted by Norm View Post
    Do you have a question?
    sorry... the actual question is

    7.36 (Computer Simulator) In this problem, you’re going to build your own computer. No,
    you’ll not be soldering components together. Rather, you’ll usethe powerful technique ofsoftwarebased simulationto create an object-orientedsoftware modelof the Simpletron of Exercise 7.35. Your
    Simpletron simulator will turn the computer you’re using into a Simpletron, and you’ll actually be
    able to run, test and debug the SML programs you wrote in Exercise 7.35.
    When you run your Simpletron simulator, it should begin by displaying:
    *** Welcome to Simpletron! ***
    *** Please enter your program one instruction ***
    *** (or data word) at a time. I will display ***
    *** the location number and a question mark (?) ***
    Location Number Instruction
    00 +1007 (Read A)
    01 +1008 (Read B)
    02 +2007 (Load A)
    03 +3008 (Add B)
    04 +2109 (Store C)
    05 +1109 (Write C)
    06 +4300 (Halt)
    07 +0000 (Variable A)
    08 +0000 (Variable B)
    09 +0000 (Result C)
    Fig. 7.34 |SML program that reads two integers and computes their sum.
    Location Number Instruction
    00 +1009 (Read A)
    01 +1010 (Read B)
    02 +2009 (Load A)
    03 +3110 (Subtract B)
    04 +4107 (Branch negative to 07)
    05 +1109 (Write A)
    06 +4300 (Halt)
    07 +1110 (Write B)
    08 +4300 (Halt)
    09 +0000 (Variable A)
    10 +0000 (Variable B)
    Fig. 7.35 |SML program that reads two integers and determines the larger.
    Special Section: Building Your Own Computer 307
    *** You then type the word for that location. ***
    *** Type -99999 to stop entering your program. ***
    Your application should simulate the memory of the Simpletron with a one-dimensional arraymemorythat has 100 elements. Now assume that the simulator is running, and let’s examine the dialog
    as we enter the program of Fig. 7.35 (Exercise 7.35):
    00 ? +1009
    01 ? +1010
    02 ? +2009
    03 ? +3110
    04 ? +4107
    05 ? +1109
    06 ? +4300
    07 ? +1110
    08 ? +4300
    09 ? +0000
    10 ? +0000
    11 ? -99999
    Your program should display the memory location followed by a question mark. Each value to the
    right of a question mark is input by the user. When the sentinel value-99999is input, the program
    should display the following:
    *** Program loading completed ***
    *** Program execution begins ***
    The SML program has now been placed (or loaded) in arraymemory.NowtheSimpletronexecutes the SML program. Execution begins with the instruction in location00and, as in Java, continues sequentially, unless directed to some other part of the program by a transfer of control.
    Use the variableaccumulatorto represent the accumulator register. Use the variableinstructionCounterto keep track of the location in memory that contains the instruction being performed. Use the variableoperationCodeto indicate the operation currently being performed (i.e.,
    the left two digits of the instruction word). Use the variableoperandto indicate the memory location on which the current instruction operates. Thus, operandis the rightmost two digits of the
    instruction currently being performed. Do not execute instructions directly from memory. Rather,
    transfer the next instruction to be performed from memory to a variable calledinstructionRegister. Then “pick off” the left two digits and place them in operationCode, and “pick off” the right
    two digits and place them inoperand. When the Simpletron begins execution, the special registers
    are all initialized to zero.
    Now, let’s “walk through” execution of the first SML instruction,+1009in memory location
    00. This procedure is called aninstruction-execution cycle.
    TheinstructionCountertells us the location of the next instruction to be performed. We
    fetchthe contents of that location frommemoryby using the Java statement
    instructionRegister = memory[ instructionCounter ];
    The operation code and the operand are extracted from the instruction register by the statements
    operationCode = instructionRegister /100;
    operand = instructionRegister % 100;
    Now the Simpletron must determine that the operation code is actually aread (versus a write,a
    load, and so on). A switchdifferentiates among the 12 operations of SML. In theswitchstatement, the behavior of various SML instructions is simulated as shown in Fig. 7.36. We discuss
    branch instructions shortly and leave the others to you.
    When the SML program completes execution, the name and contents of each register as well
    as the complete contents of memory should be displayed. Such a printout is often called a computer dump (no, a computer dump is not a placewhere old computers go). To help you program
    your dump method, a sample dump format is shown in Fig. 7.37. A dump after executing a
    308 Chapter 7 Arrays and ArrayLists
    Simpletron program would show the actual values of instructions and data values at the moment
    execution terminated.
    Let’s proceed with the execution of our program’s first instruction—namely, the+1009in location00. As we’ve indicated, theswitchstatement simulates this task by prompting the user to enter
    a value, reading the value and storing it in memory locationmemory[ operand ]. The value is then
    read into location09.
    At this point, simulation of the first instruction is completed. All that remains is to prepare
    the Simpletron to execute the next instruction. Since the instruction just performed was not a
    transfer of control, we need merely incrementthe instruction-counter register as follows:
    instructionCounter++;
    This action completes the simulated execution of the first instruction. The entire process (i.e., the
    instruction-execution cycle) begins anew with the fetch of the next instruction to execute.
    Now let’s consider how the branching instructions—the transfers of control—are simulated.
    All we need to do is adjust the value in the instruction counter appropriately. Therefore, the
    unconditional branch instruction (40) is simulated within theswitchas
    instructionCounter = operand;
    The conditional “branch if accumulator is zero” instruction is simulated as
    if ( accumulator == 0 )
    instructionCounter = operand;
    Instruction Description
    read: Display the prompt"Enter an integer",theninputtheintegerandstoreit
    in locationmemory[operand].
    load: accumulator = memory[ operand ];
    add: accumulator += memory[ operand ];
    halt: This instruction displays the message
    *** Simpletron execution terminated ***
    Fig. 7.36 |Behavior of several SML instructions in the Simpletron.
    REGISTERS:
    accumulator +0000
    instructionCounter 00
    instructionRegister +0000
    operationCode 00
    operand 00
    MEMORY:
    0123456789 0 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    10 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    20 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    30 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    40 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    50 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    60 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    70 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    80 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
    90 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000

    --- Update ---

    teacher refer us to Java How To Program : Deitel & Deitel 9th Edition book , problem 7.36

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help in java programming assignment please help?

    Sorry, I still don't see any question. What you posted looks like your assignment.
    Do you have any specific java programming questions?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help in java programming assignment please help?

    Sorry for that ..
    this is another problem..would you help me..

    Rational Numbers)Create a class calledRationalfor performing arithmetic with fractions.
    Write a program to test your class. Useinteger variables to represent theprivateinstance variables
    of the class—thenumeratorand thedenominator. Provide a constructor that enables an object of
    this class to be initialized when it’s declared. The constructor should store the fraction in reduced
    form. The fraction
    2/4
    is equivalent to1/2and would be stored in the object as 1 in thenumeratorand 2 in thedenominator. Provide a no-argument constructor with default values in case no initializers are provided. Providepublicmethods that perform each of the following operations:
    a) Add twoRationalnumbers: The result of the addition should be stored in reduced
    form. Implement this as astaticmethod.
    b) Subtract twoRationalnumbers: The result of the subtraction should be stored in reduced form. Implement this as astaticmethod.
    c) Multiply twoRationalnumbers: The result of the multiplication should be stored in
    reduced form. Implement this as astaticmethod.
    d) Divide twoRationalnumbers: The result of the division should be stored in reduced
    form. Implement this as astaticmethod.
    e) Return aStringrepresentation of aRationalnumber in the forma/b,whereais the
    numeratorandbis thedenominator.
    f) Return aStringrepresentation of a Rationalnumber in floating-point format. (Consider providing formatting capabilities that enable the user of the class to specify the
    number of digits of precision to the right of the decimal point.)
    8.16 (Huge Integer Class)Create a classHugeIntegerwhich uses a 40-element array of digits to
    store integers as large as 40 digits each. Provide methodsparse,toString,addandsubtract.Methodparsesh ould receive a String, extract each digit using method charAtand place the integer
    equivalent of each digit into the integer array. For comparingHugeIntegerobjects, provide the following methods: isEqualTo,isNotEqualTo,isGreaterThan,isLessThan,is GreaterThanOrEqualTo
    andisLessThanOrEqualTo. Each of these is a predicate method that returnstrueif the relationship
    holds between the twoHugeIntegerobjects and returnsfalseif the relationship does not hold. Provide a predicate methodisZero. If you feel ambitious, also provide methodsmultiply,divideand
    remainder.[Noterimitivebooleanvalues can be output as the word “true” or the word “false” with
    format specifier%b.]
    8.17 (Tic-Tac-Toe)Create a classTicTacToethat will enable you to write a program to play TicTac-Toe. The class contains a private 3-by-3 two-dimensional array. Use anenumeration to represent the value in each cell of the array. The enumeration’s constants should be namedX,OandEMPTY
    (for a position that does not contain anXor anO). The constructor should initialize the board elements toEMPTY. Allow two human players. Wherever the first player moves, place an Xin the specified square, and place an Owherever the second player moves. Each move must be to an empty
    square. After each move, determine whether the game has been won and whether it’s a draw. If you
    feel ambitious, modify your program so that the computer makes the moves for one of the players.
    Also, allow the player to specify whether he or she wantstogofirstorsecond.Ifyoufeelexceptionally ambitious, develop a program that will play three-dimensional Tic-Tac-Toe on a 4-by-4-by-4
    board [Note:This is an extremely challenging project!]

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help in java programming assignment please help?

    Again that looks like an assignment. What specific java programming questions do you have?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jul 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help in java programming assignment please help?

    yeah ! it is an assignment . would you solve this problem , please .

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help in java programming assignment please help?

    We do not write code. If you need help with your code, please post the code and/or the questions about it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Programming (Object Oriented Programming) Assignment
    By azmilPhenom in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2013, 07:26 AM
  2. Help with Java Programming Assignment Please?
    By a21j92 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 26th, 2012, 10:35 AM
  3. java programming assignment help
    By darking123 in forum What's Wrong With My Code?
    Replies: 56
    Last Post: October 4th, 2012, 06:05 PM
  4. java programming assignment help
    By darking123 in forum Java Theory & Questions
    Replies: 0
    Last Post: October 1st, 2012, 07:26 AM
  5. Programming help with java assignment!
    By kami21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2011, 06:37 PM

Tags for this Thread