Question
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get user input for one object, but when I tried to get it for the other two, it will not display. This is the part of the program that will compile correctly.
Name = the user name. CName = Course name. Grade = the grade for the course
-------------------------------------------------------------------------------
import java.util.Scanner;
public class Student{
private String Name; private String CName; private int Grade; public void setName(String Name){ this.Name=Name; } public void SetName(int Grade) { this.Grade=Grade; } public void SEtName(String CName) { this.CName=CName; } public String GEtName() { return CName; } public int GetName() { return Grade; }
public String getName(){ return Name; }
public static void main(String[] args){
Scanner input = new Scanner (System.in);
Student Sd = new Student(); System.out.println("Enter your first name then press enter. Enter your course name then press enter. Enter your number grade for that course. ");
String Name = input.nextLine(); String CName=input.nextLine(); int Grade=input.nextInt(); Sd.setName(Name); Sd.SEtName(CName); Sd.SetName(Grade);
System.out.printf("You said your name was %s%s%s%s%d", Sd.getName(), " and your course name was ", Sd.GEtName(), " and your grade for that course is ", Sd.GetName());
input.close(); } }
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