Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6 . 1 1 Course Info ( Individual Assignment ) Rules This is an Individual Assignment. You must complete this assignment on your own. Do
Course Info Individual Assignment
Rules
This is an Individual Assignment. You must complete this assignment on your own.
Do not collaborate or share code with other students.
Do not copy and paste code from anywhere.
Especially from Chegg or Course Hero, or Stack Overflow, or from anywhere you found through a Google Search
Students copying or sharing code will be reported to the Dean's office
for violating the Academic Integrity Policy and for disciplinary action.
Before you make a serious mistake and risk your grade and enrollment at ASU, please see your instructor for help.
Do not use any resources outside of those provided in the course materials.
Do not use any language features that have not been covered to this point in the course materials.
Required Skills Ifnventory
Use variables to name, store, and retrieve values
Use System.out.print to prompt the user for input
Use a Scanner nextLine method to collect user input
Use String methods like indexOf, lastIndexOf, length, charAt, and substring to construct expressions
Use Integer.parseInt method to parse a String value to an int value
Use String literals and String variables and concatenation to construct String expressions
Output to console with System.out.println
Problem Description and Given Info
You must write a program that take as in input, a String containing the information for a course. This course information will always be a String formatted like this:
Here is an example:
CSE Principles of Programming
Note that the four pieces of information in this String are each separated by a single space character.
You can safely assume for this assignment that the input to your program will always follow this format.
Your program must collect and store this full course information in a single String variable. You should use the Scanner nextLine method to collect the input as a single String. Your program must then extract the four pieces of information and store each in separate variables. The subject and title must be stored in String variables. The course number and section number must be stored in int variables. Finally, you program must print out the four pieces of information on separate lines, as show in the examples below.
Here are some examples of what the user should see when the program runs.
Example
Enter course info : CSE Principles of Programming
Subject : CSE
Course Number :
Section Number :
Course Title : Principles of Programming
Example
Enter course info : FSE Introduction to Engineering
Subject : FSE
Course Number :
Section
Remember that the indexOf method has a variation that takes two arguments, where the first argument is the text to look for, and the second argument is the index to start looking at
For example, given a String variable name that contains the String value "Bob Allen Smith", name.indexOf would return the int value because the first space occurring in the String that comes at or after index is at index
You can use the Integer.parseInt method to parse a String value to an int value. For example, given a String variable named age that currently stores the String value we can parse this String to an int value like this:
iint age Integer.parseIntage;
this code didnt work well
import java.util.Scanner;
public class CourseInfo
public static void mainString args
Using Scanner nextLine method, we have collected a new single string input separated by single spaces
Scanner input new ScannerSystemin;
System.out.printEnter course info: ;
String courseInfo input.nextLine;
Extracting the four pieces of information and storing them in different variables
int subIndex ;
int CNIndex courseInfo.indexOf subIndex;
int SNIndex courseInfo.indexOf CNIndex ;
int titleIndex courseInfo.lastIndexOf;
String subject courseInfo.substringsubIndex CNIndex;
int courseNumber Integer.parseIntcourseInfosubstringCNIndex SNIndex;
int sectionNumber Integer.parseIntcourseInfosubstringSNIndex titleIndex;
String title courseInfo.substringtitleIndex;
Printing out all the information on separate lines
System.out.printlnSubject: subject;
System.out.printlnCourse Number: courseNumber;
System.out.printlnSection Number: sectionNumber;
System.out.printlnCourse Title: title;
Closing the scanner to prevent resource leak
input.close;
Input CgE Painelples Progranming
Exper:ad output
:Legia Test A
Exception in thaead "main" javaang. NumberFozmatExeeption: For nput atring: a Inta
at jara.haenjaralang.IntegerpaaeInt Integerjara:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started