473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Scanner Class help?

Hi,

I'm trying to create this output:

Input team 1's name:
Team 1
Input team 1's ranking:
90.4
etc.

For 8 teams.

This is what I have:


import java.util.Scanner;

public class Tournament {
public static void main(String args[]) {
System.out.println("Input team 1's name:");
Scanner a = new Scanner(System.in);
System.out.println("Input team 1's ranking:");
Scanner b = new Scanner(System.in);
System.out.println("Input team 2's name:");
Scanner c = new Scanner(System.in);
System.out.println("Input team 2's ranking:");
Scanner d = new Scanner(System.in);
System.out.println("Input team 3's name:");
Scanner e = new Scanner(System.in);
System.out.println("Input team 3's ranking:");
Scanner f = new Scanner(System.in);
System.out.println("Input team 4's name:");
Scanner g = new Scanner(System.in);
System.out.println("Input team 4's ranking:");
Scanner h = new Scanner(System.in);
System.out.println("Input team 5's name:");
Scanner i = new Scanner(System.in);
System.out.println("Input team 5's ranking:");
Scanner j = new Scanner(System.in);
System.out.println("Input team 6's name:");
Scanner k = new Scanner(System.in);
System.out.println("Input team 6's ranking:");
Scanner l = new Scanner(System.in);
System.out.println("Input team 7's name:");
Scanner m = new Scanner(System.in);
System.out.println("Input team 7's ranking:");
Scanner n = new Scanner(System.in);
System.out.println("Input team 8's name:");
Scanner o = new Scanner(System.in);
System.out.println("Input team 8's ranking:");
Scanner p = new Scanner(System.in);

}

}

But when I try to compile it gives me 33 errors: "Tournament.java:36: cannot resolve symbol
symbol : class Scanner
location : class Tournament
Scanner [whatever variable]= new Scanner(System.in);"

Even if it does compile will the code I provided produce that output? I think I might need to use loops, but how would I do that?

Any ideas?

Thanks
Sep 30 '07 #1
3 2919
EDIT:

I have gotten help from someone and he gave me the following code:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;



class Tournament {

public static void main (String[] args) {

int numberOfTeams = 8;

Scanner in = new Scanner(System.in);

List<Team> teams = new ArrayList<Team>();

for (int i = 0; i < numberOfTeams; i++) {

System.out.printf("\nInput team %d's name: ", i + 1);

String name = in.nextLine();

System.out.printf("Input team %d's ranking: ", i + 1);

double rank = Double.parseDouble(in.nextLine());

Team team = new Team(name, rank);

teams.add(team);

}

System.out.println("\n\nHere are the teams you entered:");

for (Team team : teams) {

System.out.println(">>> " + team);

}

}

}



class Team {

private String name;

private double rank;



public Team(String name, double rank) {

this.name = name;

this.rank = rank;

}



public String toString() {

return String.format("Team[%s, rank: %.1f]", this.name, this.rank);

}

}


I understand mostly what this is doing, (it does exactly what i wanted) but I don't understand the addition of arrays and the "Team team"

Can someone please explain roughly what each part of this chunk of code does?

Thanks
Sep 30 '07 #2
Ganon11
3,652 Expert 2GB
So you asked for help somewhere else, and he gave you the full code without bothering to explain? In effect, you haven't learned how to do the project on your own. You should go back to this person and tell them you didn't learn anything, and you'd actually like an explanation of how to do it so you can become a better programmer.
Sep 30 '07 #3
Try with JDK1.5.0 or any higher version of Java. Because Scanner class is available from JDK1.5.0
Jul 31 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Dan =o\) | last post by:
Hey guys, I wonder if you could please provide me with some ideas as to how to get around this problem. Symbol MC9000-k, Pocket PC 2003... With a scanner application I've written, data is...
1
by: Darren Coleman | last post by:
I need help with 2 keyboard/input questions 1. How do i caputre all keypress events for my application/form? 2. How do I determine which keyboard sent the keypress? What i'm doing is using a...
7
by: DemonWasp | last post by:
I've been having some trouble getting the Scanner class to operate the way I'd like. I'm doing some fairly basic file IO and I can't seem to get the class to load the last line/token any way I try....
4
by: ryann18 | last post by:
What is wrong with this?? Here are the two classes...SandBox and KittyKitty?? I need to also know what happens if two or more values are equal and if exactly two values are equal, does it matter...
14
tolkienarda
by: tolkienarda | last post by:
hi all i read the scanner class documentation from sun's website and i thought i would have some fun trying to write a program that stores a line from the user to var input and then parses it on...
3
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the...
2
by: nitric | last post by:
Hey guys, I am taking Programming I this semester and I am completely new to Java. for my FIRST assignment i need to write a Java program that will give me hours, minutes and seconds after I type...
2
by: bvav22 | last post by:
Hey guys, im trying to finish an assignment for a java class, and i have finished the program except for one part. The program requires that i take 3 values inputted from the user, the first 2 must...
6
by: rotaryfreak | last post by:
Hi everyone, ive had this problem for a while and i cant seem to figure out why. I am using eclipse to create my java code. When import the Scanner class, create a new object and so on... ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.