Question

Java. Java is a new programming language I am learning, and so far I am a...

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();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
package Assignments;

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();
    Student Sd2 = new Student();
    Student Sd3 = new Student();

    System.out.println("Student1: 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("Student1: 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());
    System.out.println("\n");

    System.out.println("Student2: Enter your first name then press enter. Enter your course name then press enter. Enter your number grade for that course. ");
    String Name2 = input.nextLine();
    input.nextLine();
    String CName2=input.nextLine();
    int Grade2=input.nextInt();
    Sd2.setName(Name2);
    Sd2.SEtName(CName2);
    Sd2.SetName(Grade2);
    System.out.printf("Student2: You said your name was %s%s%s%s%d", Sd2.getName(), " and your course name was ", Sd2.GEtName(), " and your grade for that course is ", Sd2.GetName());
    System.out.println("\n");

    System.out.println("Student3: Enter your first name then press enter. Enter your course name then press enter. Enter your number grade for that course. ");
    String Name3 = input.nextLine();
    input.nextLine();
    String CName3=input.nextLine();
    int Grade3=input.nextInt();
    Sd3.setName(Name3);
    Sd3.SEtName(CName3);
    Sd3.SetName(Grade3);
    System.out.printf("Student3: You said your name was %s%s%s%s%d", Sd3.getName(), " and your course name was ", Sd3.GEtName(), " and your grade for that course is ", Sd3.GetName());
    System.out.println("\n");

    input.close();
  }
}

Add a comment
Know the answer?
Add Answer to:
Java. Java is a new programming language I am learning, and so far I am a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • JAVA help Create a class Individual, which has: Instance variables for name and phone number of...

    JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT