java
create java class "nameperson"
the example of output would be this:
//if the user inputs
sophia 206999109 2
//then the output shows this
My name is None and my studentid is 0
My name is sophia and studentid is 0
My name is sophia and studentid is 206999109
My grade is 2
so i have to create two classes
class nameperson{
}
class studentid extends person{
}
class grade extends studentid{
}
my main method is this
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Person[] people = new
Person[3];
int studentid, grade;
String name;
name = sc.next();
studentid = sc.nextInt();
grade = sc.nextInt();
people[0] = new Person();
people[1] = new Person(name);
people[2] = new Person(name,
studentid);
people[3] = new grade(grade);
for (int i = 0; i <
people.length; i++)
people[i].writeOutput();
sc.close();
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new java class file with name "main.java" is created, which contains following code.
main.java :
import java.util.*;
public class Main//Main class
{
//main method
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);//creating object
of Scanner class
nameperson[] people = new nameperson[4];//array of nameperson
int studentid, grade;//declaring variables
String name;
name = sc.next();//reading name
studentid = sc.nextInt();//reading student id
grade = sc.nextInt();//reading grade
people[0] = new nameperson();//creating object of nameperson
people[1] = new nameperson(name);//creating object of
nameperson
people[2] = new nameperson(name, studentid);//creating object of
nameperson
people[3] = new Grade(grade);//creating object of grade
//for loop is used to loop through the array
for (int i = 0; i < people.length; i++)
people[i].writeOutput();//calling method
sc.close();
}
}
class nameperson{//class
public String name; //declaring properties
public int studentid;
public nameperson()//default constructor
{
this.name="none";
this.studentid=0;
}
public nameperson(String n)//parameterized constructor
{
this.name=n;
}
public nameperson(String n,int id)//parameterized constructor
{
this.name=n;
this.studentid=id;
}
public void writeOutput()//method to display result
{
System.out.println("My name is "+name+" and studentid is
"+studentid);
}
}
class Grade extends nameperson{ //class Grade
public int grade;
public Grade(int g)//parameterized constructor
{
this.grade=g;
}
public void writeOutput()//method to display result
{
System.out.println("My grade is "+grade);
}
}
======================================================
Output : Compile and Run above program to get the screen as shown below
Screen 1 :main.java

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
java create java class "nameperson" the example of output would be this: //if the user inputs...
design two java classes The example of output would be this: user puts the amount of money: (for example 9000) I'm going to get three things 1. Cellphone cost: 3000 2. Laptop cost: 6000 3. Macbook cost: 4000 From now on, my balance would be (+balance) and I bought cellphone, laptop, (since there is not enough amount of money, I can only buy cellphone and laptop. if there is enough money then it can buy all things) so I have...
Create a java class that user put two inputs and first input generate n length array of randomly generated numbers. and the second input changes that number of multiples in the array into zero. for example, if the user puts 3 and 5 then it generates 34 60 10 and since the second input is 5 then the multiple of 5 eliminates so it generates 34 0 0 here is the main method that I'm going to use class Main...
Getting started with Java on elvis Download Greeting.java from the class web site. Use FileZilla to place it into your Lab5 directory. Look at the content of your directory to see the file using the command ls Look at the content of the file in your directory using the command more Greeting.java Compile the HelloClass program using the command javac Greeting.java. Then use ls to see your class file. Run the program without parameters using the command java Greeting Run...
java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> { LinkedList<T> list; public Stack() { list = new LinkedList<T>(); } public boolean isEmpty() { return list.isEmpty(); ...
How would I edit this Java program to end if the user inputs 0 or less? public static void main(String[] args) { Scanner sc = new Scanner(System.in); // to read input String Message; int m=0; int i=1; System.out.print("Please enter the message you would like displayed: "); Message=sc.nextLine(); while(true) { System.out.print("How many times would you like your message displayed?"); m = sc.nextInt(); break; } do { System.out.println(Message); //When I enter 0 or a negative number it still runs at least once,...
I don't really understand how to make the scores show up and how to make it start over. I honestly only half understand the things I've used to piece this together to make this work so far. but this is what I was asked to do..... read a user's first and last name read three integer scores, calculate the total and average determine the letter grade based on the following criteria - Average 90-100 grade is A, 80-89.99 grade is...
I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact { public static void main(String[] args) { Random Rand = new Random(); Scanner sc = new Scanner(System.in); System.out.println("welcome to the contact application"); System.out.println(); int die1; int die2; int Total; String choice = "y";...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...
Provide comments for this code explaining what each line of code does import java.util.*; public class Chpt8_Project { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int [][]courses=new int [10][2]; for(int i=0;i<10;i++) { while(true) { System.out.print("Enter classes and graduation year for student "+(i+1)+":"); courses[i][0]=sc.nextInt(); courses[i][1]=sc.nextInt(); if(courses[i][0]>=1...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...