[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 33 KB, 301x301, Java.jpg [View same] [iqdb] [saucenao] [google]
1785576 No.1785576 [Reply] [Original]

I have some questions for my Software Engineering homework, where I need to write a java program.

1: If I use keyboard inputs multiple times in my program, do I need to make an object to reference the scanner each time or just once?

2: How do I test whether a variable entered for the object is between 2 numbers? (like 2<=X<=10)

3. How do I set the format for the final output of the numbers that are printed to the screen so that they are currency? (like $100.00) I think that I will use doubles for my variables, but I need to selectively truncate the data into the currency format.

I know that this isn't math or science per-se, but this is the only board that will probably be able to help.

>> No.1785614

Been a long while since I did any programming so this may not be correct but I'll try to help.
1. No, 1 object will do.
2. example if(x >= 2 && x <= 10) { dostuff(); }
3. don't remember what this is called in Java, sorry.

>> No.1785623

That is not software engineering, that is introductory programming

And to answer your questions, google.

>> No.1785624

>software engineering
>java

>> No.1785632

Dude, that isn't even Intro to Java 101 ...

>> No.1785633

System.out.println("$"+currency)

or are you talking about the printf() ?

>> No.1785639

>>1785624
>>1785623

It is the Introduction to programming class, which is the first SE class in the SE track.

Google helped with all other but these three questions.

>> No.1785643 [DELETED] 
File: 13 KB, 248x249, 1262323239134.jpg [View same] [iqdb] [saucenao] [google]
1785643

>>1785576
> I think that I will use doubles for my variables

>> No.1785650

>>1785633
I believe he's talking about NumberFormat.

>> No.1785666

>>1785650

I am talking about the number format. I assume that I need to reference something in the Java database and use it to format the outputted numbers. The professor just told the class to figure it out by searching online.

>>1785633

I already know how to do that. I just need to format it as previously stated.

>> No.1785675
File: 183 KB, 566x690, 1280786169585.jpg [View same] [iqdb] [saucenao] [google]
1785675

>> No.1785707

1. once
2.just use an if statement
if( X>=2 && X<=10)
System.out.println("Whatever the fuck you want);
else
System.outprintln("Youfailedyounigger");
3.int x=100;
System.out.printf("%3.2",x);
Output value = 100.00
you nigger

>> No.1785720

Fuck its
3.int x=100;
System.out.printf("%3.2f",x);
Output value = 100.00
you nigger


%3.2f
3 ahead and 2 behind
f for float
d for double
etc.

>> No.1785739

The solutions to #1 and #2 work beautifully. I will need to test the code more to see if the solutions to #3 work.

Thanks, /sci/! I am embarassed at how simple it actually is.

>> No.1785750

>>1785720

This works pretty well, thank you.

>> No.1785752

I'm glad I could help an anon

>> No.1785780

I don't like Java so much so far. I am more used to languages in the BASIC family, like Q-BASIC and Visual Basic. However, I am tolerating it because it is mandatory, I will learn more, and the C languages are similar to it. I am enjoying my other SE class a bit more, where I am designing and building logic circuits.

>> No.1785801

Eh Java is mandatory as well and its my first language but I'm enjoying it so far.

>> No.1785830

>>1785801

on second thought, I am getting to like it more now that I know what I am doing at the moment. It will grow on me. I guess the point of getting a program due the next day in Lab without any walkthrough is meant to strengthen your abilities and teach you how to figure this out on your own. Wow, I actually feel like I'm learning! I feel like I am learning more noticeably in College than I did in High School.

>> No.1785845

Thats what I love about the course. Once you know what your doing its pretty fun. Or at least it is for me.