Rewrite the following code by removing Integer.parseInt

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help with the following question:

Rewrite the following code by removing Integer.parseInt

public class javaapplication1 {

/**
* @param args
*
*/
public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

//create 3 Department instances
System.out.println("Enter Department 1 name and ID: ");
Department d1=new Department(sc.nextLine(), Integer.parseInt ( sc.nextLine()));
System.out.println("Enter Department 2 name and ID: ");
Department d2=new Department(sc.nextLine(), Integer.parseInt( sc.nextLine()));
System.out.println("Enter Department 3 name and ID: ");
Department d3=new Department(sc.nextLine(), Integer.parseInt( sc.nextLine()));

//create 5 Students
System.out.println("Enter Student 1 Id, Name and Dept ID");
Student s1=new Student(Integer.parseInt(sc.nextLine()),sc.nextLine(),Integer.parseInt(sc.nextLine()));
System.out.println("Enter Student 2 Id, Name and Dept ID");
Student s2=new Student(Integer.parseInt(sc.nextLine()),sc.nextLine(),Integer.parseInt(sc.nextLine()));
System.out.println("Enter Student 3 Id, Name and Dept ID");
Student s3=new Student(Integer.parseInt(sc.nextLine()),sc.nextLine(),Integer.parseInt(sc.nextLine()));
System.out.println("Enter Student 4 Id, Name and Dept ID");
Student s4=new Student(Integer.parseInt(sc.nextLine()),sc.nextLine(),Integer.parseInt(sc.nextLine()));
System.out.println("Enter Student 5 Id, Name and Dept ID");
Student s5=new Student(Integer.parseInt(sc.nextLine()),sc.nextLine(),Integer.parseInt(sc.nextLine()));

//create University instance
University u1 = new University("Oxford",40000,2500000);

System.out.println("Student number 1 in Department 1: "+equals(s1.getDepId(),d1.getDepId()));

System.out.print("Input a String: ");
String str1=sc.nextLine(); //input string from user
String temp="";

for(int i=0;i<str1.length();i++){ //from 0 to last index

if(i%2==0) //if even position
temp+=Character.toLowerCase(str1.charAt(i)); //conavrt to lower case and add to temp

else //if odd position
temp+=Character.toUpperCase(str1.charAt(i)); //convert to upper case and add to temp
}
System.out.println(temp);
}

public static boolean equals(int n1,int n2){
return n1==n2; //return true if both are same else return false
}
}

public class University{
    
    //declare the instance variables as private
    private String name;
    private int population;
    private double budget;
    
    //constructor for setting values
    public University(String name, int population, double budget){
        setName(name);
        setPopulation(population);
        setBudget(budget);
    }
    
    //setters
    public void setName(String n){
        name=n;
    }
    
    public void setPopulation(int p){
        population=p;
    }
    
    public void setBudget(double b){
        budget=b;
    }
    
    //getters
    public String getName(){
        return name;
    }
    
    public int getPopulation(){
        return population;
    }
    
    public double getBudget(){
        return budget;
    }
}

public class Department{
    
    //declaring instance variables
    private String Dep_Name;
    private int Dep_Id;
    
    //constructor for setting instance variables
    public Department(String name, int id){
        Dep_Name=name;
        Dep_Id=id;
    }
    
    //setters
    public void setDepName(String name){
        Dep_Name=name;
    }
    
    public void setDepId(int id){
        Dep_Id=id;
    }
    
    //getters
    public String getDepName(){
        return Dep_Name;
    }
    
    public int getDepId(){
        return Dep_Id;
    }

public class Student{
    
    //declaring instance variables
    private int ID;
    private String name;
    private int Dep_Id;
    
    //constructor for setting values to instance variables
    public Student(int id, String n, int dep){
        ID=id;
        name=n;
        Dep_Id=dep;
    }
    
    //setters
    public void setID(int id){
        ID=id;
    }
    
    public void setName(String n){
        name=n;
    }
    
    public void setDepId(int dep){
        Dep_Id=dep;
    }
    
    //getters
    public int getID(){
        return ID;
    }
    
    public String getName(){
        return name;
    }
    
    public int getDepId(){
        return Dep_Id;
    }

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education