Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
mohdiqbal
Gerbil In Training
Topic Author
Posts: 3
Joined: Thu Sep 16, 2010 7:02 am

Find the Largest Number

Thu Sep 23, 2010 10:06 am

Hi, I am working on my assignment: The assignment is:

The process of finding the largest value (i.e., the maximum of a group of values) is used frequently computer applications. Write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.

Below is my code so far:

LargestValue

import java.util.Scanner; //scanner class import declaration
public class LargestValue
{
public void determineLargestValue()
{
Scanner input = new Scanner(System.in);

int intCounter = 0;
int total = 0;
int number;
int largest;

System.out.println("Enter number: ");
largest = input.nextInt();

total += largest;

while (intCounter < 9)
{
System.out.println("Enter number: ");
number = input.nextInt();
if(number > largest)
{
largest = number;
}
total += number;
intCounter++;
}

}//end if

}//end while


System.out.printf("The total is : %d\n", total);
System.out.printf("\nThe largest of all 10 integers is: %d\n", largest, number);
}
}


LargestValueTest

class LargestValueTest
{
public void main(String args[])
{
LargestValue LargestValue1 = new LargestValue();//create object of LargestValue class to call method
LargestValue1.determineLargestValue();//find the largest integer in 10
}//end main
}//end class
Last edited by mohdiqbal on Sat Sep 25, 2010 3:15 am, edited 1 time in total.
 
mph_Ragnarok
Graphmaster Gerbil
Posts: 1315
Joined: Thu Aug 25, 2005 7:04 pm

Re: Find the Largest Number

Thu Sep 23, 2010 10:50 am

What is this ? 8th grade comp sci ?

Use a for loop duh.

int MAX=GetNextValue; // the first value by default is the max
for(int i=0;i < COUNTER;i++){
int temp=GetNextValue;
if( temp>MAX) MAX=temp;
}
GACKT ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
Dual nehalem Xeon e5520 / 16 GB DDR3 / GTX 280
 
Heiwashin
Grand Gerbil Poohbah
Posts: 3406
Joined: Wed Dec 13, 2006 1:21 pm
Location: Denham Springs, LA

Re: Find the Largest Number

Thu Sep 23, 2010 11:00 am

mph_Ragnarok wrote:
What is this ? 8th grade comp sci ?

Use a for loop duh.

int MAX=GetNextValue; // the first value by default is the max
for(int i=0;i < COUNTER;i++){
int temp=GetNextValue;
if( temp>MAX) MAX=temp;
}

Douchebag
Looking for Knowledge wrote:
When drunk.....
I want to have sex, but find I am more likely to be shot down than when I am sober.
 
Captain Ned
Gold subscriber
Global Moderator
Posts: 24044
Joined: Wed Jan 16, 2002 7:00 pm
Location: Vermont, USA

Re: Find the Largest Number

Thu Sep 23, 2010 11:01 am

Ah, a good old bubble sort.
And then of course I've got this terrible pain in all the diodes down my left hand side.
 
SNM
Emperor Gerbilius I
Posts: 6207
Joined: Fri Dec 30, 2005 10:37 am

Re: Find the Largest Number

Thu Sep 23, 2010 11:05 am

Captain Ned wrote:
Ah, a good old bubble sort.

...huh? There are no bubble sorts here, nor should there be.

mohdiqbal: That looks fine for a program that's gathering input while acting on it. I hope your real code is indented, though!
Core i7 920, 3x2GB Corsair DDR3 1600, 80GB X25-M, 1TB WD Caviar Black, MSI X58 Pro-E, Radeon 4890, Cooler Master iGreen 600, Antec P183, opticals
 
Flying Fox
Gerbil God
Posts: 25118
Joined: Mon May 24, 2004 2:19 am
Contact:

Re: Find the Largest Number

Thu Sep 23, 2010 11:06 am

What problem(s) are you running into? We are not in the business doing your homework for you. Although most of us won't sound like a douchebag though.
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
 
SNM
Emperor Gerbilius I
Posts: 6207
Joined: Fri Dec 30, 2005 10:37 am

Re: Find the Largest Number

Thu Sep 23, 2010 11:14 am

Wait, that's Java. Is it really supposed to be written in Javascript, or was that a typo?
Core i7 920, 3x2GB Corsair DDR3 1600, 80GB X25-M, 1TB WD Caviar Black, MSI X58 Pro-E, Radeon 4890, Cooler Master iGreen 600, Antec P183, opticals
 
emorgoch
Gerbil Elite
Posts: 700
Joined: Tue Mar 27, 2007 11:26 am
Location: Toronto, ON

Re: Find the Largest Number

Thu Sep 23, 2010 1:09 pm

Captain Ned wrote:
Ah, a good old bubble sort.

Bubble sort? No sorting necessary for this. It's either check for the max as the numbers are entered (most efficient), or check them after they're all entered (if you enter all the numbers in a single command).
Intel i7 4790k @ stock, Asus Z97-PRO(Wi-Fi ac), 2x8GB Crucial DDR3 1600MHz, EVGA GTX 760
Samsung 950 Pro 512GB + 2TB Western Digital Black
Dell 2408WFP and Dell 2407WFP-HC for dual-24" goodness
Windows 10 64-bit
 
JustAnEngineer
Gold subscriber
Gerbil God
Posts: 16887
Joined: Sat Jan 26, 2002 7:00 pm
Location: The Heart of Dixie

Re: Find the Largest Number

Thu Sep 23, 2010 8:03 pm

I'd use the douchebag's method. I'm not fluent with Javscript, but I might be able to give you some FORTRAN code that would do the job. :lol:
 
Nitrodist
Grand Gerbil Poohbah
Posts: 3281
Joined: Wed Jul 19, 2006 1:51 am
Location: Minnesota

Re: Find the Largest Number

Fri Sep 24, 2010 12:00 am

SNM wrote:
Wait, that's Java. Is it really supposed to be written in Javascript, or was that a typo?


It also said that he was to output it in XHTML... so unless he's writing a applet/servelet, I'd say that he's using the wrong programming language.
Image
 
mohdiqbal
Gerbil In Training
Topic Author
Posts: 3
Joined: Thu Sep 16, 2010 7:02 am

Re: Find the Largest Number

Sat Sep 25, 2010 3:24 am

Guys, I have made me changes, my tasks are as follows:

"The process of finding the largest value is used frequently in computer applications (for eg: a program that determines the winner of a sales contest would input the number of units sold by each sales person. Teh salesperson who sells the most units wins the contest). Write a pesudocode program first and then write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.
 
emorgoch
Gerbil Elite
Posts: 700
Joined: Tue Mar 27, 2007 11:26 am
Location: Toronto, ON

Re: Find the Largest Number

Sat Sep 25, 2010 6:34 pm

Not sure what you want from us. We're not going to do your homework for you. We've already given you the process to go through to solve it. This is a simple program, shouldn't take more than 20 lines of code. Write them up and compile them. If you're still having trouble at that point, then come back, and we can help with the specific issues.
Intel i7 4790k @ stock, Asus Z97-PRO(Wi-Fi ac), 2x8GB Crucial DDR3 1600MHz, EVGA GTX 760
Samsung 950 Pro 512GB + 2TB Western Digital Black
Dell 2408WFP and Dell 2407WFP-HC for dual-24" goodness
Windows 10 64-bit
 
Nitrodist
Grand Gerbil Poohbah
Posts: 3281
Joined: Wed Jul 19, 2006 1:51 am
Location: Minnesota

Re: Find the Largest Number

Sun Sep 26, 2010 3:38 am

mohdiqbal wrote:
Guys, I have made me changes, my tasks are as follows:

"The process of finding the largest value is used frequently in computer applications (for eg: a program that determines the winner of a sales contest would input the number of units sold by each sales person. Teh salesperson who sells the most units wins the contest). Write a pesudocode program first and then write a Java Application that input a series of 10 integers and determines and prints the largest integer. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed).

b.) NUMBER: The integer most recently input by the user
c.) LARGEST: The largest number found so far.


From your posts, it's clear that you're a beginner (not hating on you here). What specifically are you having trouble with? You are creating classes and putting in methods that could all be done within the main method which may be confusing you as to how these programs should be created in that it's another layer of complexity that isn't needed at this point.

Were you the author of that code you posted? Nothing wrong with studying code to get your self familiar, but if you're having trouble with something like this then perhaps you could look up the official Java tutorials which are very well written, post something more specific about what you're having trouble with or perhaps you need some 1-on-1 tutoring with a classmate/professor/tutor.
Image

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests