472,805 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 2878
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... ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.