Ryan Hickman

Ranch Hand
+ Follow
since Oct 13, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ryan Hickman

I am trying to write two different programs in LMC using an old assembly language. The first as is follows:



Writea LMC program that takes two inputs, a number to count down from, and the stepvalue (example: count down from 35 by 5), until it reaches zero. It should print each step, and the lastnumber before zero if the sequence doesn’t end on zero, but if the number goesto negative, that number should not be printed. Example output using 13 and 3 as inputs would be: 13, 10, 7, 4, 1. Example output using 12 and 3 as inputs wouldbe: 12, 9, 6, 3, 0.



I have tried something along the lines of this:



IN

STO 91

IN

STO 92

IN

STO 93

LDA 91

ADD 92

SUB 93

OUT

HLT



Which does not work



The second LMC program I am trying to write is as follows:



Writethe code to calculate the area and perimeter of a triangle. The program should take 3 inputs, which are,in order, the base, height, and the third side of the triangle. The code shouldproduce 2 values in the output box, the first number will be the area and thesecond, the perimeter. (Hint: you’ll probably want to use DAT statements tostore some values to start).



I do not even know where to start on this one.



Any help would be appreciated.



I found a working simulator at this website:



http://www.itk.ilstu...lmc/default.htm




I also have some example codes to help:

Calculate perimeter & area - takes L & W as inputs
prints out perimeter first, then area.
00 LDA #01;
01 STA 99;
02 IN;
03 STA 98;
04 LDA #00;
05 STA 96;
06 IN;
07 STA 97;
08 ADD 97;
09 ADD 98;
10 ADD 98;
11 OUT;
12 LDA 96;
13 ADD 98;
14 STA 96;
15 LDA 97;
16 SUB 99;
17 STA 97;
18 SKZ;
19 JMP 12;
20 LDA 96;
21 OUT;
22 HLT;


MULTIPLIES TWO NUMBERS.
00 IN;
01 STA 99;
02 STA 97;
03 IN;
04 STA 98;
05 SUB 90;
06 STA 98;
07 SKZ;
08 JMP 12;
09 LDA 97;
10 OUT;
11 HLT;
12 LDA 97;
13 ADD 99;
14 STA 97;
15 LDA 98;
16 JMP 05;
90 DAT 001;

ADDS THE FIRST NUMBER INPUT TO ITSELF,
THEN SUBTRACTS THE SECOND INPUT FROM THE TOTAL
00 IN;
01 STA 90;
02 IN;
03 STA 91;
04 LDA 90;
05 ADD 90;
06 SUB 91;
07 OUT;
08 HLT;

ONE WAY OF COUNTING FROM AN INPUT DOWN TO ZERO
00 IN;
01 OUT;
02 SUB 98;
03 SKP;
04 JMP 06;
05 JMP 01;
06 HLT;
98 DAT 002;




SQUARING A NUMBER
00 IN; take input

01 STA 99; save value as a mulitiplier

02 STA 97; save value as multiplicand

03 SUB 90; subtract one from counter

04 STA 98; copy value to counter

05 LDA 97; load our accumulator number

06 ADD 99; Add original number

07 STA 97; store intermediate sum

08 LDA 98; Load counter

09 SUB 90; subtract one from counter

10 STA 98; Store counter value

11 SKZ; skip if counter is at zero

12 JMP 05; othewise, loop back to 5

13 LDA 97; load our squared number

14 OUT; Write output

15 HLT; stop

90 DAT 01; countdown value
10 years ago
Resolved it; had to add another buffer in the driver class for calculating the int. All that trouble for just one buffer statement to fix it all. Thank you everybody for your help.
11 years ago


Bold is line 122
11 years ago
[Edit] Ryan: I've removed your code paste for the reasons I said in my previous post.
PLEASE DON'T POST CODE WITH LONG LINES.

<the remainder of your post>

Error:

Exception in thread "main" Here is the data that you provided:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at Asset.calcAge(Asset.java:122)
at Asset.printData(Asset.java:159)
at AssetDriver.main(AssetDriver.java:52)

The first code is the main class the second code is the driver class testing the main class. I wanted to post more than just the calcAge method because the constructors may have something to do with the errors.
11 years ago
It is a requirement of the assignment + I don't think anything but a string would accept the / character since purchaseDate HAS to be in a mm/dd/yyyy format as well; another requirement of the assignment. Anyhow I figured out my problem; when I was entering the data I was typing an int + a string for the "what is the age of your item"; which is an int variable. Then I got another error and figured out because the "need a replacement" question is a boolean the answer has to be in true/false not yes or no. Which led to this error in the calcAge method statement:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at Asset.calcAge(Asset.java:122)
at Asset.printData(Asset.java:159)
at AssetDriver.main(AssetDriver.java:52)

I have tried many different string indexes. 6 should have worked.

11 years ago
I have tried all of that, still can't seem to get it working. Classes and objects are entirely new to me so I'm sure I"m doing something wrong that is an easy fix that I just can't see.
11 years ago
AH! I completely forgot about that! Thank you! Any idea about the calcAge method?
11 years ago
Hi all. This is the code I have so far.



The calcAge method does not work and I get this error:

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at AssetDriver.main(AssetDriver.java:37)

I am trying to have the calcAge method take the mm/dd/yyy string, convert it to an int, isolate JUST the yyyy, and then subtract the current year from what the user enters to get the difference.

I have tried everything I can think of. If anyone has any suggestions please help. Also here is my driver class I am testing it with:



In addition to the calcAge error; my driver class keeps combining What was the purchase date and what is the employee ID into one question instead of two.

11 years ago
Hi. Thanks for your quick reply. I have the program just about finished now (with the help from a student that once took this class) and will post it tomorrow. I am having just one error now. I agree that it is SO much easier just to take it one thing at a time. You are definitely right about that. As for the instructions the teacher gave us; VERY unclear. Even the other student agreed. special constructor..... is just a normal constructor like you said. I spent a good amount of time researching "special constructors" for no reason. Several things in the program's description could have been worded so much simpler.
11 years ago
I have a program assigned to me for school and have no idea where to start. I don't know what it is about classes and objects but it loses me. This is what I have to make the program do:

Attributes:

String assetID
double cost
integer lifeExpectancy
String employee ID
String purchaseDate
String description

Methods:

Special construcor that sets assetID and employeeID, defualt values for the rest
Special constructor that takes and sets all data
Typical getters for all data
Special setters for assetID and employeeID that gurantees the two data are always stored in uppercase. These setters should be called from the special constructor.
Typcial setter for the rest
Create a method called calcAge that accepts the current date in a String, formatted as mm/dd/yyyy, and returns the age (in years only).
Predicate method to decide if the component needs to be replaced; name it outdated. Return true if the age exceeds the life expectancy, return false if the age is less than or equal to the life expectancy
Method called printData that prints all data including the age of the component to the console with labels.

This is what I have so far:




Any help would be appreciated. I have no idea where to go with this since it is my first Java class taken and her assignments are a bit hard for what we have learned thus far.

11 years ago
My teacher suggested using:

int pos = text.indexOf("");
String word = text.substring(pos+1);
pos= new Text.indexOf("");
Stringword=newText.substring(0,pos);
word.toUppercase

Does this make any sense?
11 years ago
I am taking my first java class and the teacher wants us to write a program that will have the user enter their favorite quote and then in return the program will display: their quote, the length of their quote, the first word of their quote in uppercase, the first letter of the last word of their quote in uppercase, and display the first, middle, and last word of their quote labeled as such, as well as replacing every vowel with #.

I can do everything but: detect the first word of the user's quote and make it uppercase, detect the last word and make the first letter of the last word uppercase, and display the first, middle, and last word and label them as such.

The only thing I can think of right now is to restrict the user's quote to three words and make three different string variables.
11 years ago
And I actually have about 2.5 years not 2 years. As much as a rush I am in to start working I remind myself I am only 21 and have the rest of my life to work.... gotta enjoy life before rushing to work the rest of it right? ;)
11 years ago
It is one file. There is one class above and a tester class below with objects, variables, and methods.
11 years ago
Thank you for all of your replies, yes I found it strange that they listed COBOL and programming language one as well. It's a summer internship through State Farm (which explains old IBM systems). With all that said I will not be learning COBOL or programming language one or any of the older languages either because it will be a waste of time since I will probably never use them outside of the internship. If anything I will learn about them while doing the internship. Also, it is a paid internship, 18/hr so I guess they have the right to require some skills.

Found out I will actually have two years before graduation and loan repayment, so I think that is alot better than the 1 year time frame I listed before. I really hope to learn especially the following in these two years:

JSE
J2EE
Html
C#
ASP.Net
SQL
CSS
XML

Narrowed it down a bit. I believe if I learned these even at a basic level I would be applicable for a Jr. software developer position and believe two years is a good amount of time to have a basic understanding of the above as well. If any comments, or suggestions please feel free to share them as usual (negative as well! I am open to all recommendations) I really appreciate the support and responses from this community so far. Thank you for your time.

11 years ago