Results 1 to 4 of 4

Thread: Scanner

  1. #1
    aussieguy0101 is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Scanner

    Hi All
    I have been learning Java for only a month and am writing a program for a basic mechanic shop, its unfinished but what I am having probs with is the scanner. I need to know how to have all methods within the program access the scanner, I dont know where to put it.

    thanks!

    import java.util.*;


    public class ServiceAppointment {
    Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {

    String registrationNumber;
    String vehicleMakeModel;
    String buildYear;
    String ownerName;
    String contactNumber;

    System.out.print("Enter Make / Model");
    vehicleMakeModel = keyboard.next();
    System.out.print("Enter Year of Vehicle");
    buildYear = keyboard.next();
    System.out.print("Enter Owners Name");
    ownerName = keyboard.next();
    System.out.print("Enter Phone Number");
    contactNumber = keyboard.next();




    public static void addWorkHours(double hours) {
    System.out.print("Enter Hours worked");
    hours = keyboard.nextDouble();
    hours = hours * 35;

    if (hours <-0) {

    }
    }

    public static void addPartDetails(String partDescription, double partCost) {

    }
    public static void displayServiceSummary() {

    }
    }

  2. #2
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    992
    Rep Power
    2

    Default Re: Scanner

    Since your methods are static, you need to make Scanner static as well.
    Java Code:
    private static Scanner keyboard = new Scanner(System.in);

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Scanner

    Ehrm, SurfMan, shouldn't the OP get rid of all that static stuff in the first place rather than adding more?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    992
    Rep Power
    2

    Default Re: Scanner

    Quote Originally Posted by PhHein View Post
    Ehrm, SurfMan, shouldn't the OP get rid of all that static stuff in the first place rather than adding more?
    I agree 100%, but I thought I would make it too difficult at this stage.

Similar Threads

  1. help with the Scanner
    By HelloWorld1234 in forum New To Java
    Replies: 2
    Last Post: 02-03-2013, 01:05 AM
  2. How to use Scanner ?
    By sandeep43 in forum New To Java
    Replies: 7
    Last Post: 08-10-2011, 01:29 PM
  3. Using scanner for CSV
    By getName() in forum Advanced Java
    Replies: 7
    Last Post: 06-20-2010, 04:33 PM
  4. Help With Scanner
    By jtmoney0511 in forum New To Java
    Replies: 10
    Last Post: 10-12-2009, 11:24 PM
  5. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •