0

This is my code:

package Class;

import java.util.Scanner;

public class Bicycle 
{    
    public static int units;
    public static int courseNum;
    public static String courseName;

    public Bicycle(int startUnits, int startNum, String startName) 
    {
        units = startUnits;
        courseNum = startNum;
        courseName = startName;
    }

    public static int setUnits(int newValue) 
    {
        units = newValue;
        return units;
    }

    public static int setNum(int newValue)
    {
        courseNum = newValue;
        return courseNum;
    }

    public static String setName(String newValue) 
    {
        courseName = newValue;
        return courseName;
    }

    public class subClass extends Bicycle 
    {
        public int randVariable;

        public subClass(int startUnits, int startNum, String startName) 
        {
            super(startUnits, startNum, startName);
        }   

        public void randVariable(int newValue) 
        {
            randVariable = newValue;
        }   
    }

    public static void main(String args[]) 
    {
        int BaseUnits;
        int BaseCourseNum;
        String BaseCourseName;

        int FinalUnits;
        int FinalCourseNum;
        String FinalCourseName;

        Scanner entries = new Scanner(System.in);

        BaseUnits = entries.nextInt();
        BaseCourseNum = entries.nextInt();
        BaseCourseName = entries.nextLine();

        FinalUnits = setUnits(BaseUnits);
        FinalCourseNum = setNum(BaseCourseNum);
        FinalCourseName = setName(BaseCourseName);

        System.out.printf("The Course ");
        System.out.println(FinalCourseName);
        System.out.printf(" (CIS %d) is worth %d units.", FinalCourseNum, FinalUnits);
    }
}

What I'm trying to do is get a string input, and although I am using the code that would do that, the program never actually asks me to enter that string.

b4hand
  • 8,601
  • 3
  • 42
  • 48
CoolKat
  • 112
  • 1
  • 12

2 Answers2

0
Scanner entries = new Scanner(System.in);

        BaseUnits = entries.nextInt();
        BaseCourseNum = entries.nextInt();
        BaseCourseName = entries.next(); //<--

use next() instead of nextLine(); read this nextLine for further clearification.

Sindhoo Oad
  • 1,134
  • 2
  • 13
  • 29
0

your code snippets is taking input from user at below line

Scanner entries = new Scanner(System.in);

    BaseCourseName = entries.nextLine();

either you can change this to

    BaseCourseName = entries.nextLine();

or

you can take input from BufferedReader also as given below.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String line = br.readLine();
Prashant
  • 2,480
  • 2
  • 17
  • 26